Go Down

Topic: Using values from 9DOF Razor in Arduino Mega (Read 4857 times) previous topic - next topic

lau06275

The input is always going to be in the form shown at the start of the post, but I understand what you mean.
The input is coming from an accelerometer assembly that has its own IMU and is processing this data and sending it in that form.

However I understand what you are saying in that say for my purpose the angle goes above 100 degrees, there is now another character to deal with, similarly with negative values, as there can be a negative sign in front of the angle.

Do you know of any other way to get around this, sorry if it may seem simplistic as I say I am a novice to the system


AWOL

#16
Mar 08, 2011, 02:19 pm Last Edit: Mar 08, 2011, 02:24 pm by AWOL Reason: 1
You can either call Serial.available before you read every character, and check that the return value is non-zero,
or you can call it once to see if there are enough characters present to process the whole message.
Or you can call "read" repeatedly and dump any -1 values that it returns.
http://arduino.cc/en/Serial/Read
http://arduino.cc/en/Serial/Available

To be fair, he did say:
Quote
Not tested but should give you an idea.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Fabio Varesano

Code: [Select]
if (Serial.available() > 0) {

Yeah, this can fail miserably.. it should check for the whole data line length.. remember to insert also the \r and \n which you can't see but they are transmitted.

lau06275

I have made a change to the code on the Razor IMU that will now add 360 to each of the values of the angles.
This means that it will never be less or more than three digits and will never be negative so don't have to worry about them. That's what I am going forward with at the moment.

What does the \r and \n do what do they represent

AWOL

Quote
What does the \r and \n do what do they represent

Carriage return and newline codes.

0x0d and 0x0a
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

petteym

could you post the code you used to simply print out the data from the razor, I've tried several and for the life of me I can't get it to work, all I'd like at the moment is to get the data from the razor onto the serial monitor, Thanks
Thanks,
petteym

lau06275

This is what we used, although we were messing around with different serial ports on the arduino mega so just use the serial that you are using.
Code: [Select]
#include <NewSoftSerial.h>

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);

}
void loop(){
  if(Serial.available()>0) {
    int incomingByte = Serial.read();
    if(incomingByte >=48 && incomingByte <=53)
      Serial1.print(incomingByte, BYTE);
  }
  if (Serial1.available()>0)
    Serial.print(Serial1.read(), BYTE);
}


Some of it isnt necessary like the incoming BYTE stuff that we added and were messing around with.

If it is angles from the 9DOF you are reading, we have put software available on the Sparkfun website, not sure if you have that already.

What hardware are you using?


ivereninov

I also have Razor and Mega. This is my code to send data for a tricopter project.

1.functions to send and receive integers
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
union u_tag {
    byte b[2];
    int f_val;
  };
void SendInt(int f)
{
   u_tag u;
   u.f_val = f;
   Serial.print(u.b[0], BYTE);
   Serial.print(u.b[1], BYTE);     
   
}
int ReceiveInt()
{
   u_tag u;
   u.b[0] = Serial1.read();
   u.b[1] = Serial1.read();
   return u.f_val;
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
for floats use

union u_tag {
    byte b[4];
    float f_val;
  };

void SendFloat(float f)
{
      u_tag u;
      u.f_val = f;
      Serial.print(u.b[0], BYTE);
      Serial.print(u.b[1], BYTE);     
      Serial.print(u.b[2], BYTE);     
      Serial.print(u.b[3], BYTE);     

float ReceiveFloat()
{
      u_tag u;
      u.b[0]=Serial.read();
      u.b[1]=Serial.read();
      u.b[2]=Serial.read();
      u.b[3]=Serial.read();
return u.f_val;
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
After sending data from Razor use this kind of code to recieve .

  if(Serial1.available()>=9)
   {
       while (Serial1.read()!='\n'); \\ after sending integers from razor send a '\n' it would be a marker.When we see it,lets receive our ints.
       r=ReceiveInt();
       p=ReceiveInt();
       y=ReceiveInt();
   }



Sorry for bad english, ask if something is not understandable

m_canero

Hi, I have 9 Degrees of Freedom - Razor IMU connected to Arduino Mega2560 by Serial port.
I've got this problem.
I can't understand the format and the order of the data that I receve from Razor.
I've written this code:
Code: [Select]
if (Serial3.available() > 0) {
                               a=Serial3.read(); b=Serial3.read(); c=Serial3.read(); d=Serial3.read(); e=Serial3.read();  f=Serial3.read();  }

but it seems to work only when I press the reset button and reads only the value of 'a'.
Can somebody tell me where to find any clear istructions because I haven't found anything on sparkfun (where I bought it) and it's the first time that I ever worked with this device.   

Thank you for your help. Bye Mario





AWOL

How many characters are available, and how many are you reading?

(Serial comms are slooooow)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

m_canero

I try to write also in this way :
a=Serial3.read();
b=Serial3.read();
c=Serial3.read();
d=Serial3.read();
e=Serial3.read(); 
f=Serial3.read();

But I've the same result, only 'a' is read, the other values are -1.

AWOL

#26
Jun 27, 2011, 04:03 pm Last Edit: Jun 27, 2011, 04:05 pm by AWOL Reason: 1
See reply #24.
And replies #12 and #14
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up