Witam, mam problem z w/w czujnikiem, dla nie wtajemniczonych jest to magnetometr, dzięki niemu można skonstruować kompas. Problem polega na tym że gdy podłącze do arduino i wgram jakikolwiek przykładowy program to wartości xyz zawsze pokazuje albo tylko same zera albo jedynki, np. że x=1 y=1 z=1. Sprawdzałem podłączenie kilka razy, zasilanie itp. Wykrywa adres 0d gdy wgram i2c scanner ale domyślnie te moduły chyba działają na adresie 1E. Załaczam program na którym bazowałem. Jest to ten sam którym bawił się Elektromaras na yt i jemu działało xd
/* Include the standard Wire library */
#include <Wire.h>
/* The I2C address of the module */
#define HMC5803L_Address 0x1E
/* Register address for the X Y and Z data */
#define X 3
#define Y 7
#define Z 5
void setup()
{
Serial.begin(9600);
/* Initialise the Wire library */
Wire.begin();
/* Initialise the module */
Init_HMC5803L();
delay(300);
}
void loop()
{
/* Read each sensor axis data and output to the serial port */
Serial.print("X=");
Serial.print(HMC5803L_Read(X));
Serial.print(" ");
Serial.print("Y=");
Serial.print(HMC5803L_Read(Y));
Serial.print(" ");
Serial.print("Z=");
Serial.println(HMC5803L_Read(Z));
/* Wait a little before reading again */
delay(200);
}
/* This function will initialise the module and only needs to be run once
after the module is first powered up or reset */
void Init_HMC5803L(void)
{
/* Set the module to 8x averaging and 15Hz measurement rate */
Wire.beginTransmission(HMC5803L_Address);
Wire.write(0x00);
Wire.write(0x70);
/* Set a gain of 5 */
Wire.write(0x01);
Wire.write(0xA0);
Wire.endTransmission();
}
/* This function will read once from one of the 3 axis data registers
and return the 16 bit signed result. */
int HMC5803L_Read(byte Axis)
{
int Result;
/* Initiate a single measurement */
Wire.beginTransmission(HMC5803L_Address);
Wire.write(0x02);
Wire.write(0x01);
Wire.endTransmission();
delay(6);
/* Move modules the resiger pointer to one of the axis data registers */
Wire.beginTransmission(HMC5803L_Address);
Wire.write(Axis);
Wire.endTransmission();
/* Read the data from registers (there are two 8 bit registers for each axis) */
Wire.requestFrom(HMC5803L_Address, 2);
Result = Wire.read() << 8;
Result |= Wire.read();
return Result;
}