Go Down

Topic: Reading data from/Interfacing with 9DOF Razor IMU (Read 8935 times) previous topic - next topic

leomusic568

Hello everyone,

I'm having some trouble interfacing my 9DOF Razor IMU (SEN-10736; http://www.sparkfun.com/products/10736) with my Arduino Uno.  For those who don't know, this IMU (Inertial Measurement Unit) has an 8 MHz Atmega 328 chip which is programmed via the Arduino IDE (selecting the Arduino Pro/Mini (3.3V, 8MHz) option as the board).

The AHRS (Attitude and Heading Reference System) code I'm using for the IMU is from https://dev.qu.tu-berlin.de/projects/sf-razor-9dof-ahrs, which uses a DCM (Direction Cosine Matrix) filter to obtain pitch, yaw, and roll angles and outputs them via serial.  This works wonderfully, especially with the included Processing sketch (a 3D animation showing the board's orientation in real time...quite cool!).  I can also see the output by opening a serial monitor to the specified baud rate when the IMU is connected directly to my computer through an FTDI Basic Breakout board (http://www.sparkfun.com/products/9873).

However, I've run into some problems getting the IMU to talk to my Uno.  I've got them hooked up as follows:

IMU TX >> Uno Rx
IMU RX >> Uno TX
IMU 3.3V >> Uno 3.3V
IMU GND >> Uno GND

Uno >> PC via USB

I've made multiple attempts in trying to access the IMU data from the Uno (as in, we're programming the Uno now) using the various Serial commands (for instance, variable = read() to obtain the data then store it to some variable, and write(variable) or print(variable) to see it in the serial monitor).  Since the IMU outputs the yaw, pitch, roll data as an array, I've also tried defining the output as an array, with similar results.  I get some numbers, but not getting anything that looks right.   

I'm aware that the USB uses the RX/TX of the Uno.  I plug in the IMU to the RX/TX ports after the sketch has uploaded.  Data shows up in the serial monitor after the IMU is connected, but it's nothing readable and I've double checked that everything's at the same baud rate, I'm accessing the right COM port and that everything is properly connected.  Same problem occurs when I use SoftwareSerial (on pins 2 and 3) as well.

There's loads of info of reading sensor data through analog or digital inputs, but I can't find much on serial.

I'm trying to get data from the IMU to control motors, servos, etc.

Sorry for the long post.  In light of that:

TL;DR  Tried everything I can think of, can't get the new(est) Sparkfun 9DOF IMU to talk to my Arduino Uno via serial.

I'm sure there's something stupid I'm forgetting.  Any help is much appreciated!

Thanks!

-Leo.

MarkT

And how are you level-shifting the serial signals?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

leomusic568

Hello, thank you for your reply.

I don't think I'm doing any level-shifting; they're just straight wired via the RX and TX pins. 

I only have a rather superficial knowledge about logic-levels in general.  With this in mind, I can't seem to find at what level the IMU serial operates at.  How would I know if I need to shift levels and how would I go about doing so?  I see there are logic-level converters for sale on SparkFun for example.

Just for the sake of asking, would this have anything to do with the CTS and DTR pins on the IMU?  They're currently not hooked up to anything.  Again, I've only got a top-level idea of their functions (they're part of a serial port but are usually accompanied by DSR and RTS) so let's pretend I don't know anything: what exactly do these do? 

Thanks again!

-Leo.

MarkT

You can't just connect 5V and 3V3 logic signals together and expect things to work - in fact you are more likely to damage something or put on of the chips into latch-up.  At the very least try series resistors (5k to 10k range say) between the two boards - should prevent damage.  And you have commoned the GND lines ?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

leomusic568

With all due respect, I'm not sure where you obtained those numbers from.  The IMU board operates at 3.3V.  Correct me if I'm wrong, but I don't think that's what defines the logic level.

In fact, I think the problem lies more in the code.  After several attempts, I finally got good, readable data.  However, it's still not what I need and I'm not sure where to go.  Here's the output code from the IMU (just the very last output section; we're running at 9600 Baud):

Code: [Select]

      Serial.println(TO_DEG(yaw)); //Serial.println();     
      Serial.println(TO_DEG(pitch)); //Serial.println();
      Serial.println(TO_DEG(roll)); //Serial.println();


I can read it in it's entirety using the following code on the Uno:

Code: [Select]

String sensorData;
char c;
void setup() {
  Serial.begin(9600);
  Serial.println("9DOF Test");
}
 
void loop() {
  while (Serial.available()) { 
    if (Serial.available() >0) {
c = Serial.read();
//sensorData += c; //adds c to the sensorData string
       Serial.print(c); //see whatever came in on Serial.read()
    }
  }
  if (sensorData.length() >0) {
   Serial.println(sensorData);  //output the string
    readString=""; //resets reString for the next iteration of the loop
  }
}


Since the IMU outputs using Serial.print, I can get a direct read out of the data from the IMU on the Uno.   However, when I print out c from Serial.read() it gives me back the ENTIRE data stream instead of just one byte of it.  Essentially, c and sensorData have the exact same data.

I want to be able to access each Euler angle (pitch, yaw, and, roll) independently as a number (int) so that I may use them to control actuators (servos, motors, etc.).  I was thinking that if I could get each piece of data as an independent string, I could convert each one to a character array using .toCharArray()  and then to an integer using atoi.

Any thoughts?

leomusic568

No one has any experience with this unit?   It strikes me odd that it'd be this difficult to get useful data off of this unit...otherwise what use does it serve? 

How about parsing serial streams?  Anyone know how to do that in the Arduino code? 

In C++ you can use the strtok function but I'm unsure how tokens work in Arduino code.

Thanks,

-Leo.

gabilodno1612

Hi all

I am using the Razor IMU with an Arduino 1

thie is the code:

Code: [Select]

#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3);
String buff;
String prueba;
int posicioncoma;
int posicioncomaaux;
int posasterisco;
String valor9;
String valor8;
String valor7;
String valor6;
String valor5;
String valor4;
String valor3;
String valor2;
String valor1;
String valor0;

 
void setup() {
  Serial.begin(57600);
  softSerial.begin(57600);
}
 
void loop() {
  if(softSerial.available()){
    while(softSerial.available()){
      char in = (char)softSerial.read();
      buff += in;
      if(buff.indexOf('#')!=-1){

        Serial.println(buff);
       
        posicioncoma = buff.lastIndexOf(',');
        posasterisco = buff.lastIndexOf('#');
        valor9 = buff.substring(posicioncoma+1,posasterisco);
        //Serial.println(valor9);
       
        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor8 = buff.substring(posicioncomaaux+1,posicioncoma);
        //Serial.println(valor8);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor7 = buff.substring(posicioncoma+1,posicioncomaaux);
        //Serial.println(valor7);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor6 = buff.substring(posicioncomaaux+1,posicioncoma);
        //Serial.println(valor6);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor5 = buff.substring(posicioncoma+1,posicioncomaaux);
        //Serial.println(valor5);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor4 = buff.substring(posicioncomaaux+1,posicioncoma);
        //Serial.println(valor4);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor3 = buff.substring(posicioncoma+1,posicioncomaaux);
        //Serial.println(valor3);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor2 = buff.substring(posicioncomaaux+1,posicioncoma);
        //Serial.println(valor2);

        posicioncoma = buff.lastIndexOf(',',posicioncomaaux-1);
        valor1 = buff.substring(posicioncoma+1,posicioncomaaux);
        //Serial.println(valor1);

        posicioncomaaux = buff.lastIndexOf(',',posicioncoma-1);
        valor0 = buff.substring(posicioncomaaux+1,posicioncoma);
        //Serial.println(valor0);
       
        buff="";
       
      }
    }
  }

}


The problem is that i obtain a String like that. I can also separate these numbers of the String and convert them to In but the main problem is that i have no idea about what these numbers mean.

&34,56,23,56,12,-34,-67,34,-76#

I tried to rotate the imu in one axis and some number changes, but these number that changes movimg one axis also change moving another.

Could someone help me to know how to obtain the pitch, yaw and roll angles instead of these?

Thanks in advance






Henradrie

I'm parsing using strtok for my IMU's.

  char delimiters[] = ",#";
  char* valPosition;

  valPosition = strtok(input, delimiters);

  for (int i = 0; i < outSize; i++) {
    out = atoi(valPosition);   //changing atoi to atof converts from strings to floats
    valPosition = strtok(NULL, delimiters);
  }

atoi converts the incoming number stream into 16 bit integers

gabilodno1612

#8
May 04, 2016, 11:24 am Last Edit: May 04, 2016, 04:59 pm by gabilodno1612
but my problem is not parsing, my problem is that i have no idea if some of these numbers are the real Yaw, pitch and roll angles, because i have try to find out if any of them are these angles by moviming the imu but my conclusion is that NO.

I have seen that in some tutorials not using arduino UNO, the obain a String as YPR = 23,23,34 and i am obtaining just these 9 numbers that i think that they are the 9 degrees of freedom of the imu without processing

Sam_n

All,

If I may get back to the OP's issue...

Leo,

Did you ever get a resolution to your issue??? I don't see any directly related solutions listed in this thread that have to do with your original posting. I have the exact same issue and am not sure what to do about it.
Thanks,
Sam

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy