Monday, September 20, 2010

Read data from the 9 DOF Razor IMU via Arduino board.

After several problems with the original 9DOF Razor IMU board, I have finally got a board with no functional problems or bugs. The challenge we had to work around then was how to read the data from the board? So I decided do some research and found in this blog that there was a simple way to read data using the Arduino Duemilanove connected to the 9DOF Razor IMU board without requiring any additional cable as shown in Figure 1.
Figure 1
The sketch to read the data from the 9DOF Razor IMU via Arduino Duemilanove is very short and simple as shown below.
/*

Read data from the 9DOF Razor IMU board via arduino duemilanove board.

1. Upload this Sketch to the Arduino board
2. Disconnect the USB cable from the PC. 
3. Connect the jumper wires between the two boards
   according to the following table:

9DOF Razor IMU | Arduino Duemilanove
---------------|--------------------
TX0............|TX1.................
RX1............|RX0.................
3.3V...........|3V3.................
GND............|GND.................
---------------|--------------------

4. Connect again the USB Cable to the PC.
5. Open Serial Monitor.
6. Send the character '1'.
7. Send the character '0' to view the 9DOF Razor IMU Menu.

*/

void setup() {
  Serial.begin(38400);
}

void loop() {
  if(Serial.available()) {
    Serial.print(Serial.read(), BYTE);
  }
}
After doing the upload of the sketch, and open the Serial Monitor, send a character between '1' and '5' followed by a '0' then a menu is shown (Figure 2).

Figure 2
In the menu there are have five options: [1] Accelerometer (ADXL345), [2] Magnetometer (HMC5843), [3] Gyroscope (LPR530 and LY530), [4] Raw and [5] Self Test. For example, if you choose the option "1" and if you move the 9DOF Razor IMU board in any direction you will see on the Serial monitor the variation of the values for the aceleration
The following video shows the 9DOF Razor IMU board connected to the Arduino board working hard (Sorry for the bad video quality!). Notice menu of the 9DOF Razor IMU board on the monitor of the laptop.
But unfortunately this sketch does not fit what I want. With the Arduino Duemilanove only can be used a single Serial connection at a time. However, that problem can be solved by using software libraries. One of the libraries is the SoftwareSerial library which allows the serial communication on any of the Duemilanove's digital pins. But, because it's not supported by hardware, the library has a few limitations. The other library is the NewSoftSerial library that emulates an additional serial port, allowing you to communicate with another Serial device. However, there is another Arduino board where you can use more than one connection, which is the Arduino Mega. With the Arduino Mega is possible connect more three Serial devices. The last solution is more robust but, requires a further investment in a new board. So I'll have to take a look in the Arduino board clones.

11 comments:

  1. so i tried to do exactly what you did but for it to stream data to my serial monitor, i have to hold down the reset button on the duemilanove.... any idea what could be going on?

    ReplyDelete
  2. This is very strange. In my case the data flow without having to make any reset. Check if the baud rate is correct.
    The objective of using the Arduino Duemilanove is to make a bridge between the board and the 9DOF Razor IMU board to read the data via USB. It's like using the TDI Basic Breakout - 3.3V board instead of Arduino Duemilanove. The inputs from IDE via Serial connection is send directly to the 9DOF Razor IMU board and the outputs are send back directly to the computer.

    ReplyDelete
  3. Eli, i make a connection from CTS of 9DOF to RESET Arduino and it's working fine! =)

    ReplyDelete
    Replies
    1. hey, can i make it work without reseting the arduino?

      Delete
  4. Followed these instructions exactly...and I either get nonsense like this from the serial monitor (4� àœÀĸÀ¼À䘛àœàä 4ƒ ó{³” ij „3Ä3t„“ ä ô´0ƒƒ ó{³” ä“) or nothing at all. Tried holding reset button, connecting CTS to RESET, still nothing. No response when I type 1 or 0 into the serial monitor.

    Could this have to do with me having a MAC?

    ReplyDelete
  5. Hello John, a possible cause for the garbage that you see is due to incorrect selection of the data rate in bits per second (baud) for serial data transmission. For communicating with the computer try one of the rates available in Serial Monitor until you can see the correct values.

    ReplyDelete
  6. I'm getting this error
    Can you please help me out...
    avrdude: stk500_getsync(): not in sync: resp=0x30
    Thanx in advane

    ReplyDelete
  7. The problem i'm facing is that i'm not able to put these values which i got on serial monitor into variables so that i can further use them...somebody help!!!

    ReplyDelete
    Replies
    1. hello mr hemant
      i am facing the same problem

      Delete
  8. Hi All,
    I have my GY-951 working now, purchased cheaply from ebay linking to sparkfun razor for info. Seems to have a different firmware loaded not the example but outputing real values for direct use.

    The diagram above is wrong, the RX0 of the arduino (i'm using uno) needs to be connected to the TX of the 9DOF. The RX of the 9DOF is not necessary to test.

    The Atmel328 of mine like the sparkfun is programmed with a baud rate of 57600, so i changed that in the code:
    void setup() {
    Serial.begin(57600);
    }

    void loop() {
    if(Serial.available()) {
    Serial.print(Serial.read(), BYTE);
    }
    }

    The error: avrdude: stk500_getsync(): arises because during programming of the Arduino chip it is communicating with the 328 on the 9DOF too as the rx lines are connected. Program the receiving arduino with the 9DOF disconnected from the RX.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete