Serial Communication

You are right, I'm looking for a way to convert the 4 bytes into a float format. The cast (float)incomingvalue won't work. Try the code following. I've tested putting some bytes into the array, and it gives the same value as a float.

Edit: I've looked at page http://babbage.cs.qc.edu/IEEE-754/32bit.html I don't know which order your device will send the bytes, you may have to tinker, by reversing the order the 4 bytes are read into the array. I've posted the sketch I was using to try and convert bytes to and from floats. It gives the same value as the calculated values from the page, e.g. 100 is hex 42c80000, which is loaded as the values 0 0 200 66.

union t_long_fl { // this assign the byte array on the same memory as the float
byte b_arr[4];
float f_var;
} ;

t_long_fl t1;
int j;
 
int int_part_of_float;
int frac_part_of_float;

// for each block of data, as you coded it
  j=0;
  for (i=9; i<13; i++)
  {
    t1.b_arr[j] = Serial.read(); // add byte into array
    j += 1;
  }

  int_part_of_float = (int)t1.f_var;
  frac_part_of_float = 100 * (t1.f_var - (float)int_part_of_float);

  Serial.print("Acceleration in Z: ");
  Serial.print(int_part_of_float);
  Serial.print('.');
  Serial.println(frac_part_of_float);
  Serial.print("\n");
long readnumber()
{
  char c;
  long res= 0;
  int count = 0;
  boolean pos = true;
  while (true) {
   if (Serial.available())
   {
     c = Serial.read();
     count ++;
     if (c >= '0' && c <= '9')
     {
       res *= 10;
       res += (c - '0');
     }
     else if (c = '-' && count == 1)
     {
        pos = false;
     }
     else
     else
     {
       break;
     }
   }
  }
  return pos ? res : -res;
}

union t_long_fl {
byte  b_arr[4];
float f_var;
} t1 ;

void print_ba()
{
  for (int i = 0; i < 4; i++)
  {
     Serial.print(" ");
     Serial.print((int)t1.b_arr[i]);
  }
}

void print_float(float f)
{
  long i_i = (long)f;
  int i_f = 100 * (f - (float)i_i);
  Serial.print(i_i);
  Serial.print('.');
  Serial.print(i_f);
}


void setup()
{
  Serial.begin(9600);
  Serial.print("enter [Fii ff ] or [Imm mm mm mm ] or [P]\nii ff integer,fractional part for float\nmm values for each byte (dec)\n");
}

void loop()
{
  long int_part;
  int int_frac;
  if (Serial.available())
  {
    char c = Serial.read();
    Serial.print(c);
    switch (c)
    {
      case 'I':
        for (int i = 0; i < 4 ; i++)
        {
          t1.b_arr[i] = readnumber();
        }
        print_ba();
        Serial.println();
        break;
      case 'F':
        int_part = readnumber();
        Serial.print("int part:");
        Serial.print(int_part);
        int_frac = readnumber();
        Serial.print(" frac part:");
        Serial.println(int_frac);
        t1.f_var = int_part + float(int_frac)/100.0;
        break;
      case 'P':
        print_float(t1.f_var);
        print_ba();
        Serial.println();
        break;
      default:
        Serial.println(" bad char ");
        break;
    } // end switch
  }
} // end loop

