sketching to read 3 dof IMU combo board

Hi,
I have little programming experience. I have brought a 3 dof IMU combo board (2axis accelerometer and 1 axis gyroscope) from spark fun and would like to read the sensors through my USB arduino. Can some one help me or point me in the right direction to write the code for the program.
http://www.sparkfun.com/products/9249
A description of hardware connections will also prove to be really helpful

Thanks a lot

Start with a simpler project, like reading the analog value a potentiometer wired between +5V & GND.
You are starting out with too much here.

The board (based on the Sparkfun IMU_Combo_Board-v2.pdf doc) produces analog voltages on each of the output pins..

You need to wire the power leads between the arduino and the board;- gnd and +5v.
Be careful that gnd is linked to gnd and 5v is linked to 5v..

Then pick one of the outputs and wire it to analog pin 0. (i would use 9 or 10 which are the acceleration sensors and will react as you tilt the sensor).

And use the example sketch AnalogInput (which you can find in the File-menu/examples).

have fun :slight_smile:

Thank you for your replies
@crossroads I know I am chewing off more than I can bite but I have already tried and successfully varied the speed of a dc motor using a potentiometer and the arduino.
@dafid Thanks for the procedure. I managed to read the inputs using the code given here
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284738418
********** sketch ******************
// Main module K_bot angles in Quids, 10 bit ADC -------------
// 4 - Checking sensor data format display raw sensors data

#include <math.h>

#define GYR_Z 2 // Gyro Z (IMU pin #7)
#define ACC_X 0 // Acc X (IMU pin #1)
#define ACC_Y 1 // Acc Y (IMU pin #2)

int STD_LOOP_TIME = 9;

int sensorValue[3] = { 0, 0, 0};
int sensorZero[3] = { 0, 0, 0};
int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;

void setup() {
analogReference(DEFAULT); // Aref 5V
Serial.begin(115200);
delay(100);
calibrateSensors();
}

void loop() {
// ********************* Sensor aquisition & filtering *******************
updateSensors();

// ********************* print Debug info *************************************
serialOut_raw();

// *********************** loop timing control **************************
lastLoopUsefulTime = millis()-loopStartTime;
if(lastLoopUsefulTime<STD_LOOP_TIME) delay(STD_LOOP_TIME-lastLoopUsefulTime);
lastLoopTime = millis() - loopStartTime;
loopStartTime = millis();
}

void serialOut_raw() {
static int skip=0;
if(skip++==40) {
skip = 0;
Serial.print("ACC_X:"); Serial.print(sensorValue[ACC_X]);
Serial.print(" ACC_Y:"); Serial.print(sensorValue[ACC_Y]);
Serial.print(" GYR_Z:"); Serial.println(sensorValue[GYR_Z]);
}
}

// Sensors Module ---------------------------------------------------------------------

void calibrateSensors() { // Set zero sensor values
long v;
for(int n=0; n<3; n++) {
v = 0;
for(int i=0; i<50; i++) v += readSensor(n);
sensorZero[n] = v/50;
}
sensorZero[ACC_X] -= 205;
}

void updateSensors() { // data acquisition
long v;
for(int n=0; n<3; n++) {
v = 0;
for(int i=0; i<5; i++) v += readSensor(n);
sensorValue[n] = v/5 - sensorZero[n];
}
}

int readSensor(int channel){
return (analogRead(channel));
}

However I am having a hard time trying to understand the output in the serial monitor.
when X points upwards, Y points to the left and Z goes into the plane.
I get the following serial monitor output.

ACC_X:204 ACC_Y:0 GYR_Z:119
ACC_X:205 ACC_Y:0 GYR_Z:126
ACC_X:205 ACC_Y:0 GYR_Z:122
ACC_X:205 ACC_Y:0 GYR_Z:119
ACC_X:204 ACC_Y:0 GYR_Z:121
ACC_X:205 ACC_Y:0 GYR_Z:115
ACC_X:205 ACC_Y:0 GYR_Z:122
ACC_X:205 ACC_Y:0 GYR_Z:120
ACC_X:205 ACC_Y:0 GYR_Z:120
ACC_X:205 ACC_Y:0 GYR_Z:122
ACC_X:205 ACC_Y:0 GYR_Z:127
ACC_X:204 ACC_Y:1 GYR_Z:118
ACC_X:205 ACC_Y:0 GYR_Z:125
ACC_X:205 ACC_Y:0 GYR_Z:132
ACC_X:205 ACC_Y:0 GYR_Z:123
ACC_X:204 ACC_Y:1 GYR_Z:113
ACC_X:204 ACC_Y:0 GYR_Z:123
ACC_X:205 ACC_Y:0 GYR_Z:123
ACC_X:205 ACC_Y:0 GYR_Z:117
ACC_X:205 ACC_Y:0 GYR_Z:121
ACC_X:205 ACC_Y:0 GYR_Z:126
ACC_X:205 ACC_Y:0 GYR_Z:120
ACC_X:204 ACC_Y:0 GYR_Z:118
ACC_X:204 ACC_Y:0 GYR_Z:122
ACC_X:204 ACC_Y:0 GYR_Z:121
ACC_X:205 ACC_Y:0 GYR_Z:125

