Saturday, November 6, 2010

Read 9DOF Razor IMU data via Seeeduino Mega board (Arduino Mega clone).

Figure 1
Read the data from the 9DOF Razor IMU board is very simple, but first I had to solder the pin-headers on the Seeeduino Mega board since the board is not sold with the pin-headers soldered, and then I connected the Seeeduino Mega board to the 9DOF Razor IMU board according to the diagram in Figure 1. Below is shown the sketch that allows you to read the data, as can be seen is short and simple.
/*

Read 9DOF Razor IMU data via Seeeduino Mega board (Arduino Mega clone).

1. Connect the jumper wires between the two boards
   according to the following table:

9DOF Razor IMU | Seeeduino Mega
---------------|--------------------
TX0............|RX1..(pin 18).......
RX1............|TX1..(pin 19).......
3.3V...........|3V3.................
GND............|GND.................
---------------|--------------------

2. Connect the USB Cable between the PC and the Seeeduino Mega board.
3. Select the "Board" item from the "Tools" top menu and check the radio
   button Arduino Mega (ATmega1280). 
4. Upload this Sketch to the Seeeduino Mega board
5. Open Serial Monitor and set the Baud rate to 57600.
6. Send the character '0' to view the 9DOF Razor IMU Menu.

9DOF IMU Test Firmware v15
==========================
[1]Accelerometer: ADXL345
[2]Magnetometer: HMC5843
[3]Gyroscope: LPR530 and LY530
[4]Raw
[5]Self Test

 */

void setup() {
  Serial.begin(57600);
  Serial1.begin(38400);  // Baud rate fixed....
  Serial1.print(4);      // Begin with Raw data
}

void loop() {
  if(Serial.available() > 0) {
    int incomingByte = Serial.read();
    /*
       DEC - BYTE
         0 - 48
         1 - 49
         2 - 50
         3 - 51
         4 - 52
         5 - 53
    */
    if(incomingByte >= 48 && incomingByte <= 53)
        Serial1.print(incomingByte, BYTE);
  }
  
  if(Serial1.available() > 0)
    Serial.print(Serial1.read(), BYTE);
}
After making the upload of the sketch, for the Seeeduino Mega Board, I opened the serial monitor and selected the baud rate to 57600 and can immediately observe the raw data to arrive (Figure 2).
Figure 2
To view the menu with more options, send the character "0". More options available can be seen in the sketch above. If you choose the Self Test (#5 in the Menu) and you always get a "MAG: BAD" message don't worry, probably your 9DOF Razor IMU board has no problem. Try upload the sketch, but where the first menu item to send is #5 (Self Test) instead of #4 (Raw) and you will see that the result will be different.

5 comments:

  1. hey hdias im using ur progress as a guide for mine and have run into a problem. i am trying to use a specktrum radio controller but when i add

    uGear = pulseIn(pin3, HIGH);
    uYaw = pulseIn(pin4, HIGH);
    uPitch = pulseIn(pin5, HIGH);
    uRoll = pulseIn(pin6, HIGH);
    uThrtl = pulseIn(pin7, HIGH);

    to read the pulse coming from the receiver or any pulse it seems to break timing and doesnt allow me to read the 9dof board off serial 1. have u run into this? or know a place with a solution

    ReplyDelete
  2. ok forget my posts before im wondering if u know why my seeduino board resets when there is any delay in the read code. ive concluded thats why it resets when i use pulseIn(). i used ur working clean code and i stuck a delay(100); after serial.print's and it breaks the program. thank you for ur work on your project.

    ReplyDelete
  3. hdias i fixed it just in case u decide to add some RC control u need to Serial1.flush() before u read pulses. works great now!!!

    ReplyDelete
  4. If you need some more information about how to integrate the RC control maybe you can find it at this site: http://www.instructables.com/id/Quadrotor/step23/Code/

    ReplyDelete
  5. Hi, may i know what are the codes u uploaded onto the razor imu board?

    ReplyDelete