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 IMU
- Download the latest AHRS code from here.
- Download and install the latest Arduino IDE(arduino 0018) from here.
- 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.
- 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=0×05
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!).
- 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).
- 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.
- Click on Tools → Boards → Sparkfun 9DOF Razor IMU with Atmega328p
- Click on Tools → Serial Port → Select the serial port on which Razor IMU has been connected.
- To upload the code on the board, click on File → Upload to I/O Board.
- 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…..
- Download and Install Python 2.6.5 and VPython from here.
- Download and Install PyWin from here.
- Download and Install PySerial from here.
- Download and Unzip (WHEW!!!) the graphic interface code from here.
- Open the IMU_Razor9DOF file in Notepad and set your COM port and the baud rate(57600 already) and save changes.
- 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!
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).
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.
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 ?
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?
Razor has been good enough for me so far……it comes with an open source AHRS code and thats a big plus. I don’t know if something like that is there for the Ultimate IMU. You’ll have to write your own AHRS code for that. Quite a task, if you want to get the things going quickly.
Well thanks for the answer, do have any report of any uav, if you have personally worked on it or someone else’s??
No
Sorry,Does anyone know how to modify AHRS code to calculate position and velocity in 3D translation or full 9DOF displacement? Thanks!
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)
You know how much it draws on the 3.3v line ? <50mA or more ?
Around 50mA…maybe even less.
tnx. I have to choose between two USBUART cables (data + power) one with ‘+3.3V / 50mA power output’ an another one with ’3.3V / 250mA power output’ ?. Should I go with the last one ?
BTW Are you satisfied with this product as an AHRS?
bye
Yeah….go with the last one. Better be safe than sorry!
Well, if you keep this thing away from strong magnetic fields and strong vibrations, it performs damn good for its price, otherwise not!
hi
how to subtract gravity component from accelerometer data. i’m trying to process accelerometer data to get position. i have doubt too in integrating the data.
Have a look at the open source code of this IMU.
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?
I fed 9V to Sparkfun’s USB Explorer Board for ZigBee. It has an on-board 3.3V regulator. I routed this 3.3V to the 9DoF board and it works!
When I upload the program, I keep getting the error:
avrdude: stk500_getsync(): not in sync: resp=0x0d
avrdude: stk500_disable(): protocol error, expect=0×14, 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?
Interesting, I never faced such problem with Arduino.
Check if have connected DTR pin also. This is sync error, make sure that the baud rate selected is correct.
Got same errors, I connected DTR pin, everything is fine ! Thx
BTW it works also with the “Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328″
Yeah….true!
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.
I had long discussions with the Sparkfun technical team, but could not arrive at a fix. I still power it from an external 3.3V.
This is the 9DoF board I have :-
http://www.sparkfun.com/products/9623
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.
Pingback: RAZOR IMU: Как прошить | MyLinks
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.
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.
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=0×00″
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…
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
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.
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.
Oh…thanks a lot Emory, that was really very humbling!
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.
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.
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.
Great! Thank you so much, it is displaying the data now.
Hi,
I copy the configuration in the boards.txt file but Arduino respond:
I have a problem
AVRDUD :can’t find programmer id
Valid programmers are:….
now I used the arduino pro mini (8khz, 328and 3.3v) its telling me
avrdude: stk500_getsync(): not in sync :resp=0×00
You usually get this error when you sent the wrong programmer id. If you follow the steps given in this article, it should get working.
Btw, are you using razor IMU?
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
It takes less than 30secs or so. There must be some issue with your tool chain.
tool chain in the sense u r meaning what i didn’t get u
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
i downloaded code from ur website . it is having more than one file which file i shd upload
I suggest you download the code directly using a USB-serial adapter. That should work good.
what does it mean protocol error ,expect= 0*14,resp = 0*18
thanks ya as u said it is finely uploading in USB.actually i have some doubt in ur code
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.
I had actually done that, but turns out that my FTDI board had issues. Replacement board worked fine. Thanks though
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?
Have a look at Thinnkware, Sunrom and Rhydolabz as well.
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..
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.