The 9DoF Razor IMU from Sparkfun


In one of the projects my team was working on at IIT Kanpur, we were supposed to conduct some ‘on-the-road’ tests on a parafoil. To measure the inertial parameters, we had to find out some cheap alternative to the costly Inertial Measurement Units (IMU) we had in our lab as rugged road test could have rendered them inaccurate. As Sparkfun Electronics happens to be our vendor of choice for this kind of stuff, it didn’t take us long to narrow down on the 9DoF Razor IMU. The Razor IMU was cheap, very light, small in size and most important of all, it was Open Source. The on-board sensors were of pretty high quality too. Perfect Choice!

Once we received the IMUs, testing them for functionality was pretty easy with the on-board firmware. Simply power them up, connect them to the PC through a USB to Serial converter and that’s pretty much it. I faced some problems with the magnetometer output and the on-board power supply, which I sorted out eventually, the technical support staff from Sparkfun told me that there was some inherent problem with the power supply design due to which the magnetometer malfunctioned sometimes. I have discussed the problem at length and the workaround in the following two videos on YouTube (read the description) :-

9DoF Razor IMU from SparkFun Malfunctioning

9DoF Razor IMU from SparkFun Functioning Properly

Currently, the Razor IMU’s product page on Sparkfun’s website states that they are coming up with a new version, I hope this issue won’t be there this time.

The IMU’s firmware (not talking about the factory burnt firmware for testing here) has been written in the Arduino environment. Being an Arduino illiterate, it took me quite some time to get it up and running. To help others like me, I wrote a step-by-step tutorial. I have also discussed about some modifications I did in the original source code. You might want to have a look……

SparkFun’s 9DoF Razor IMU Made Easy

If you are reading this then you probably don’t know anything about Arduino and Python(like me!) and have already spent a few frustrating hours trying to get this IMU up and running. I can understand that the python graphic interface video on the product page looks elusive now and is making you pull your hair off! No more headbanging! Simply follow the steps given below while enjoying a cheese pizza with coke and you’ll be just fine.

Uploading the AHRS code on the Razor

Recently I was informed by a dear friend of mine, Mr Emory Moody, that there have been some changes in the Arduino’s I2C library and the code referred in #1 below won’t compile. Emory figured out what needed to be changed and was generous enough to hand me over the modified code. You can download the modified code by clicking here. Now you can safely skip #1 below.

  1. Download the latest AHRS code from here.
  2. Download and install the latest Arduino IDE(arduino 0018) from here.
  3. Now you need to find a file called ‘boards.txt‘ in the installed Arduino directory. The path to this file is, Root Directory → arduino-0018 → hardware → arduino → boards.txt.
  4. Assuming that you have the latest Razor IMU boards from SparkFun which come fitted with an ATMega328p, open the boards.txt file and add the following lines at the bottom and save it.

###############################

atmega328.name=Sparkfun 9DOF Razor IMU with ATmega328p

atmega328.upload.protocol=stk500

atmega328.upload.maximum_size=30720

atmega328.upload.speed=57600

atmega328.bootloader.low_fuses=0xFF

atmega328.bootloader.high_fuses=0xDA

atmega328.bootloader.extended_fuses=0x05

atmega328.bootloader.path=atmega

atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex

atmega328.bootloader.unlock_bits=0x3F

atmega328.bootloader.lock_bits=0x0F

atmega328.build.mcu=atmega328p

atmega328.build.f_cpu=8000000L

atmega328.build.core=arduino

###############################

You need to perform this underground file manipulation because the Razor IMU has the ATMega328p deriving its clock from an 8MHz crystal oscillator while the preset board definitions assume the processor to be running at 16MHz. Note the second last line above,

  • atmega328.build.f_cpu=8000000L

