This module has 3 sensors. Gyroscope, Accelerometer and Magnetometer.
I think I'm reading the raw data in the wrong way.
For example, for the magnetometer HMC5883L, I'm using this code which I copied from a library and it gives the correct values, but when I use the same code for reading the raw data from the accelerometer ADXL345 then it's not what it should be according to different sources I've read.
The magnetometer HMC5883L:
void HMC5883L_print_Serial(void) { int16_t x,z,y; uint8_t data[6]; float heading,heading_in_degrees,declination_angle_YANBU; data_read(data); // This one doesn't x = data[1] << 8 | data[0]; z = data[3] << 8 | data[2]; y = data[5] << 8 | data[4]; // This one works OK /*x = data[0] << 8 | data[1]; z = data[2] << 8 | data[3]; y = data[4] << 8 | data[5];*/ heading = atan2(y,x); declination_angle_YANBU = ((3.0 + (52.0 / 60.0)) / (180 / M_PI)); // in yanbu city it's heading += declination_angle_YANBU; // Correct for heading < 0deg and heading > 360deg if (heading < 0){ heading += 2 * PI; } if (heading > 2 * PI){ heading -= 2 * PI; } heading_in_degrees = heading * 180 / M_PI; Serial.println(heading_in_degrees); _delay_ms(20); }
The accelerometer ADXL345
void ADXL345_print_Serial(void){ int16_t x,z,y; uint8_t data[6]; ADXL345_read_raw(data); // This one gives values from -255 to +255 x = data[1] << 8 | data[0]; z = data[3] << 8 | data[2]; y = data[5] << 8 | data[4]; // This one give values from -32768 to +32768 /*x = data[0] << 8 | data[1]; z = data[2] << 8 | data[3]; y = data[4] << 8 | data[5];*/ Serial.print(x);Serial.print("\t"); Serial.print(y);Serial.print("\t"); Serial.println(z); _delay_ms(100); }
So basically I want to learn how to work with these sensors and also I want to know the principles about each one, because I'm confused between then I feel they are the same and each one provides similar functions; like, tilt sensing.