sorry for such a long post. I could not figure out how to paste for forum.
Thanks a lot

PS: shouldn't Gyro Z be zero?

That thread refers to a different sensor board

#define   GYR_Z                 2                              // Gyro Z (IMU pin #7)
#define   ACC_X                 0                              // Acc  X (IMU pin #1)
#define   ACC_Y                 1                              // Acc  Y (IMU pin #2)

These IMU pin numbers are not correct for the board you linked to in the first post IMU Combo Board - 3 Degrees of Freedom - ADXL203/ADXRS614 - SEN-09249 - SparkFun Electronics.

Nothing much can be said with out correct understanding of how the arduino is linked to the sensors.

To insert code into the post use the # button (3rd last bottom row).

hi, I am doing the same thing as you for my Final Year Project, I'm also a newbie in programming and had no idea why am I chosen for this project, I wish you could tell me how do u connect your Arduino to the IMU combo Board. My Arduino board is Arduino Pro Mini, http://www.sparkfun.com/products/9218, but i believe that it's the same. I couldn't get any number at all. I suspecting something went wrong, but I do not which. please tell me which 1 i wrong

AI0 = RATE
AI1 = ACC Y
AI2 = ACC Z

but i get "$"c?b aâ?!C÷??$"c?b aâ?!C÷??$"c?b aâ?!C÷??$"c?b aâ?!C÷??$"c?b" this as a result .. please help me.

Hitmitsu,

Start a new thread as your problem is likely different, and discussion will be confused otherwise.
Post your code and a schematic of the wiring.
Tell us what the sensor board is.
Explain what you where doing when the output was generated.

With all of the above, perhaps someone can help you

@hitmitsu I got the same problem when i first tried. Check if you are using the right Reference voltage. Is it 3V or 5V ? ...instead of EXTERNAL in the code to read reference voltage use the DEFAULT and connect it to the 5V pin or 3V pin on the arduino

@ dafid I have begun to grasp the values ..
All the sensors are at least logically transmitting data (ie. x axis values change when orientation is changed etc etc)
But the Y axis values still show values which are all positive. Shouldn't the values change sign as well.
yes.. You are right those are not the right pin numbers for my board. But since they are commented ... i figuered it would not make much of a difference..

I have connected X acceleration to AI1, Y acceleration to AI2 and gyro Z on AI0
This is the current code and the output in the serial monitor when x is pointing upwards, y pointing to the right and z pointing inwards

 // Main module   K_bot               angles in Quids, 10 bit ADC  -------------
// 4 - Checking sensor data format    display raw sensors data            

#include <math.h>

#define   GYR_Z                 0                              // Gyro Z (IMU pin #7)
#define   ACC_X                 1                              // Acc  X (IMU pin #1)
#define   ACC_Y                 2                              // Acc  Y (IMU pin #2)

int   STD_LOOP_TIME  =          9;            

int sensorValue[3]  = { 0, 0, 0};
int sensorZero[3]   = { 0, 0, 0};
int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;

void setup() {
  analogReference(DEFAULT);                                   // Aref 5V
  Serial.begin(115200);
  delay(100);                                                
  calibrateSensors();
}

void loop() {
// ********************* Sensor aquisition & filtering *******************
  updateSensors();

// ********************* print Debug info *************************************
  serialOut_raw();

// *********************** loop timing control **************************
  lastLoopUsefulTime = millis()-loopStartTime;
  if(lastLoopUsefulTime<STD_LOOP_TIME)         delay(STD_LOOP_TIME-lastLoopUsefulTime);
  lastLoopTime = millis() - loopStartTime;
  loopStartTime = millis();
}

