Pages: [1]   Go Down
Author Topic: [Solved] Problem with float from 8-bit Arduino to Due  (Read 657 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I´m trying to receive 3 float from an 8-bit Arduino Mini, which I know that it manage 4 bytes float, in a 12 byte array.
But I´m having troubles to convert it to Due´s float because I do not understand at all, how many bytes have a float in the Due,
(I think the float in Due it´s like an double, 8 bytes). I hope someone could confirm me that the Due´s float are 8 byte in memory and
tell me how to convert a 4 bytes float to a 8 bytes float, I´m trying to do it with "union" with no results.

Thanks and regards.

Update: I found "Sizeof" function in the reference, I will test it on the Due and I will post the results.
« Last Edit: April 03, 2013, 12:45:29 pm by ruizo » Logged

Offline Offline
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally it works  smiley-lol

sizeof() told me that float are 4 bytes long and double are 8 bytes long on Due, I didn't understood well in the reference  smiley-roll-sweat

//  Test code to send binary data from 9 DOF Razor IMU to Arduino Due
//  Programa de Prueba para comprobar que el Arduino Due recibe correctamente
//  los datos del 9 DOF Razor IMU y los procesa.
//  Miguel Angel Ruiz 2013

const int TOTAL_BYTES = 12 ; // the total bytes in a message
char MESSAGE [12] = {'N','N','N','N','N','N','N','N','N','N','N','N',};  //  String for testing

union y_tag {
    byte by[4];
    float yval;
} y;

union p_tag {
    byte bp[4];
    float pval;
} p;

union r_tag {
    byte br[4];
    float rval;
} r;

float yaw;
float pitch;
float roll;

void setup(){
  Serial.println("Iniciando IMU");
  Serial1.print("#oe0"); // Disable Error Output
  Serial1.print("#ob");  // Binary Output Format Selected
  Serial1.print("#o0");  // Disable Continuos Data Streaming
  Serial.println("Arranque listo, comenzando");
  Serial.print("Mensaje de prueba -> ");
  for(int i=0; i<12; i++){
    Serial.print(MESSAGE[i], HEX);
  Serial1.print("#f");  // Request one frame of data

}// Fin de setup

void loop(){
  if ( Serial1.available() >= TOTAL_BYTES){
   [0] =;[1] =;[2] =;[3] =;
        yaw = y.yval;
        p.bp[0] =;
        p.bp[1] =;
        p.bp[2] =;
        p.bp[3] =;
        pitch = p.pval;
       [0] =;[1] =;[2] =;[3] =;
        roll = r.rval;
        Serial.print("Received IMU msg, Yaw = ");
        Serial.print(yaw, 2);
        Serial.print(", pitch = ");
        Serial.print(pitch, 2);
        Serial.print(", roll = ");
        Serial.println(roll, 2);
 /*    for(int i=0; i<12; i++){          //  Old code for testing
       MESSAGE[i] =;
    Serial1.print("#f");                 //  Request another frame of data
}// Fin del loop
« Last Edit: April 03, 2013, 12:49:11 pm by ruizo » Logged

Pages: [1]   Go Up
Jump to: