Go Down

Topic: Reading data from/Interfacing with 9DOF Razor IMU (Read 7842 times) previous topic - next topic


Hello everyone,

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 (Inertial Measurement Unit) 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 (Attitude and Heading Reference System) code I'm using for the IMU is from https://dev.qu.tu-berlin.de/projects/sf-razor-9dof-ahrs, which uses a DCM (Direction Cosine Matrix) 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 IMU to talk to my Uno.  I've got them hooked up as follows:

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

Uno >> PC via USB

I've made multiple attempts in trying to access the IMU data from the Uno (as in, we're programming the Uno now) using the various Serial commands (for instance, variable = read() to obtain the data then store it to some variable, and write(variable) or print(variable) to see it in the serial monitor).  Since the IMU outputs the yaw, pitch, roll data as an array, I've also tried defining the output as an array, with similar results.  I get some numbers, but not getting anything that looks right.   

I'm aware that the USB uses the RX/TX of the Uno.  I plug in the IMU to the RX/TX ports after the sketch has uploaded.  Data shows up in the serial monitor after the IMU is connected, but it's nothing readable and I've double checked that everything's at the same baud rate, I'm accessing the right COM port and that everything is properly connected.  Same problem occurs when I use SoftwareSerial (on pins 2 and 3) as well.

There's loads of info of reading sensor data through analog or digital inputs, but I can't find much on serial.

I'm trying to get data from the IMU to control motors, servos, etc.

Sorry for the long post.  In light of that:

TL;DR  Tried everything I can think of, can't get the new(est) Sparkfun 9DOF IMU to talk to my Arduino Uno via serial.

I'm sure there's something stupid I'm forgetting.  Any help is much appreciated!




And how are you level-shifting the serial signals?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


Hello, thank you for your reply.

I don't think I'm doing any level-shifting; they're just straight wired via the RX and TX pins. 

I only have a rather superficial knowledge about logic-levels in general.  With this in mind, I can't seem to find at what level the IMU serial operates at.  How would I know if I need to shift levels and how would I go about doing so?  I see there are logic-level converters for sale on SparkFun for example.

Just for the sake of asking, would this have anything to do with the CTS and DTR pins on the IMU?  They're currently not hooked up to anything.  Again, I've only got a top-level idea of their functions (they're part of a serial port but are usually accompanied by DSR and RTS) so let's pretend I don't know anything: what exactly do these do? 

Thanks again!



You can't just connect 5V and 3V3 logic signals together and expect things to work - in fact you are more likely to damage something or put on of the chips into latch-up.  At the very least try series resistors (5k to 10k range say) between the two boards - should prevent damage.  And you have commoned the GND lines ?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


With all due respect, I'm not sure where you obtained those numbers from.  The IMU board operates at 3.3V.  Correct me if I'm wrong, but I don't think that's what defines the logic level.

In fact, I think the problem lies more in the code.  After several attempts, I finally got good, readable data.  However, it's still not what I need and I'm not sure where to go.  Here's the output code from the IMU (just the very last output section; we're running at 9600 Baud):

Code: [Select]

      Serial.println(TO_DEG(yaw)); //Serial.println();     
      Serial.println(TO_DEG(pitch)); //Serial.println();
      Serial.println(TO_DEG(roll)); //Serial.println();

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

Code: [Select]

String sensorData;
char c;
void setup() {
  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 that I may use them to control actuators (servos, motors, etc.).  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.

Any thoughts?


No one has any experience with this unit?   It strikes me odd that it'd be this difficult to get useful data off of this unit...otherwise what use does it serve? 

How about parsing serial streams?  Anyone know how to do that in the Arduino code? 

In C++ you can use the strtok function but I'm unsure how tokens work in Arduino code.



Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131