Code explanation and Openlog data reading problem

Asked by Suleman Mehmood

Hello Fabio,

I hope you are doing fine and many thanks for solving my problem earlier. I have couple of question from the code you provided me last time. I need to understand them as i have to explain in my project report. In earlier message you gave me this code:
#include <FreeSixIMU.h>
#include <FIMU_ADXL345.h>
#include <FIMU_ITG3200.h>
#include <Wire.h>

float angles[3]; // yaw pitch roll
int raw[6];//***
// Set the FreeSixIMU object
FreeSixIMU sixDOF = FreeSixIMU();

void setup() {
  Serial.begin(115200);
  Wire.begin();

  delay(1);
  sixDOF.init(); //begin the IMU
  delay(1);

  //**Serial.print("eulerX\teulerY\teulerZ\traw1\traw1\traw3\n");
}

void loop() {
  sixDOF.getRawValues(raw); //***
  delay(200);

  Serial.print(raw[0]);//***
  Serial.print(","); //***
  Serial.print(raw[1]);//***
  Serial.print(","); //***
  Serial.print(raw[2]);//***
  Serial.print(","); //***
  Serial.print(raw[3]);//***
  Serial.print(","); //***
  Serial.print(raw[4]);//***
  Serial.print(","); //***
  Serial.print(raw[5]);//***
  Serial.print("\n"); //***

  delay(200);
}

You will get 6 values:
acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z

You can convert the acc values into g (gravity) units by dividing them
by 256.

You can convert the gyro values into deg/sec by dividing them by 14.375.

Ok now i understand that in order to get acc value i have to divide by 256 because its 8 bits.. and 2^8 = 256... Can you explain y do we have to divide if i am wrong. What value of g i will get i.e.(1g, 2g, 4g, ???). Also can you explain in order to get gyro values by do we have to divide by 14.375. Can i ask you to please explain me in detail so that it would help me elaborate in my report.

My 2nd question : I have connected OpenLog from sparkfun with Arduino Pro mini to save data on SD card. The good news open log is working fine and managed to save some data. But data is coming in one line rather than saving 6 reading is one line. I will post some results to explain what i mean. Results are as follows:

293,-49,28,26,13,-7292,-51,31,23,5,4292,-49,29,23,9,8293,-49,33,23,5,-17293,-48,29,19,4,-4292,-48,30,20,6,14293,-49,30,23,1,-6

It should be like this
293,-49,28,26,13,-72
92,-51,31,23,5,42
92,-49,29,23,9,82
93,-49,33,23,5,-172
93,-48,29,19,4,-42
92,-48,30,20,6,142
93,-49,30,23,1,-6

I m running OpenLOg at 9600 Baud.

Please help me thanks

Regards
Suleman Mehmood

Question information

Language:
English Edit question
Status:
Solved
For:
FreeIMU Edit question
Assignee:
No assignee Edit question
Solved by:
Fabio Varesano
Solved:
Last query:
Last reply:
Revision history for this message
Best Fabio Varesano (fabio-varesano) said :
#1

> Ok now i understand that in order to get acc value i have to divide by 256 because its 8 bits.. and 2^8 = 256

No, it's not a matter of bit and bytes but it's about sensor sensitivity. See page 4 at http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf ... note how it is 256 LSB/g at 2g sensitivity. If you divide the read value by 256 you are transforming the value from internal units into g units. Use floats to keep the precision.

The same motivation is for the 14.375... if you go into the ITG3200 you'll see that this is the scale factor of the sensor to convert a raw reading into degrees/sec.

I don't have any experience with the OpenLog software. Check that both the Arduino and OpenLog are using the same Serial speed. Also, note that the format used in the FreeIMU raw output only uses '\n', the newline character, to represent a new line while in Windows usually programs need '\n\r' to correctly display a newline. Try opening the resulting file with an editor like Jedit which should understand the file correctly.

Revision history for this message
Suleman Mehmood (sulemanmehmood) said :
#2

Thanks Fabio Varesano, that solved my question.