Thank you very much. I reviewed the code and I am sorry to say that I do not understand it completely. I compiled it alone to help understand the process but am having difficulty when implementing into my code as to where to place it and the expected output. From the Microstrain (Inertia Link manufacturer), by the coding involved in the following link (http://www.microstrain.com/inertia-link.aspx) under documentation: 3DM-GX2® Orientation SDK: SDK master: Windows: Code: C: Library: Source: utils: there is a function called FloatFromBytes. This function does the IEEE754 conversion. To compare values, they recommended I use the website you gave with all 4 of the outputs given by my last posted code into a single line HEX input into the website. Can the Arduino Software handle such a function such as FloatFromBytes, or is it necessary to use the coding you produced? (I am sure this took much time to create--i was surprised but I need some comments or background to its process since this is a bit above my C knowledge.

Thank you

The inertial device sends out a number of bytes. 4 of the bytes (48=32bits) are a representation of the floating value, which is also 48=32bits.

The arduino library does include float functions, which are also stored as 32bits, which is 4 consecutive bytes in memory. If you declare a float variable, the compiler reserves 4 bytes space in memory for it. It does not have a floatfrombytes as such.

What the code does is overlay a 4 byte array, at the same point in memory, as a float value. Both take the same amount of room. This is the union{...}. The union allows access to the same 4 bytes as either an array, or as a float.

So when the 4 bytes are received in, they are put in the correct position to be read as a float.

The rest of the code, is to print out the float. First it converts the float to a long, a long can only store the integer part, so a float of say 100.25 would convert to an long of 100. The second conversion is to get the fractional part, which is done by taking 100.25 - 100 = 0.25 (this is done as a float operation). Then multiply 0.25 by 100 to get the value 25.

The idea is that you declare these once:
union t_long_fl { // this assign the byte array on the same memory as the float
byte b_arr[4];
float f_var;
} ;

t_long_fl t1;
int j;

int int_part_of_float;
int frac_part_of_float;

at the top of your interpretation block.
The rest of the first code posted was to replace the blocks where you were reading in the successive bytes. Obviously, you only need those code blocks where you are expecting a float.

Why not try to start with printing out the hex bytes in lines of 4, as the data, then put those values into the conversion website? At least you will see if you are getting the sequencing right.

(To clarify, the first code example is for you to try; the second sketch was to verify the conversion was working. It takes 3 commands:
enter the 4 bytes, enter the float, print out the bytes and the float.)

I've looked at floatfrombytes.

You can code that on an arduino.
It takes a pointer to 4 bytes stored adjacently. By pretending they are an array, it then moves each byte in turn onto the correct position on a float variable - much like my code did. Then it returns the pattern of bits as a float.

Its doing the same as my code with the union.

The testbyteorder is to sort out which order the bytes are sent. It must depend on the architecture of the processor; in the absence of that, just stuff the bytes in either 0-0 1-1 2-2 3-3 or 0-3 1-2 2-1 3-0

i cannot get the following to compile and am concerned as to the unrecognition of "const" since it is not in brown text. Is this the reason for error? or is there another reason.

#include "i3dmgx2_Errors.h"
short convert2short(unsigned char *);
unsigned short convert2ushort(unsigned char *);
unsigned long convert2ulong(unsigned char );
long convert2long(unsigned char
);
int calcChecksum(unsigned char *, int);

float FloatFromBytes(const unsigned char*);
char * explainError(int);
int TestByteOrder();

byte IMUByte =0;
float f;
float incomingByte = 0; // for incoming serial data
int i;

char a;
char b;
char c;
char d;
char e;

char serOutString[11];
// array to hold string of arduino read values of digital pin

//int val=0; // temporary value for inputs & outputs
//int val4=0; //temp
//char val2=2;
//char val3=0;
//char val1=0;
//int p=0; // temporary value for pin

//read a string from the serial and store it in an array
//you must supply the array variable
void IMU_String (char *strArray) {
int i = 0;
if(Serial.available()) {
//Serial.print("reading Serial String: "); //optional: for confirmation
while (Serial.available()){
strArray = Serial.read();

  • i++;*
  • // Serial.print(strArray[(i-1)]); //optional: for confirmation*
  • }*
  • // Serial.println(); //optional: for confirmation*
  • } *
    }
    //Print the whole string at once - will be performed only if thers is data inside it
    //you must supply the array variable
    void printSerialString(char *strArray) {
  • int i=0;*
    _ if (strArray != 0) { _
    _ while(strArray != 0) {
    //Serial.print( strArray );
    strArray = 0; // optional: flush the content
    i++;
    }

    * }
    }
    void setup()
    {
    Serial.begin(115200);
    //e = 250; // DEC for 0xFA stop continuous mode*

    //Serial.print(e);
    //a = 196; // DEC for 0xC4 start continuous
    //Serial.print(a);
    //b = 193; // DEC for 0xC1 dont change
    //Serial.print(b);

    //c = 41; // DEC for 0x29 dont change
    //Serial.print(c);
    d = 194; // DEC for 0xC4 change for desired output see Microstrain Protocal
    Serial.print(d);
    delay(1000);
    * if (Serial.available() >= 0) {*_

float incomingBytes(const unsigned char* pBytes);
{
* float f = 0;*

_ ((BYTE*)(&f))[0] = pBytes[3];
((BYTE*)(&f))[1] = pBytes[2];
((BYTE*)(&f))[2] = pBytes[1];
((BYTE*)(&f))[3] = pBytes[0];_

}
/*----------------------------------------------------------------------
* convert2long
* Convert four adjacent bytes to a signed long.
*
* parameters: buffer : pointer to a 4 byte buffer.
* returns: the converted value as a signed long.
--------------------------------------------------------------------/
long convert2long(unsigned char* plbyte) {
* long l = 0;*
* {*
* l = (plbyte[0] <<24) + (plbyte[1] <<16) + (plbyte[2] <<8) + (plbyte[3] & 0xFF); *
* }*

* return l;*
}
* }*
* } *
*} *
void loop() {}
Thanks. This is our last step thankfully. Then after this is complete, then we need to organize the data by a record so we have AccelX = the float value, same for Y,Z? Do you need a record like they do, or is there another way?

Blackdragon, there are quite a few things wrong. Can you get a local coder to help you. I'm still not sure what you are trying to do...

  1. Structure needs correcting. You cannot nest a function inside another function, hence you must move convert2long and incomingBytes out of setup().

  2. Unless you have put the header file i3dmgx2_Errors.h into your arduino ide in the correct place, it will error and not compile. Try taking it out and see what else errors.

3 All the "prototypes", which define functions, short covert2short(unsigned char *) are probably not needed (in this environement, the arduino ide tries to generate them for you). Try removing them.

4 IMU_String should add a 0 to the end of the string to terminate it. See how printSerialString is looking for a 0 to stop processing.

5 const is OK, its a valid keyword. Its probably not the problem. Remove it if you want.

6 brackets at the end do not look balanced.

7 You don't need printSerialString,
you get the same result with Serial.print(strArray). The String library will print a string or a (null terminated) array of characters.

8 If you define a function, nothing happens unless you later call it. For example convert2long would be a function definition if it were outside setup. To call it - to actually make the computer do that processing - you need a statement like this:

l = convert2long( char_array);

8 Can you plan out the overall code and show that? Then code from that skeleton.

9 Have a close look at some examples of sketches.

I will try to have a look at the coding tomorrow, but its bedtime now.

We tried to simplify down your coding into the following. We now get data at least so that provides confidence that the setup on this end is correct.

long readnumber()
{
char c;
char d;
long res= 0;
int count = 0;
boolean pos = true;
while (true) {
if (Serial.available())
{
c = Serial.read();
count ++;
if (c >= '0' && c <= '9')
{
res *= 10;
res += (c - '0');
}
else if (c = '-' && count == 1)
{
pos = false;
}
else

{
break;
}
}
}
return pos ? res : -res;
}

union t_long_fl {
byte b_arr[4];
float f_var;
} t1 ;

void print_ba()
{
for (int i = 0; i < 4; i++)
{
Serial.print(" ");
Serial.print((int)t1.b_arr*);*

  • }*
    }
    void print_float(float f)
    {

  • long i_i = (long)f;*
    int i_f = 100 * (f - (float)i_i);

  • Serial.print(i_i);*

  • Serial.print('.');*

  • Serial.print(i_f);*
    }
    char d;
    void setup()
    {

  • Serial.begin(115200);*

  • d=194;*

  • Serial.print(d);*

  • Serial.print("enter [Fii ff ] or [Imm mm mm mm ] or [P]\nii ff integer,fractional part for float\nmm values for each byte (dec)\n");*
    }
    void loop()
    {

  • long int_part;*

  • int int_frac;*

  • if (Serial.available())*

  • {*

  • char c = Serial.read();*

  • Serial.print(c);*

  • for (int i = 0; i < 4 ; i++)*

  • {*
    t1.b_arr = readnumber();
    * }*
    * print_ba();
    _
    Serial.println();*_

* int_part = readnumber();
_
Serial.print("int part:");_
Serial.print(int_part);
int_frac = readnumber();
_
Serial.print(" frac part:");_
Serial.println(int_frac);
t1.f_var = float(int_frac);*

* t1.f_var = float(int_part);*

* print_ba();
_
Serial.println();*_

* }*
} // end loop
Providing output of:
Âenter [Fii ff ] or [Imm mm mm mm ] or [P]
ii ff integer,fractional part for float
mm values for each byte (dec)
 0 0 0 0
int part:0 frac part:0
0 0 0 0
º 0 0 0 0
int part:0 frac part:0
0 0 0 0
þ 0 0 0 0
int part:0 frac part:0
0 0 0 0
( 0 0 0 0
int part:0 frac part:0
0 0 0 0
; 0 0 0 0

Sadly, all your data seems to be zeros.

Try this, I've tried to put some comments in.

Can you say how the device is connected - as far as I can see you must have it connected to the serial output line, so everything that is
a Serial.print("some string") is being sent to your device as well as the host computer.

// declare a union to convert bytes to a float
union t_long_fl {
  byte  b_arr[4];
  float f_var;
}  t1 ;

// prints the 4 bytes of the union byte array, for debugging to see what is coming back
void print_ba()
{
  for (int i = 0; i < 4; i++)
  {
    Serial.print(" ");
    Serial.print((int)t1.b_arr[i]);
  }
  Serial.println();
}

// prints a float with 2 decimal places
void print_float(float f)
{
  long i_i = (long)f;
  int i_f = 100 * (f - (float)i_i);
  Serial.print(i_i);
  Serial.print('.');
  Serial.print(i_f);
}



char d;
void setup()
{
  Serial.begin(115200);
  //d=194;
  d = 0xC2;  // this is the command value for Acceleration & Angular Rate (0xC2)
  Serial.print(d);
}

void loop()
{

  int i;
  boolean frame_all_done = false;

  if (Serial.available())
  {
    char c = Serial.read();

    if (c == 0xC2) {
      // have got the first character of the frame we expect, wait for rest of frame to come it
      // if the frame character is not an 0xC2 will not process in this block
      while (Serial.available() < 30) {
          // loop waits until there are 30 bytes read from the interface  
          // overall response frame is 31 long, but we already got the 1st one
      } 

      Serial.println(" Received all frame bytes");
      //Bytes 2-5   AccelX
      Serial.print("Accel X:");
      for (i = 0; i < 4 ; i++)
      {
        t1.b_arr[i] = Serial.read();
      }
      print_float(t1.f_var);
      print_ba();
      //Bytes 6-9   AccelY
      Serial.print("Accel Y:");
      for (i = 0; i < 4 ; i++)
      {
        t1.b_arr[i] = Serial.read();
      }
      print_float(t1.f_var);
      print_ba();
      //Bytes 10-13 AccelZ
      Serial.print("Accel Z:");
      for (i = 0; i < 4 ; i++)
      {
        t1.b_arr[i] = Serial.read();
      }
      print_float(t1.f_var);
      print_ba();
      //Bytes 14-17 AngRateX
      Serial.print("AR X:");
      for (i = 0; i < 4 ; i++)
      {
        t1.b_arr[i] = Serial.read();
      }
      print_float(t1.f_var);
      print_ba();
      //Bytes 18-21 AngRateY
      Serial.print("AR Y:");
      for (i = 0; i < 4 ; i++)
      {
        t1.b_arr[i] = Serial.read();
      }
      print_float(t1.f_var);
      print_ba();
      //Bytes 22-25 AngRateZ
      Serial.print("AR Z:");
      for (i = 0; i < 4 ; i++)
      {
        t1.b_arr[i] = Serial.read();
      }
      print_float(t1.f_var);
      print_ba();
      //Bytes 26-29 Timer
      for (i = 0; i < 4 ; i++)
      {
        Serial.read(); // just discarding
      }
      //Bytes 30-31 Checksum
      for (i = 0; i < 2 ; i++)
      {
        Serial.read(); // just discarding
      }
      
      frame_all_done = true; // set up flag to ask for another frame


    } // end if frame start detected
    else
    {
          Serial.print("First byte rx is not expected frame start:"); 
          Serial.print((byte)c,HEX);     
    }
    

  }  // end if serial data available
  
    // frame is now finished, the loop is ready for another frame, so try asking for another frame
    if (frame_all_done == true)
    {
      char d;
      d = 0xC2;
      delay(2000); // wait two seconds
      Serial.print(d);
      frame_all_done = false;
    }
   
  
  
} // end loop

I am getting a better feel for your coding but am confused as to the lack of the mathematics for the IEEE 754 format. The website: http://www.h-schmidt.net/FloatApplet/IEEE754.html calculates the decimal equivalent from the 32 bit long binary input with the following formula: sign * 2exponent * mantissa with the following explanation

The sign is stored in bit 32. The exponent can be computed from bits 24-31 by subtracting 127. The mantissa (also known as significand or fraction) is stored in bits 1-23. An invisible leading bit (i.e. it is not actually stored) with value 1.0 is placed in front, then bit 23 has a value of 1/2, bit 22 has value 1/4 etc. As a result, the mantissa has a value between 1.0 and 2. If the exponent reaches -127 (binary 00000000), the leading 1 is no longer used to enable gradual underflow.
Rounding errors: Not every decimal number can be expressed exactly as a floating point number. This can be seen when entering "0.1" and examining its binary representation which is either slightly smaller or larger, depending on the last bit.

By using the following code and taking the acceleration Z values (putting zeros infront numbers to make 8 bits due to screen's truncation) in order, I get acceleration in Z to be -1.02g, a reasonable value. I need assistance in making the 32 bit word from the binary output of the unit and read off the sign, exponent, and mantissa to do the formula to produce such values.

Thank you soo much

The code is:

float incomingByte; // for incoming serial data
int i;

char d;

void setup()
{
Serial.begin(115200);

d = 194; // DEC for 0xC2 Command byte to initiate communication: change for desired output see Microstrain Protocal
Serial.print(d);

delay(1000);

if (Serial.available() >= 0) {
for (i=0; i<1; i++) {// read the incoming byte:
incomingByte = (float)Serial.read();

Serial.print("\n\nHeader: ");
Serial.println(incomingByte);
}
Serial.print("\n");

for (i=1; i<5; i++) {
incomingByte = (float)Serial.read();

Serial.print("Acceleration in X: ");
Serial.println(incomingByte, BIN);
}
Serial.print("\n");

for (i=5; i<9; i++) {
incomingByte = (float)Serial.read();

Serial.print("Acceleration in Y: ");
Serial.println(incomingByte, BIN);
}
Serial.print("\n");

for (i=9; i<13; i++) {
incomingByte = (float)Serial.read();

Serial.print("Acceleration in Z: ");
Serial.println(incomingByte, BIN);
}
Serial.print("\n");

}
}

void loop() {}

Is there any reason you want to use the mathematics for the IEEE 754 format. It is not a normal way of representing numbers although it does have advantages.

Also.

Please Please Please Please Please Please Please

When posting code click on the hash icon on the top bar of the reply box and paste the code between the square brackets that appear. In that way the page looks a lot nicer and we don't have to do acres of scrolling to get to the new bit.

Thank you.

The reason is for the output of an understanding of one value from the incoming bytes. I understand that functions in a float structure can be used but I could not get a code to run perfoming this conversion to produce a value of -1g for example.

I will do that. I was not sure how you posted code-i checked off the box near the bottom of the posting but I never got a popup box to do so. I understand now

Thank you

Blackdragon,
You do not need to get bogged down in the maths of the floating point number. My code example shows how to change the 4 bytes received to a float. Its very similar to the example from the website, which you also found. The technique is to put the 4 received bytes at the same addresses as the float variable, then ask the computer to interpret the float value. The arduino already 'knows' that if it is given a float, how to manipulate it. You don't have to know.

look at this code, from your example:

for (i=1; i<5; i++) {
incomingByte = (float)Serial.read();

i = 1.
Serial.read() returns a byte - 8 bits, say 00101001. That example is hex2A, or decimal 42 (32 + 10). If you cast that to a float - the (float) operation - you get a floating number with a value of 42.0 It is represented as 4 bytes, and using the www.h-schmidt.net/FloatApplet/IEEE754.html website, the values are probably 42280000.
That number, 42.0 is assigned to incomingByte overwriting any previous value of incomingByte.
i = 2.
Serial.read() returns a byte - 8 bits, say 00000001. If you cast that to a float - the (float) operation - you get a floating number with a value of 1.0 It is represented as 4 bytes, and you can work out what they are but it doesn't matter. That number, 1.0 is assigned to incomingByte - IT DOES NOT ADD TO IT.
i=3
much the same
i=4
much the same
i=5
exits loop

It will end up with the (floating) value of the last of the 4 bytes read.

You need to write the 4 bytes into a byte array and then use those 4 bytes as a float, as per my code. A cast - which is what the (float) operation is called - will not work. The sketch I wrote a few nights back tries to do that.

Please also answer the question of how the device is connected, because I am interested in how the single serial input pin is used for the device but the serial out goes both to the computer AND the device. That is not a way of connecting hardware that I have met before.

The reason I tried to write the last sketch with a loop, is that you can shake the device up and down, and see if the values are changing. With a one shot, its going to be difficult to alter the acceleration at the exact time you want the reading. At least for testing, try using a loop to read the values repeatedly. Then convert to your one-shot code.

I was just confused since I received 4 zeros in the output since I was expecting one final value. Would you say the last code posted with your code incorporated was done correctly? I think I am getting the float part but was just not sure with what I was receiving. Is there a way to extend the decimals to more than 2 places to see if the data is 0.005 for example?

The setup is through the usage of pins 0-1 on the Duemilanove. Using the USB cable to upload the coding to the board, then once the code is running, the command byte is transmitted on pin 1 and received on pin 0. To my understanding of the board, the transmission pin works in correspondance to the USB cable to print the information on the computer screen to validate the data.

Thank you

Well I am finished now. I was successfully able to get the unit to convert the byte to a float value which I can confirm and makes sense.

Thank you all so very much for progress and promptness the whole way through. Our project isn't fully complete but this portion is ready for integration in my perspective.

Thank you again. Especially Shelleycat for all your coding (I dont have any idea how long those took to write up) but it all really helped me progress and learn what I needed to do along the way.

One last concern is since we have an Arduino Duemilanove which contains a USB port, can we print the serial data (currently written to a computer screen via usb) to a a USB thumb drive through a USB type A to type B cable. Are there certain write functions that are needed or must you use a ftdi viniculum chip?

thanks

I'm glad it worked.

As far as I know the arduino cannot drive a USB as a master, so it will not be able to write to a thumb drive. On the forums there are numerous posts about writing to a SD card, and there is a library for that. I've not tried it.

What I have done with an arduino as a data logger is use hyperterminal on the computer to receive the data from the arduino, and capture that to a file.

As for printing the float with 3 decimal places, this might work:

// prints a float with 3 decimal places
void print_float(float f)
{
  long intpart = (long) f; // get the integer part of number
  long frac 1000.0 * (f - float(intpart)); 
  Serial.print(intpart);
  Serial.print('.');
  Serial.print(frac);
}

he arduino cannot drive a USB as a master

Correct.

so it will not be able to write to a thumb drive

It can't directly, but it can with the help of a chip known as the Vinculum VNC1L. There are modules (VDIP1, VDIP2, VMUSIC, etc) that have been interfaced to the arduino with varying degrees of success.

It's not trivial or trouble free, but it is doable. Search the forum and maybe the playground for discussions.

-j

For memory we are planning to use the Spark Fun Logomatic V2 SD logger. This will work correct?

The other issue of concern is that I integrated my code with my coding for servos and they seem to glitch even with all the print statements removed but the command byte one (d). I tried to switch the transmit and receive off of serial (0,1) and use another digital set on the Duemilanove (6,7) but I have had no luck. Any suggestions as to where I am going wrong? It compiles but I dont receive relevant data. Thanks

[#include <NewSoftSerial.h>

int RXpin = 6;
int TXpin = 7;

NewSoftSerial IMU = NewSoftSerial(RXpin,TXpin);

typedef unsigned char byte;

byte incomingByte = 0; // for incoming serial data
byte incomingByte1 = 0; // for incoming serial data
byte incomingByte2 = 0; // for incoming serial data
byte incomingByte3 = 0; // for incoming serial data
byte incomingByte4 = 0; // for incoming serial data
int EulerX = 0;
int EulerY = 0;
int EulerZ = 0;

int i;
int t = 0;

int servo1 = 4;
int servo2 = 2;
int pulseWidth1;
int pulseWidth2;

void servoPulse1 (int servo1, int EulerX) {
pulseWidth1 = ((EulerX * 10.9) + 1500); // Converts angle to microseconds
digitalWrite(servo1, HIGH); // Set servo high (turns it on)
delayMicroseconds(pulseWidth1); // Wait a very very small amount
digitalWrite(servo1, LOW); // Set servo low (turns it off)
//delay(20); // Typical Refresh cycle of servo (20 ms)
//Serial.println (pulseWidth1, DEC);

}

void servoPulse2 (int servo2, int EulerY) {
pulseWidth2 = ((EulerY * 10.9) + 1500); // Converts angle to microseconds
digitalWrite(servo2, HIGH); // Set servo high (turns it on)
delayMicroseconds(pulseWidth2); // Wait a very very small amount
digitalWrite(servo2, LOW); // Set servo low (turns it off)
//delay(20); // Typical Refresh cycle of servo (20 ms)
//Serial.println (pulseWidth2, DEC);
}

float Convert754(byte bits25_32, byte bits17_24, byte bits9_16, byte bits1_8);
char d;

float Convert754(byte bits25_32, byte bits17_24, byte bits9_16, byte bits1_8)
{
unsigned char bytes[4];
float floatval;

bytes[3] = bits25_32;
bytes[2] = bits17_24;
bytes[1] = bits9_16;
bytes[0] = bits1_8;

floatval = (float)bytes;

return floatval;
}

void setup()
{
pinMode(servo1, OUTPUT);
pinMode(servo2, OUTPUT);
pinMode(6, INPUT);
pinMode(7, OUTPUT);
// set the data rate for the SoftwareSerial port
}

void loop() {
Serial.begin(115200);
IMU.begin(115200);
delay (10);

d = 206; // DEC for 0xCE (Euler Angle) change for desired output see Microstrain Protocal
IMU.print(d);
Serial.println (d, DEC);

delay(810);

if (IMU.available() >= 0){
for (i=0; i<1; i++) {// read the incoming byte:
incomingByte = IMU.read();

Serial.print("\n\nHeader: ");
Serial.println(incomingByte, DEC);
}
Serial.print("\n");

for (i=1; i<5; i++) {
if (i==1) { incomingByte1 = IMU.read(); }
if (i==2) { incomingByte2 = IMU.read(); }
if (i==3) { incomingByte3 = IMU.read(); }
if (i==4) { incomingByte4 = IMU.read(); }
}
Serial.print("Euler Angle About X: ");
EulerX = (float)( Convert754(incomingByte1, incomingByte2, incomingByte3, incomingByte4)*180/3.14);
Serial.print(EulerX, DEC);
Serial.print("\n");

for (i=5; i<9; i++) {
if (i==5) { incomingByte1 = IMU.read(); }
if (i==6) { incomingByte2 = IMU.read(); }
if (i==7) { incomingByte3 = IMU.read(); }
if (i==8) { incomingByte4 = IMU.read(); }
}
Serial.print("Euler Angle About Y: ");
EulerY = (float)( Convert754(incomingByte1, incomingByte2, incomingByte3, incomingByte4)*180/3.14);
Serial.print(EulerY, DEC);
Serial.print("\n");

for (i=9; i<13; i++) {
if (i==9) { incomingByte1 = IMU.read(); }
if (i==10) { incomingByte2 = IMU.read(); }
if (i==11) { incomingByte3 = IMU.read(); }
if (i==12) { incomingByte4 = IMU.read(); }
}
Serial.print("Euler Angle About Z: ");
EulerZ = (float)( Convert754(incomingByte1, incomingByte2, incomingByte3, incomingByte4)*180/3.14);
Serial.print(EulerZ, DEC);
Serial.print("\n");
IMU.flush();
}
delay (10);

servoPulse1(servo1, EulerX);

servoPulse2(servo2, EulerY);

}
][/code]

Well we got the Sparkfun Logomatic to connect and provide feedback to the board on the serial pins. But now the InertiaLink and Logomatic run off the same two pins. Is it possible to move the Logomatic to two other digital pins--such as a void loop with a digital output for the data to be sent to the Logomatic?

Thank you