void serialOut_raw() {
static int skip=0;
  if(skip++==40) {                                                        
    skip = 0;
    Serial.print("ACC_Y:");           Serial.print(sensorValue[ACC_Y]);          
    Serial.print("  ACC_X:");         Serial.print(sensorValue[ACC_X]);
    Serial.print("  GYR_Z:");         Serial.println(sensorValue[GYR_Z]);
  }
}

// Sensors Module  ---------------------------------------------------------------------

void calibrateSensors() {                                       // Set zero sensor values
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<50; i++)       v += readSensor(n);
    sensorZero[n] = v/50;
  }                                                          
  sensorZero[ACC_X] += 205;                        
}

void updateSensors() {                                         // data acquisition
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<5; i++)       v += readSensor(n);
    sensorValue[n] = v/5 - sensorZero[n];
  }
}

int readSensor(int channel){
  return (analogRead(channel));
}
ACC_Y:8  ACC_X:-205  GYR_Z:-3
ACC_Y:5  ACC_X:-206  GYR_Z:-2
ACC_Y:7  ACC_X:-205  GYR_Z:-6
ACC_Y:6  ACC_X:-205  GYR_Z:-1
ACC_Y:8  ACC_X:-206  GYR_Z:-5
ACC_Y:7  ACC_X:-205  GYR_Z:-7
ACC_Y:7  ACC_X:-205  GYR_Z:3
ACC_Y:6  ACC_X:-205  GYR_Z:5
ACC_Y:7  ACC_X:-205  GYR_Z:-8
ACC_Y:7  ACC_X:-205  GYR_Z:0
ACC_Y:7  ACC_X:-205  GYR_Z:1
ACC_Y:8  ACC_X:-205  GYR_Z:-2
ACC_Y:5  ACC_X:-205  GYR_Z:-1
ACC_Y:9  ACC_X:-205  GYR_Z:-5
ACC_Y:5  ACC_X:-205  GYR_Z:-3
ACC_Y:8  ACC_X:-206  GYR_Z:-3
ACC_Y:9  ACC_X:-205  GYR_Z:1
ACC_Y:6  ACC_X:-205  GYR_Z:6
ACC_Y:7  ACC_X:-206  GYR_Z:-3
ACC_Y:8  ACC_X:-205  GYR_Z:-9
ACC_Y:5  ACC_X:-206  GYR_Z:3
ACC_Y:8  ACC_X:-205  GYR_Z:-1
ACC_Y:5  ACC_X:-205  GYR_Z:-3

Thanks a lot for your responses

Your sensor module seems a bit strange to me.
It adjusts readings relative to the first position of the board.
And then it adjusts the X readings by 205?

So the values displayed can not be interpreted without knowing the initial position.
And the X values require mental arithmetic after that.

Do have a reason for this?

// Sensors Module  ---------------------------------------------------------------------

/* dafid - this is called in the setup() and calculates a 'zero' value that is used to adjust 
subsequent readings.
 */
void calibrateSensors() {                                       // Set zero sensor values
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<50; i++)       v += readSensor(n);
    sensorZero[n] = v/50;
  }
/* dafid - except the X axis is specially offset by 205.
      I do not understand why you do this at all.
*/                                                         
  sensorZero[ACC_X] -= 205;                       
}

void updateSensors() {                                         // data acquisition
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<5; i++)       v += readSensor(n);
    sensorValue[n] = v/5 - sensorZero[n];
  }
}

The link I gave in the first post actually set this value to 102 and the reasoning given for that on the link is as follows:
For ADXL330/335: 1g = 330 mV (+- 10%)
ACC_Z correction for 10 bit ADC and 3.3V AREF: 330/3300*1024 = 102 (to be fine tuned later on)

Based on a logic I quite don't understand myself, I decided to give a try based on my own sensors. So,
For ADXL203: 1g = 1000 mV (+- 10%)
ACC_Z correction for 10 bit ADC and 5V AREF: 1000/5000*1024 = approximately 205 (to be fine tuned later on)

I really have no idea, about the inside workings of the code. I was hoping you could help me out over there. I am following the link and its code and modifying the code where I deem necessary.

Hope that made a little bit of sense.
Come to think of it I might have possibly realized the answer to my last question. as to Why the x axis sign does not change? Based on my reasoning the trignometrically one of the orthogonal axes do not change sign if rotated about the origin in the 1st and 2nd quadrants. And this axes should be the one facing vertically upwards .ie x axis in my case. So the X axis should not change sign... but it is... and Y axis should change sign but it isn't...

thanks..