If you don’t add the above stuff to the boards.txt file, you’ll still be able to upload the AHRS code on the IMU board but you’ll receive nothing but some weird ASCII characters on the terminal (like I did for two days!).

  1. Now connect your Razor IMU to the computer through the SparkFun’s FTDI Breakout board or some other USB-to-serial converter stuff (you are lucky if you have that thing called serial port still there).
  2. Uploading the AHRS code on the Razor IMU through Arduino IDE is pretty simple. Open all the files present in the SF9DOF_AHRS_1_0.zip (I am using version 1.0 for the time being) in the Arduino environment.
  3. Click on Tools → Boards → Sparkfun 9DOF Razor IMU with Atmega328p
  4. Click on Tools → Serial Port → Select the serial port on which Razor IMU has been connected.
  5. To upload the code on the board, click on File → Upload to I/O Board.
  6. You should then see the IDE compiling code and then burning it on the IMU board. Once ‘Done Uploading’, you can see the Razor IMU in action by opening a terminal software like Hyperterminal or RealTerm. Set the baud rate at 57600.

Python Graphic Interface for the Razor 9DoF IMU

I know you were waiting waiting for this! Its pretty simple…..

  1. Download and Install Python 2.6.5 and VPython from here.
  2. Download and Install PyWin from here.
  3. Download and Install PySerial from here.
  4. Download and Unzip (WHEW!!!) the graphic interface code from here.
  5. Open the IMU_Razor9DOF file in Notepad and set your COM port and the baud rate(57600 already) and save changes.
  6. Double Click IMU_Razor9DOF to run it and brace yourself for some cool graphical display of the IMU data. 🙂

Some playing around with the AHRS code

I have always been a WINAVR chap, but Arduino is fun and easy once you get familiar with it. I am not! But still, I thought why not play around with the AHRS code. I wanted to see the accelerometer readings apart from the Euler Angles which are shown on the terminal. Code is very much self-explanatory and anyone can easily modify it.

1. Open the file Output.pde in the Arduino IDE.

2. Replace the following piece of code

#if PRINT_EULER == 1

Serial.print(“ANG:”);

Serial.print(ToDeg(roll));

Serial.print(“,”);

Serial.print(ToDeg(pitch));

Serial.print(“,”);

Serial.print(ToDeg(yaw));

//Serial.print(“,”);

//Serial.print(ToDeg(MAG_Heading));

#endif

With this code

#if PRINT_EULER == 1

Serial.print(“ANG:”);

Serial.print(ToDeg(roll));

Serial.print(“,”);

Serial.print(ToDeg(pitch));

Serial.print(“,”);

Serial.print(ToDeg(yaw));

Serial.print(“,”);

Serial.print( Accel_Scale(accel_x) );

Serial.print (“,”);

Serial.print( Accel_Scale(accel_y) );

Serial.print (“,”);

Serial.print( Accel_Scale(accel_z) );

//Serial.print(“,”);

//Serial.print(ToDeg(MAG_Heading));

#endif

3. In the file SF9DOF_AHRS_1_0.pde the Accel_Scale macro has been erroneously defined as

#define Accel_Scale(x) x*(GRAVITY/9.81)

Change it to

#define Accel_Scale(x) x*(9.81/GRAVITY)

4. Compile and upload the program on the Razor IMU. Now you should see the accelerometer readings in meters per second per second on the terminal. Making these modifications does not affect the functionality of the Python Graphic Interface.

Thats all folks…..I hope you enjoyed your cheese pizza and coke! 🙂

About Pranjal Chaubey

An engineer, who believes in 'Being Wise, b.i.t.Wise!™'
This entry was posted in AVR, Tutorials, Utility and tagged , , , , , . Bookmark the permalink.

