Thursday, 18 September 2014

Using Arduino Uno to read Sparkfun Razor IMU (9DOF) output via Serial.

I had a lot of trouble with interpreting the output of the Sparkfun Razor IMU (9DOF) using Arduino Uno. Scouring the internet for previous solutions, I came to believe that the proper way to handle the output from the IMU required massaging the bytes obtained via Serial.read(). However, it turns out that the solution is as simple as interpreting each byte as an ASCII character (type: char). Here's what worked for me:

Hardware:
Connect the following pins.
Arduino --- IMU
RX --- TX
TX --- RX
3.3V --- 3.3V
GND --- GND

On the IMU board, CTS (Clear To Send) and DTR (Data Terminal Ready) do not require a connection for Serial. They are used for the FTDI Serial to USB connection.


Software:

On the Arduino Uno - Below is the simplest, baseline code you need to read the output from the IMU using another Arduino (I say another because the IMU contains its own ATMega chip):

When writing new sketches to the Arduino, you'll need to unplug the RX/TX 

On the Sparkfun Razor IMU - load the code found on here: https://github.com/ptrbrtz/razor-9dof-ahrs/wiki/Tutorial If you want to change the Serial output of the IMU, modify Output.ino within the Razor_AHRS folder in this conditional:




10 comments:

  1. Hi Ben, I was wondering if you could provide some tips on how to convert the serial data into float or integer types. I would like to use the Razor 9DOF IMU as a sensor connected to Arduino Uno that would trigger an LED to be lighted up. Thanks.

    ReplyDelete
    Replies
    1. Hi Nathan, you can use something like an atoi function. Arduino has a version here: https://www.arduino.cc/en/Tutorial/StringToIntExample
      You can then type cast to the variable type that you'd like. Let me know if that works!

      Delete
  2. Hey Ben, even I m working on retrieving 9DOF RAZOR SPARKFUN IMU values.
    I am using Arduino UNO. And i have done the connection just as you mentioned. While uploading the code(Razor_AHRS) on the IMU, i remove the Rx--Tx( UNO---IMU). And then I make the connection again, and open the serial output window. The issue is that I get no values, as in YawPitchRoll(0,0,0)..may be float.(0.0,0.0,0.0)...Please share your insight on it. I am trying to develop a system out of 9DOF IMU..Please help...
    Truly appreciate for your time and consideration.
    --Sovik

    ReplyDelete
    Replies
    1. Hi Sovik, maybe check if the indicator LEDs on the IMU are blinking to see if it's indeed sending information. Also check your transmission baud rates to see if your devices are talking at the right frequency. Sorry for the slow response and let me know if that helps!

      Delete
  3. hai ben, what type of ftdi can we use for these razon imu

    ReplyDelete
    Replies
    1. Anything that converts between serial and USB.

      Delete
  4. i am using CH340g usb to ttl. circuit break board. but its not working. while upload a program, its just shows uploading.... upload can't be completed.

    ReplyDelete
    Replies
    1. Try swapping out either your board or cable to identify where the fault is occurring.

      Delete
  5. what is the unit for values of three sensors(accele, gyro, magno) inside these imu.

    ReplyDelete
  6. I have done exactly the way you said. but the comport isn't showing anything. can you tell me the reason.

    ReplyDelete