Given your explanation above.. the sensorZero stuff is just confusing you and every one else.

I recommend you remove it until you find a reason for it.

And then you could display the value sensed as a simple integer...

I understand that the sensor reads 0g of acceleration as 2.5 V and varies that by 1V for each g.

So you might expect to see 2.5 v on two and either 1.5 or 3.5v on the other.

ie 512, 512, and 307 or 723.

As you say, the orientation of the sensor would determine which reading is which value.

@tejasinamda : I get the values alr .. the same codes as u

// Main module   K_bot               angles in Quids, 10 bit ADC  -------------
// 4 - Checking sensor data format    display raw sensors data            

#include <math.h>

#define   GYR_Z                 2                              // Gyro Z (IMU pin #7)
#define   ACC_X                 0                              // Acc  X (IMU pin #1)
#define   ACC_Y                 1                              // Acc  Y (IMU pin #2)

int   STD_LOOP_TIME  =          9;            

int sensorValue[3]  = { 0, 0, 0};
int sensorZero[3]   = { 0, 0, 0};
int lastLoopTime = STD_LOOP_TIME;
int lastLoopUsefulTime = STD_LOOP_TIME;
unsigned long loopStartTime = 0;


void setup() {
  analogReference(DEFAULT);                                   // Aref 5V
  Serial.begin(115200);
  delay(100);                                                
  calibrateSensors();
}

void loop() {
// ********************* Sensor aquisition & filtering *******************
  updateSensors();
  
// ********************* print Debug info *************************************
  serialOut_raw();

// *********************** loop timing control **************************
  lastLoopUsefulTime = millis()-loopStartTime;
  if(lastLoopUsefulTime<STD_LOOP_TIME)         delay(STD_LOOP_TIME-lastLoopUsefulTime);
  lastLoopTime = millis() - loopStartTime;
  loopStartTime = millis();
}

void serialOut_raw() {
static int skip=0;
  if(skip++==40) {                                                        
    skip = 0;
    Serial.print("ACC_X:");           Serial.print(sensorValue[ACC_X]);          
    Serial.print("  ACC_Y:");         Serial.print(sensorValue[ACC_Y]);
    Serial.print("  GYR_Z:");         Serial.println(sensorValue[GYR_Z]);
  }
}

// Sensors Module  ---------------------------------------------------------------------

void calibrateSensors() {                                       // Set zero sensor values
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<50; i++)       v += readSensor(n);
    sensorZero[n] = v/50;
  }                                                          
  sensorZero[ACC_X] -= 103;                        
}

void updateSensors() {                                         // data acquisition
  long v;
  for(int n=0; n<3; n++) {
    v = 0;
    for(int i=0; i<5; i++)       v += readSensor(n);
    sensorValue[n] = v/5 - sensorZero[n];
  }
}

int readSensor(int channel){
  return (analogRead(channel));
}

I am using Arduino ProMini + IMU Combo Board and i get this values

ACC_X:102 ACC_Y:0 GYR_Z:1
ACC_X:103 ACC_Y:0 GYR_Z:-2
ACC_X:102 ACC_Y:0 GYR_Z:1
ACC_X:103 ACC_Y:0 GYR_Z:2
ACC_X:103 ACC_Y:0 GYR_Z:1
ACC_X:103 ACC_Y:0 GYR_Z:0
ACC_X:102 ACC_Y:0 GYR_Z:0
ACC_X:102 ACC_Y:0 GYR_Z:2
ACC_X:102 ACC_Y:0 GYR_Z:2
ACC_X:102 ACC_Y:0 GYR_Z:-1
ACC_X:102 ACC_Y:-1 GYR_Z:4
ACC_X:103 ACC_Y:0 GYR_Z:1
ACC_X:103 ACC_Y:0 GYR_Z:-1
ACC_X:103 ACC_Y:0 GY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ACC_Y:1 GYR_Z:1
ACC_X:103 ACC_Y:0 GYR_Z:2
ACC_X:105 ACC_Y:1 GYR_Z:-1
ACC_X:102 ACC_Y:0 GYR_Z:1
ACC_X:102 ACC_Y:0 GYR_Z:2

i dunno if this values is correct or wrong. and i'm building something like a balancing robot but it's not a balancing robot. I need to connect my Arduino ProMini with IMU combo board and joystick and servo together. I do not understand how to use gyro to control my servo and the what readings does the servo read.. My Gyro is giving an unstable values which i think is not correct. but i got no idea how to correct. Please help ..