86 Responses to The 9DoF Razor IMU from Sparkfun

  1. Sebastian says:

    Hey thank you very much for this Tutorial.
    My prof wanted me to find that .
    I recognized some drifts but thats not your problem ^^

    • Thanks!
      Drifts will always be there as the Razor IMU code (and on-board processor) are very simplistic and don’t employ any sophisticated filtering algorithm (Kalman for example).

  2. Frederic C says:

    In your opinion, is it possible to post-process the accelerometer values to obtain a reliable displacement value in the x-y plane?
    And thanks for the post. Good catch on the gravity constant.
    Frederic

    • Thanks!
      You can always post-process to get the position but it can NEVER be reliable for a considerable amount of time, even with the best MEMS accelerometers in the world! It depends on how long you want to do it to get the position and how much positional error you can tolerate. The positional error will increase (without any bounds) with every passing second…….google about something called as Kalman Filter, its the only way out if you don’t want the error to keep on growing with time.

  3. hyosunkwon says:

    Thanks Pranjal,
    it was so much useful tutorial indeed.
    I have a question for further development though, do you have any clues to connect that arduino with processing?? I want to make a graphical contents according to the values that the sensor gives.

    Thanks again!

    • Thanks! 🙂
      You want to connect this with your computer/laptop?
      You can use the FTDI F232RL chip module from Sparkfun to connect it to the PC….but you must be doing that already for programming this IMU. Can you please elaborate ?

  4. sidhant says:

    Hey..Can you tell me about the Ultimate IMU from Sparkfun, Which one would be a better option, Ultimate with LPC or Razor with 328? Even im going with the UAV which needs good data rate, what would you suggest?

  5. Fan says:

    Sorry,Does anyone know how to modify AHRS code to calculate position and velocity in 3D translation or full 9DOF displacement? Thanks!

    • parimbaut says:

      this IMU can’t be used as such for velocity and position estimation because of the accelerometer drift (it needs an additional GPS to cope with that)

  6. testms says:

    You know how much it draws on the 3.3v line ? <50mA or more ?

  7. BGOOD says:

    Hello Pranjal!

    I have seen your videos on the sparkfun 9DOF yaw issues and I have tried to hook up 3.3v to the 9DOF directly. However, it still does not work. How exactly did you directly hook up 3.3v to the 9DOF board? The issue I am having looks just like the video you have of the sensor malfunctioning. Any ideas?

  8. Zeng says:

    When I upload the program, I keep getting the error:
    avrdude: stk500_getsync(): not in sync: resp=0x0d
    avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x0d

    I disconnected everything and connected them, for thousands of times, but I just can’t fix it. Did you ever have the same problem?

  9. Invicta says:

    Hi
    Thank you for the great article on the Razor 9DOF. Do you remember which version of the board you had? Did you ever come up with a fix for the board or did you continue to use the external regulated 3.3V from the FTDI breakout.

  10. sid says:

    Hey again. I’ve got a new Razor IMU from Sparkfun. And it comes preloaded with a firmware which transmits serial data of the sensors. Now is it possible to change in the code of python interface rather than loading the new firmware to the IMU?

    And in case I load the AHRS code in IMU, what type of data would be coming in as output(the format exactly), so that i can interface it with my Arduino board?

    • The first half of your comment in not exactly straightforward. What you are suggesting effectively means that you’ll have to port the AHRS code in python. But it not impossible though, you’ll be getting raw values from the sensors and will be processing the euler angles on the PC. Interesting!

      For this, I suggest you have a look at the AHRS code files. They are in arduino as well, should be no problem for you.

  11. Pingback: RAZOR IMU: Как прошить | MyLinks

  12. praveen says:

    do you hav eany idea to change sensor data rate from 50 hz to some other rate

    • You need to change the timing of the interrupt that does all the processing. I have a feeling that you can trim it down, i.e. sample at less than 50Hz, but you cannot go above 50Hz. The processing power in ATMega is very limited.

  13. Alvaro says:

    i read a char array of serial port and i get Euler angles correctly buy now i dont know how to split them to have pitch roll and yaw in c++ , i have tried with tokens (strtok)ut fails to do it correctly
    Any sugestion ?

    • I would suggest that you slightly modify the firmware of the IMU so that it only transmits the data when there’s a request (like transmit data only when IMU receives the character ‘T’ on the UART). In that way, you’ll be able to capture the complete string coming from the IMU, parsing it should be pretty easy.

  14. Muhammad Usman says:

    I followed the above tutorial in order to burn the code in IMU but when i burn this modified base code into the IMU’s Atmega328p ic using usb to serial Converter…i see the following error….

    “done uploading…
    avrdude: stk500_getsync(): not in sync: resp=0x00”

    now i tried to solve this error by the help of internet but i could not succeed…from the internet i found the information about this error as given below…

    “Check the following:
    If you have a NG Arduino, did you press reset just before selecting Upload menu item?
    Is the correct Serial Port selected?
    Is the correct driver installed?
    Is the chip inserted into the Arduino properly? (If you built your own arduino or have burned the bootloader on yourself)
    Does the chip have the correct bootloader on it? (If you built your own arduino or have burned the bootloader on yourself)
    Note that it is nearly impossible for anyone to debug this, as there are so many possible issues. Try everything.”

    Please tell me the procedure to get this error corrected….
    Waiting for reply and thanking in advance…

    • Marcos says:

      If using one cable USB -> TTL make sure to connect the DTR pin, arduino won’t be able lo load your programs if this pin is not connect

  15. eletrox says:

    hiiii …. i am using 16f877a for interfacing IMU…. any idea abt the code ???

    • You need to know how to use the UART peripheral on the 16F877A, as the IMU interfaces via the UART. Once you understand that, you can very easily write your own code. There are many examples out there on how to use the UART present on 16F877A, google them.

  16. Emory Moody says:

    Pranjal, I would like to thank you very sincerely on behalf of everyone who owns one of these versions of this board. I am also highly grateful that you continue to monitor this article. Thanks for helping to keep a useful tool useful.

  17. Emory Moody says:

    There is good discussion here, and you are providing a shred of hope for those who spent the money on these discontinued devices. Let’s face it, it makes for an expensive keychain and it is much better to find a practical use for the device. I am referencing the conversation below as this sort of application was exactly why I originally bought the device and my own research may be useful to anyone pursuing such an application.

    My team ran straight into math problems, specifically, not enough bit depth to retain accuracy.

    Hence, it does not seem possible to fully implement a Kalman Filter on an 8 bit processor but you may well be able to do so using a FPU like this one http://www.sparkfun.com/products/8129

    Emory

    Frederic C says:
    July 5, 2011 at 9:58 PM
    In your opinion, is it possible to post-process the accelerometer values to obtain a reliable displacement value in the x-y plane?
    And thanks for the post. Good catch on the gravity constant.
    Frederic
    Reply
    Pranjal Chaubey says:
    July 6, 2011 at 10:37 AM
    Thanks!
    You can always post-process to get the position but it can NEVER be reliable for a considerable amount of time, even with the best MEMS accelerometers in the world! It depends on how long you want to do it to get the position and how much positional error you can tolerate. The positional error will increase (without any bounds) with every passing second…….google about something called as Kalman Filter, its the only way out if you don’t want the error to keep on growing with time.

    • Emory Moody says:

      I forgot to add that as Sparkfun was wise enough to put vias on the board for the I2C bus, it is relatively simple to add a wired breakout board with the FPU on it.

  18. HI! So I have the 9DOF Razor program successfully installed and the board is being read by the computer. The program is communicating with the board, but displaying no data. When I run the python interface the roll, pitch, and yaw are all unresponsive (the proper COM port has been programmed). When I run the python shell I get a menu with options 1-5 including accerelrometer,magnetometer, gyroscope, raw output, change baud rate, and then toggle autorun and help. None of the options are clickable/inputable and they scroll up infinitely unless I hit the restart button on the IMU, which moves them back to the beginning and it starts to scroll up again.
    Do you know if the problem lies within the software? Or the board? They seem to be communicating but I’m getting no data and the menu is not working.
    Please let me know if you can/not help! Thank you!

    • Catch is, the razor IMU program does not show up any menu when you program it with the 9DoF code. It simply initializes and then starts sending out data at 57600 baud. Sparkfun actually sells the device with their own firmware, which is supposed to test the unit, which rolls out those 4-5 options that you have stated. On the face of it, it seems that you have tried to burn the 9DoF code in your IMU but for some reason that hasn’t happened. And going by your description, your hardware looks perfectly alright to me.

      Check out this link, and download the “SF9DOF_AHRS_1_0.zip” file (I use this one, other one also works fine).
      http://code.google.com/p/sf9domahrs/downloads/list

      Burn the above code in your IMU, inside the zip file, using the Arduino IDE. Your Razor should work fine after that.

  19. Jason says:

    Hi,
    I have a problem 🙂 I copy the configuration in the boards.txt file but Arduino respond:

    AVRDUD :can’t find programmer id

    Valid programmers are:….

  20. Asupathy says:

    how long it ll take to upload the file in the IMU board for me it is taking more than 15 minutes is there any problem

  21. Asupathy says:

    actually i m connecting through XBee the signal is transmitting from sensor to XBee but there the DOUT led is not blinking is there any mistake

  22. Asupathy says:

    i downloaded code from ur website . it is having more than one file which file i shd upload

  23. Asupathy says:

    what does it mean protocol error ,expect= 0*14,resp = 0*18

  24. Asupathy says:

    thanks ya as u said it is finely uploading in USB.actually i have some doubt in ur code

  25. Chan says:

    Hey Pranjal,

    I am trying to connect the Razor via a FTDI breakout board (3.3 V, 8 MHz), but it doesn’t recognize any serial ports to upload my sketch. Is there a fix to this or am I missing something?

    Thanks!

    • Have you installed the FTDI driver in your system? Search for FTDI driver on the internet and install their driver so that when you connect the USB, it shows up as a serial port. Then when you’ll open the Arduino IDE, you’ll see a serial port.

      • Chan says:

        I had actually done that, but turns out that my FTDI board had issues. Replacement board worked fine. Thanks though 🙂

  26. Amol Mahurkar says:

    Do you know any online shopping site from India where I get a IMU? (Looking for cheapest one.. accelerometer n gyro) I just found it on robokits.. (Don’t know whether to trust them) it’s costly.. It’s similar to one at sparkfun.. robokits copied all details except its datasheet .. robokits has new version..
    robokits: http://alturl.com/3oz2v (Is it trustworthy enough)
    sparkfun: http://alturl.com/57uvp
    Which should one I go for? (importing will cost veryhigh). or do u know any other place?

  27. ArduTest says:

    I installed all the python stuff and did all modifications to the razor lke described before.
    In the debug window of python i can see the output of the razor running.
    The two scenes of the python script keeps frozen, the scene with the arrow keeps grey.
    Is there anything i need to configure in the python runtime or is there anything else wrong?

    • Prima facie, this looks to be some VPython issue. Which OS you are running? Check if VPython is compatible with it..

      • ArduTest says:

        I´m running WinXP professional. I found somwhere in the internet a compiled C# executable which is using Python libraries. This works fine, but i cannot modify it.
        I also think this should be a Python issue, so i asked if there is any ajustment in the Python runtime. The serial comunication works well, i can see all the output values form the Razor in the debug window, only the graphic output seems to hang. If i modify the script, setting x/y/z manually to fixed values and deleting all the serial comunication, i get the graphical output working. Could that be any problem with refresh rates of the output window or do i have to force (somehow?) a screenupdate of the output window after recieving new values form the serial port? I never used Python before, so i try to get some help…
        Thanks for any idea..

        • Even I am not a python user, so can’t say much. Is your graphics card compatible with the Python Library?
          You might want to put this question on some Python forum with seasoned python coders around.

  28. Abhi Arora says:

    Sir , I was trying to get data serially from my imu
    (https://www.sparkfun.com/products/9623
    )…
    For that i have opened serial monitor in arduino and changed the board
    in arduino to ARDUINO PRO(atmega328 , 3.3V)…
    also i hve changed com port accordingly…
    then the serial monitor was showing useless data….

    I also modifies BOARD.txt(downloaded from
    https://pranjalchaubey.wordpress.com/2011/04/14/razor-imu/ ) file in
    arduino folder so the board submenu in arduino ide shows sparkfun 9dof
    razor imu atmega328
    have also openned all the .pde programs downloaded from
    http://code.google.com/p/sf9domahrs/ in different tabs of arduino

    and when i complided the output (so that i can receive imu data in
    serial monitor) code it was showing the error “analog_reference is not
    declared in this scope”…..
    and
    “sketch_jul25a.cpp: In function ‘void Read_adc_raw()’:
    ADC:12: error: ‘analog_buffer’ was not declared in this scope
    ADC:12: error: ‘sensors’ was not declared in this scope
    ADC:13: error: ‘analog_count’ was not declared in this scope
    ADC:14: error: ‘analog_buffer’ was not declared in this scope
    ADC:14: error: ‘sensors’ was not declared in this scope
    ADC:16: error: ‘AN’ was not declared in this scope
    ADC:22: error: ‘analog_buffer’ was not declared in this scope
    ADC:23: error: ‘analog_count’ was not declared in this scope
    ADC:24: error: ‘analog_buffer’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘float read_adc(int)’:
    ADC:31: error: ‘SENSOR_SIGN’ was not declared in this scope
    ADC:32: error: ‘AN_OFFSET’ was not declared in this scope
    ADC:32: error: ‘AN’ was not declared in this scope
    ADC:39: error: ‘AN’ was not declared in this scope
    ADC:39: error: ‘AN_OFFSET’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Analog_Reference(uint8_t)’:
    ADC:58: error: ‘analog_reference’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void __vector_21()’:
    ADC:69: error: ‘analog_count’ was not declared in this scope
    ADC:69: error: ‘MuxSel’ was not declared in this scope
    ADC:70: error: ‘analog_buffer’ was not declared in this scope
    ADC:73: error: ‘MuxSel’ was not declared in this scope
    ADC:75: error: ‘analog_reference’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Compass_Heading()’:
    Compass:14: error: ‘roll’ was not declared in this scope
    Compass:16: error: ‘pitch’ was not declared in this scope
    Compass:19: error: ‘magnetom_x’ was not declared in this scope
    Compass:19: error: ‘magnetom_y’ was not declared in this scope
    Compass:19: error: ‘magnetom_z’ was not declared in this scope
    Compass:23: error: ‘MAG_Heading’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Normalize()’:
    DCM:6: error: ‘FALSE’ was not declared in this scope
    DCM:8: error: ‘DCM_Matrix’ was not declared in this scope
    DCM:25: error: ‘TRUE’ was not declared in this scope
    DCM:38: error: ‘TRUE’ was not declared in this scope
    DCM:51: error: ‘TRUE’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Drift_correction()’:
    DCM:88: error: ‘Accel_Vector’ was not declared in this scope
    DCM:89: error: ‘GRAVITY’ was not declared in this scope
    DCM:94: error: ‘errorRollPitch’ was not declared in this scope
    DCM:94: error: ‘DCM_Matrix’ was not declared in this scope
    DCM:95: error: ‘Omega_P’ was not declared in this scope
    DCM:95: error: ‘Kp_ROLLPITCH’ was not declared in this scope
    DCM:97: error: ‘Ki_ROLLPITCH’ was not declared in this scope
    DCM:98: error: ‘Omega_I’ was not declared in this scope
    DCM:103: error: ‘MAG_Heading’ was not declared in this scope
    DCM:106: error: ‘errorYaw’ was not declared in this scope
    DCM:108: error: ‘Kp_YAW’ was not declared in this scope
    DCM:111: error: ‘Ki_YAW’ was not declared in this scope
    DCM:116: error: ‘ToRad’ was not declared in this scope
    DCM:119: error: ‘ToDeg’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Matrix_update()’:
    DCM:135: error: ‘Gyro_Vector’ was not declared in this scope
    DCM:135: error: ‘Gyro_Scaled_X’ was not declared in this scope
    DCM:136: error: ‘Gyro_Scaled_Y’ was not declared in this scope
    DCM:137: error: ‘Gyro_Scaled_Z’ was not declared in this scope
    DCM:139: error: ‘Accel_Vector’ was not declared in this scope
    DCM:139: error: ‘accel_x’ was not declared in this scope
    DCM:140: error: ‘accel_y’ was not declared in this scope
    DCM:141: error: ‘accel_z’ was not declared in this scope
    DCM:147: error: ‘Omega’ was not declared in this scope
    DCM:147: error: ‘Omega_I’ was not declared in this scope
    DCM:148: error: ‘Omega_Vector’ was not declared in this scope
    DCM:148: error: ‘Omega_P’ was not declared in this scope
    DCM:163: error: ‘Update_Matrix’ was not declared in this scope
    DCM:164: error: ‘G_Dt’ was not declared in this scope
    DCM:174: error: ‘DCM_Matrix’ was not declared in this scope
    DCM:174: error: ‘Temporary_Matrix’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Euler_angles()’:
    DCM:192: error: ‘pitch’ was not declared in this scope
    DCM:192: error: ‘DCM_Matrix’ was not declared in this scope
    DCM:193: error: ‘roll’ was not declared in this scope
    DCM:194: error: ‘yaw’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void I2C_Init()’:
    I2C:11: error: ‘Wire’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Accel_Init()’:
    I2C:16: error: ‘Wire’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Read_Accel()’:
    I2C:39: error: ‘Wire’ was not declared in this scope
    I2C:55: error: ‘AN’ was not declared in this scope
    I2C:58: error: ‘accel_x’ was not declared in this scope
    I2C:58: error: ‘SENSOR_SIGN’ was not declared in this scope
    I2C:58: error: ‘AN_OFFSET’ was not declared in this scope
    I2C:59: error: ‘accel_y’ was not declared in this scope
    I2C:60: error: ‘accel_z’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Compass_Init()’:
    I2C:68: error: ‘Wire’ was not declared in this scope
    sketch_jul25a.cpp: In function ‘void Read_Compass()’:
    I2C:79: error: ‘Wire’ was not declared in this scope
    I2C:95: error: ‘magnetom_x’ was not declared in this scope
    I2C:95: error: ‘SENSOR_SIGN’ was not declared in this scope
    I2C:96: error: ‘magnetom_y’ was not declared in this scope
    I2C:97: error: ‘magnetom_z’ was not declared in this scope”

    please help me in this and guide me how to upload the code that i
    downloaded from your site…????

  29. Johnny PaxIovanni says:

    Hi guy,
    thanks for the article, i have a problem with my Razor 9DOF, i have the Drift problem to SE but i have the FTDI Basic 3.3v by Sparkfun, so i think it’s not an alimentation problem, any suggest or i forgot something? 😀

    Thank you Gio.

  30. Michael says:

    Hi Pranjal,

    I am connecting the Razor board(new version, https://www.sparkfun.com/products/10736) to a Xbee Module. But the xbee on my computer is not receiving anything. The connection to the Xbee is correct(i checked it using a bounce back code written on an arduino).
    Sparkfun says that the razor comes with a inbuilt code. So just by connecting to a serial port of 3.3 v logic level, we will be able to see the values.
    A 5V supply is given to the board and the 3.3 v from the board is connected to the Xbee module.

    Sometimes I get some unknown characters in the serial terminal, otherwise nothing,
    The xbee is working at 57600bps.

    What can be the error? Can you please help me?

    • Make sure the XBee bit rate matches the bit rate of the IMU. I think its 34800 (or whatever is the closest standard value). Better you check sparkfun’s source code for this.

  31. Hi Pranjal,

    Thanks for all the useful hints for the Razor 9DoF. Could you please point me to a step-by-step idiots guide as to how to replace the Arduino bootloader. Cheers

    • Replace the Arduino bootloader with what?
      Removing *everything* including the bootloader is simple though. Just buy any standard USB AVR programmer, from the software for the programmer simply select erase all option (I am speaking generally of *any* chip programming software here). This should remove the bootloader and everything else.

  32. aditya gupta says:

    hi pranjal
    i wanted to ask that if i dont have a breakout and connect imu directly through arduino-uno how can i do it?

    waiting for your reply

    • Connect the IMU to Arduino UNO’s UART pins. IMU’s Tx should connect to UNO’s Rx and IMU’s Rx should go to UNO’s Tx. Make sure your UART bit rate is set correctly otherwise you’ll receive all gibberish or nothing at all.

  33. Áliah Bagarib says:

    Hi, i’m trying to use python to see if my IMU is working properly. But i can’t get it to work. ( https://pbs.twimg.com/media/BdW2xs7CUAAzNfV.png:large ) What could be the problem?

  34. snehal says:

    can you please tell if its possible to calculate linear velocity using IMU

  35. Sugimiyanto says:

    Hi Pranjal,
    i like your article.

    I have error compiling like this :

    “In file included from SF9DOF_AHRS.ino:70:
    C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:215:26: error: pins_arduino.h: No such file or directory”

    when i change to another board, ex: Arduino Duemilanove or diecimila
    there are no error.

    how to solve it?
    thank you so much.

    Best regards,
    Sugi.

  36. mazx says:

    Hello Pranjal! I connected FTDI pins with Razor imu(10736) but while I upload the AHRS code i get this error “avrdude.exe: stk500_getsync(): not in sync: resp=0x00” . I even edited the board.txt as u mentioned above. What am i doing wrong plz help 😦 .

  37. Pramod says:

    Hi!
    Thanks for the tutorial, can I used TIVA123G board for the same purpose? if Yes then what are the changes I have to made in the code as well as in python.
    Pls. guide me!
    Regards,
    Pramod

  38. Kai says:

    Hi Pranjal,
    I currently have the 9DOF IMU from Sparkfun (SEN 10736) https://www.sparkfun.com/products/10736 connected with the 3.3V FTDI Basic Breakout also from Sparkfun https://www.sparkfun.com/products/9873 and connecting to my Laptop through USB. I have been successful in uploading the Razor AHRS Firmware and am able to get yaw, pitch, and roll angles. With this code, you can only output either the calibrated sensor data or yaw, pitch, and roll but not simultaneously. Do you know of a way to output both the calibrated sensor data and the yaw, pitch, and roll in Ascii Text? Under the output, I added an additional print in the loop to include ypr but when I check on the serial monitor, the YPR are not updating. Do you know if there is something in the code or do you think number of number-to-text conversions is too much for the 8MHz Atmega328P? Do you think binary output would be faster and then switching the binary outputs into ascii text on the computer would be better? Thank you for all your help! I am working on an undergraduate student project and we are stuck on this issue.

    void output_sensors_text(char raw_or_calibrated)
    {
    Serial.print(“#A-“); Serial.print(raw_or_calibrated); Serial.print(‘=’);
    Serial.print(accel[0]); Serial.print(“,”);
    Serial.print(accel[1]); Serial.print(“,”);
    Serial.print(accel[2]);

    Serial.print(“#M-“); Serial.print(raw_or_calibrated); Serial.print(‘=’);
    Serial.print(magnetom[0]); Serial.print(“,”);
    Serial.print(magnetom[1]); Serial.print(“,”);
    Serial.print(magnetom[2]);

    Serial.print(“#G-“); Serial.print(raw_or_calibrated); Serial.print(‘=’);
    Serial.print(gyro[0]); Serial.print(“,”);
    Serial.print(gyro[1]); Serial.print(“,”);
    Serial.print(gyro[2]);

    Serial.print(“#YPR=”);
    Serial.print(TO_DEG(yaw)); Serial.print(“,”);
    Serial.print(TO_DEG(pitch)); Serial.print(“,”);
    Serial.print(TO_DEG(roll)); Serial.println();

    • No, number to text conversions won’t overwhelm the processor. Don’t worry about that, we have printed out huge additional data along with the standard IMU output and never had a problem with the processor speed. Printing out binary values is DEFINITELY faster than this method, but it seems like your problem lies somewhere else.

      Whatever information you want to print out, use the function “void printdata(void)” in the original source code. Its in the “Output.pde” file. It worked for us, it should work for you.

Leave a reply to Pranjal Chaubey Cancel reply