Pages: 1 [2]   Go Down
Author Topic: Using values from 9DOF Razor in Arduino Mega  (Read 4317 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25730
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 08, 2011, 08:24:41 am by AWOL » Logged

"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.

Torino, Italy
Offline Offline
Sr. Member
****
Karma: 2
Posts: 309
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25730
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What does the \r and \n do what do they represent
Carriage return and newline codes.

0x0d and 0x0a
Logged

"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.

Daytona Beach
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Thanks,
petteym

Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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?

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Salerno Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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




Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25730
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

(Serial comms are slooooow)
Logged

"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.

Salerno Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25730
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

See reply #24.
And replies #12 and #14
« Last Edit: June 27, 2011, 09:05:09 am by AWOL » Logged

"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.

Pages: 1 [2]   Go Up
Jump to: