Reading data from/Interfacing with 9DOF Razor IMU

Hello everyone,

I'm having some trouble interfacing my 9DOF Razor IMU (SEN-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, 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 (

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 IMU GND >> Uno GND

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?

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 ?

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):

      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:

String sensorData;
char c;
void setup() {
  Serial.println("9DOF Test"); 
void loop() {
  while (Serial.available()) {  
    if (Serial.available() >0) {
    c =; 
    //sensorData += c; //adds c to the sensorData string
       Serial.print(c); //see whatever came in on
  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 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.



Hi all

I am using the Razor IMU with an Arduino 1

thie is the code:

#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3);
String buff;
String prueba;
int posicioncoma;
int posicioncomaaux;
int posasterisco;
String valor9;
String valor8;
String valor7;
String valor6;
String valor5;
String valor4;
String valor3;
String valor2;
String valor1;
String valor0;

void setup() {
void loop() {
      char in = (char);
      buff += in;

        posicioncoma = buff.lastIndexOf(',');
        posasterisco = buff.lastIndexOf('#');
        valor9 = buff.substring(posicioncoma+1,posasterisco);
        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor8 = buff.substring(posicioncomaaux+1,posicioncoma);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor7 = buff.substring(posicioncoma+1,posicioncomaaux);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor6 = buff.substring(posicioncomaaux+1,posicioncoma);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor5 = buff.substring(posicioncoma+1,posicioncomaaux);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor4 = buff.substring(posicioncomaaux+1,posicioncoma);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor3 = buff.substring(posicioncoma+1,posicioncomaaux);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor2 = buff.substring(posicioncomaaux+1,posicioncoma);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor1 = buff.substring(posicioncoma+1,posicioncomaaux);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor0 = buff.substring(posicioncomaaux+1,posicioncoma);


The problem is that i obtain a String like that. I can also separate these numbers of the String and convert them to In but the main problem is that i have no idea about what these numbers mean.


I tried to rotate the imu in one axis and some number changes, but these number that changes movimg one axis also change moving another.

Could someone help me to know how to obtain the pitch, yaw and roll angles instead of these?

Thanks in advance

I’m parsing using strtok for my IMU’s.

char delimiters = “,#”;
char* valPosition;

valPosition = strtok(input, delimiters);

for (int i = 0; i < outSize; i++) {
out = atoi(valPosition); //changing atoi to atof converts from strings to floats

  • valPosition = strtok(NULL, delimiters);*
  • }*
    atoi converts the incoming number stream into 16 bit integers

but my problem is not parsing, my problem is that i have no idea if some of these numbers are the real Yaw, pitch and roll angles, because i have try to find out if any of them are these angles by moviming the imu but my conclusion is that NO.

I have seen that in some tutorials not using arduino UNO, the obain a String as YPR = 23,23,34 and i am obtaining just these 9 numbers that i think that they are the 9 degrees of freedom of the imu without processing


If I may get back to the OP's issue...


Did you ever get a resolution to your issue??? I don't see any directly related solutions listed in this thread that have to do with your original posting. I have the exact same issue and am not sure what to do about it. Thanks, Sam