Interfacing 9DOF Razor IMU with Arduino Uno

Hello everyone,

First of all, this site has been very helpful and quite informative!  It's answered a lot of my questions in the past.  I used to do the RC plane thing a number of years ago, but now quadrotors have definitely caught my interest.  This time around, however, I haven't been so successful in finding help on the internet.  Hopefully someone here who's well versed in Arduino will be able to help me out on this one. 

Warning: long post ahead.


I'm having some trouble interfacing my 9DOF Razor IMU (SEN-10736; http://www.sparkfun.com/products/10736) with my Arduino Uno.  For those who don't know, this IMU has an 8 MHz Atmega 328 chip which is programmed via the Arduino IDE (selecting the Arduino Pro/Mini (3.3V, 8MHz) option as the board).

The AHRS code I'm using for the IMU is from https://dev.qu.tu-berlin.de/projects/sf-razor-9dof-ahrs, which uses a DCM filter to obtain pitch, yaw, and roll angles and outputs them via serial.  This works wonderfully, especially with the included Processing sketch (a 3D animation showing the board's orientation in real time...quite cool!).  I can also see the output by opening a serial monitor to the specified baud rate when the IMU is connected directly to my computer through an FTDI Basic Breakout board (http://www.sparkfun.com/products/9873).

However, I've run into some problems getting the Uno to get useable data from the IMU.  I've got them hooked up as follows:

IMU TX >> Uno Rx
IMU RX >> Uno TX
IMU 3.3V >> Uno 3.3V
IMU GND >> Uno GND

Uno >> PC via USB

Since the USB uses the RX/TX of the Uno, I plug in the IMU to the RX/TX ports after the sketch has uploaded to the Uno.

I'm thinking that my problem lies in the code.  First off, here's the output code from the IMU (just the very last output section; we're running at 9600 Baud):

Code:
 
Serial.println(TO_DEG(yaw));
Serial.println(TO_DEG(pitch));
Serial.println(TO_DEG(roll));


 I can read it in it's entirety via the serial monitor using the following code on the Uno:

Code:
 
String sensorData;
char c;
void setup() {
Serial.begin(9600);
Serial.println("9DOF Test");
}

void loop() {
while (Serial.available()) {
if (Serial.available() >0) {
c = Serial.read();
//sensorData += c; //adds c to the sensorData string
Serial.print(c); //see whatever came in on Serial.read()
}
}
if (sensorData.length() >0) {
Serial.println(sensorData); //output the string
readString=""; //resets reString for the next iteration of the loop
}
}


Since the IMU outputs using Serial.print, I can get a direct read out of the data from the IMU on the Uno.   However, when I print out "c" from Serial.read() it gives me back the ENTIRE data stream instead of just one byte of it.  Essentially, "c" and "sensorData" have the exact same data.

I want to be able to access each Euler angle (pitch, yaw, and, roll) independently as a number (int) so I can control the ESCs.  I was thinking that if I could get each piece of data as an independent string, I could convert each one to a character array using .toCharArray()  and then to an integer using atoi.  The main trouble I'm having is parsing the data from the IMU into 3 separate entities.


I'm sure there's something stupid I'm forgetting.  Or I could just be completely headed in the wrong direction.  Any help is much appreciated!

And sorry for the long post.

Thanks!

-Leo.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • can u post the libraries used in imu code

    i am using arduino uno to program imu 9dof razor , i got error

    stk500_getsync(): not in sync: resp=0x00

    i have made all the connections accordingly.

    can you help me find what went wrong , thanks in advance

  • Hey Leo, have you already figured out this issue? I have the same problem when trying to interface the Uno and the razor imu.

This reply was deleted.

Activity