Hi I hope I have posted this in the right forum,
I recently borrowed a 9DOF sensor stick from sparkfun (SparkFun 9 Degrees of Freedom - Sensor Stick - SEN-10724 - SparkFun Electronics) to learn how sensors work. I wrote a small program that outputs readings and viewed it via the serial monitor window.
The output was as follows
ACCEL: 1234 3421 3643
MAG: 2354 0 9012
GYRO: 1231 2525 0
(these are not the actual readings, its just what the output looks like)
After knowing that the program works, I went ahead and purchased the same sensor. I then soldered headers onto the sensor and uploaded the exact same program. When I ran monitored the output via the serial monitor, I am getting some wierd symbols
àüàpÀÜF£E?b?âÄ?Â?¢ÄC¸?¤Å?Å?¥#"ã¤Â?ÂZó âÄ¥Â{¢ÄC ?¤ÅTÄ?Å#"ãĤÂ?ñ âÄ?¤¢¤C ?¤?B+?Å#"ãĤ:¤ó â8?Â?¢¤C ?¤+?Å?Å#"c¤Â?¤ó ¼âÄ?Â?¢¤C ?¤Ä\Ä??#"ã?E??d â8?Ò?¢¤C ¤Ä?Ä?¥#"ã¤Â?¤ó âÄ?Â?¢|C¼a¤Ä?Æi¥#"ãĤÂÄó âÄ?Â?b¤C ?¤+?Æ?¥#"ãÄáRa?ü âÄ?Â?¢¤» ?¤Å?Å?¥#"ã¤ò?8¤ó âÄ?Â?¢¤C¼?ª$?Å?¥#"ã?E?EFd âÄ?Âd¢¤C ?XÄ?Å?¥#"ã?D?¤ó â8?Ât¢ÄC ?¤Ä?-?Å#"ãÄÂĤó âÄ%Â?¢¤C ?¤Ä?Å?Å#¢ã?DÆÂ?ó âÄ?Âj¢ÄC ?¤ÄÄ?¥#"ã?Â{¤ó âÄ?Â?¢¤C ?¤ÄTÅ?¥#Îã?Â?¤ó â8?Â?¢Ä? ?¤Ä??¥#"ãĤÂÄó?âÄ¥Â?¢¤C ?DÄ?Å?¥#"ã¤úmÂ?ó âÄ?Â?¢¤C ?¤Å[Ä?¥³"ã?DDÆó âÄ?Â?¢¤C ?¤?Å?%#"ãÄÂ?Â¥ó âÄ?¤¢¤C ?¤Å?Å??#"ã?Â?"?ó âÄ?Â?¢hC ?¤Å?Än?³"ã¤ÂF? â8?Â?¢¤? ?¤Å?Ä??#"ã?Â¥Âeó âÄ?Â?¢|C ?¤Ä?Å?¥#"ãdÂEÆó âÄ?¤J¤C ?¤Ä?Ån?#"ãÄÂ¥ÂÄó âÄ?Â?¢¤» ?\Ä?%?Å#"ã¤ÂÄÂ?ó âÄ?Â?¢Ä» ?¤$?ÅC[#"ãĤÂDó âÄ?Â?¢jC ?¤Å?%?Å#"ãÄÂ?øÄó âÄ?Â?¢?C
¤Å?Å??#¢ã?Â$¤ó âÄ?Â?H¤C ?¤Ä\Å?¥#"ãÄÂÂ?ó?âÄJÂ?¢¤C ?¤Å?Åf?#"ã?D¦Â¤ó âÄ?Â?B¤C ?¤Å?Å??#"ã¤Â¥Â?ó âÄ?Â?¢ÄC ¤Ä?Å?Å#"ãÄÂ?¤ó?âÄ¥Â{¢¤C ?ZÄ?Ä?Å#"ãĤ¤ó âÄ?Â?¢¤C ¤Å?Ä??#"ã?Â[Â?ó âÄ?Â?¢BC ?¤Å?Å?¥#"ãÄÂ?Â?ó âÄ?Âj¢¤¸ ?d%?E?¥#"ãh¤Âdó bÄ?Â?¢Ä¹ ?¤Ä?Å??#"MĤÂ?ó âÄ?ÂD¢¤C ?¤?Æ?Å#"ã?DZF?e ½âÄ?Â?¢DC ?¤Å[Ä?{#S!?#C? âÄ?:?¢ÄC ?dÅ?Äfu#"ã¤Â?¤ó âÄ?Â?¢jC¼?¤*?Æ?¥#"ã¤Â¤Â¤ó âÄ?Â?¢?¹ ?¤Å?Å??#"ã¤aBeRø âÄ?Â?¢Äà ?¤Å?Å¥#"ã¤ÂÄÂXó âÄ?Â?J¤C ?¤Æ??Å#"KĤÂ?ó?âÄ?¤¢ÄC ?¤Æ?Ä?Å#"ãHÂ?¤ó âÄ?Â?¢ÄC ?¤?Å??£"ãĤÂDó Þq8?Â?¢lC ?¤$?Å?¥#"ã?Â?:¤ó ½âÄ?8?¢¤C ?¤Å?$??#"ã?ÂF?d â8?Â?¢¤C ?¤Å?Ä?#"ã?DXE?f âÄ?Â?¢jC ?¤(?Ä??3"ã?ÂÄÂ?ó âÄ?@?¢ÄC ¤Å?Å?¥#"ã??D?e âÄKÂ?¢ÄC ?¤Ä?+?u#"ïÄ:ÄÂ?ó âÄKÂ?¢¤C ?¤Å?Ä?¥#"ã¤B¤Â¤ó âÄ?¤¢ÄC ?¤Å[Ä?y#"ãĤ¤ó âÄ?Âd¢¤C ?¤E?Ä?¥#"ã?ÂD¤ó âÄ?a[¢¤C ?¤Å?Åf¥#"ã?¤ú¤ó âÄ?ÂdjÄC ?¤Ä?bC[#"ãX¤Â?ó âÄ]Â?¢lC
¤Å?Äf¥#"ãÄÂj¤ó J8?¤¢¤C ?¤Å?+?¥
(these are the actual readings copied from the serial monitor)
I have no idea why this is happening . Is it possible that I damaged the sensor when soldering the header? Or any other reason as to why this is happening? I am totally new to sensors.
Any help would be much appreciated.
This is the program I have used
#include <Wire.h>
// Registers for ADXL345
#define ADXL345_ADDRESS (0xA6 >> 1) // address for device is 8 bit but shift to the
// right by 1 bit to make it 7 bit because the
// wire library only takes in 7 bit addresses
// Need to set the power control bit to wake up the adxl345
#define ADXL_REGISTER_PWRCTL (0x2D) // Power register
#define ADXL_PWRCTL_MEASURE (0x08)
// There are 6 data registers, they are sequential starting with the LSB of X.
// We'll read all 6 in a burst and won't adress them indivisually
#define ADXL345_REGISTER_XLSB (0x32)
// Registers for ITG3200
#define ITG3200_ADDRESS (0xD0 >> 1)
// Again request data of 6 bytes in a burst
#define ITG3200_REGISTER_XMBS (0x1D)
// Initialise low pass filter
#define ITG3200_REGISTER_DLPF_FS (0x16)
// Initialise scale
#define ITG3200_FULLSCALE (0x03 << 3)
#define ITG3200_42HZ (0x03)
// Registers for HMC5843
#define HMC5843_ADDRESS (0x3C >> 1)
// First data address of 6 is XMSB.
// Need to set measurement to continuous or else will just get 1 reading
#define HMC5843_REGISTER_XMSB (0x03)
#define HMC5843_REGISTER_MEASMODE (0x02)
#define HMC5843_MEASMODE_CONT (0x00)
int accelerometer_data[3];
int gyro_data[3];
int magnetometer_data[3];
// void because this only tells the cip to send data to its output register
// writes data to the slave's buffer
void i2c_write(int address, byte reg, byte data) {
// Send output register address
Wire.beginTransmission(address);
// Connect to device
Wire.write(reg);
// Send data
Wire.write(data); //low byte
Wire.endTransmission();
}
// void because using pointers
// microcontroller reads data from the sensor's input register
void i2c_read(int address, byte reg, int count, byte* data) {
// Used to read the number of data received
int i = 0;
// Send input register address
Wire.beginTransmission(address);
// Connect to device
Wire.write(reg);
Wire.endTransmission();
// Connect to device
Wire.beginTransmission(address);
// Request data from slave
// Count stands for number of bytes to request
Wire.requestFrom(address, count);
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
data[i] = c;
i++;
}
Wire.endTransmission();
}
void init_adxl345() {
byte data = 0;
// Wake the accelerometer up by sending setting the measure bit (0x08) to the
// power register (0x2D)
i2c_write(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, ADXL_PWRCTL_MEASURE);
// Check to see if it worked!
i2c_read(ADXL345_ADDRESS, ADXL_REGISTER_PWRCTL, 1, &data);
Serial.println((unsigned int)data);
}
void read_adxl345() {
byte bytes[6];
memset(bytes,0,6);
// Read 6 bytes from the ADXL345
i2c_read(ADXL345_ADDRESS, ADXL345_REGISTER_XLSB, 6, bytes);
// Unpack data
for (int i=0;i<3;++i) {
accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);
}
}
void init_itg3200() {
byte data = 0;
// Set DLPF to 42Hz (can change if want) and set scale to full scale
i2c_write(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, ITG3200_FULLSCALE | ITG3200_42HZ);
//check if working
i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, 1, &data);
Serial.println((unsigned int)data);
}
void read_itg3200() {
byte bytes[6];
memset(bytes,0,6);
//read 6 bytes from the ITG3200
i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_XMBS, 6, bytes); //now unpack the bytes
for (int i=0;i<3;++i) {
gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
}
}
/*void read_itg3200() {
byte bytes[6];
memset(bytes,0,6);
// read 6 bytes from the ITG3200
i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_XMBS, 6, bytes);
// unpack data
for(int i=0; i<3; ++i) {
gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
}
}*/
void init_hmc5843() {
byte data = 0;
// set to continuous measurement
i2c_write(HMC5843_ADDRESS, HMC5843_REGISTER_MEASMODE, HMC5843_MEASMODE_CONT);
// check if worked
i2c_read(HMC5843_ADDRESS, HMC5843_REGISTER_MEASMODE, 1, &data);
Serial.println((unsigned int)data);
}
void read_hmc5843() {
byte bytes[6];
memset(bytes,0,6);
// read 6 bytes from the HMC5843
i2c_read(HMC5843_ADDRESS, HMC5843_REGISTER_XMSB, 6, bytes);
// now unpack the bytes
for(int i=0; i<3; ++i) {
magnetometer_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
}
}
// initialise and start everything
void setup() {
Wire.begin();
Serial.begin(9600);
for(int i=0; i<3; ++i) {
accelerometer_data[i] = magnetometer_data[i] = gyro_data[i] = 0;
}
init_adxl345();
init_itg3200();
init_hmc5843();
}
void loop() {
read_adxl345();
Serial.print("ACCEL: ");
Serial.print(accelerometer_data[0]);
Serial.print("\t");
Serial.print(accelerometer_data[1]);
Serial.print("\t");
Serial.print(accelerometer_data[2]);
Serial.print("\n");
read_hmc5843();
Serial.print("MAG: ");
Serial.print(magnetometer_data[0]);
Serial.print(",");
Serial.print(magnetometer_data[1]);
Serial.print(",");
Serial.print(magnetometer_data[2]);
Serial.print("\n");
read_itg3200();
Serial.print("GYRO: ");
Serial.print(gyro_data[0]);
Serial.print("\t");
Serial.print(gyro_data[1]);
Serial.print("\t");
Serial.print(gyro_data[2]);
Serial.print("\n");
delay(100);
}
Thanks in advance