Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 24, 2009, 07:40:15 pm
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
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 11, 2009, 11:47:20 pm
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]
3  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 10, 2009, 11:39:33 am
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
4  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 09, 2009, 12:33:37 am
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.
5  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 08, 2009, 04:46:45 pm
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
6  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 08, 2009, 03:42:07 pm
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
7  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 08, 2009, 12:40:02 am
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() {}
8  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 08, 2009, 12:39:09 am
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
9  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 07, 2009, 03:10:15 pm
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
10  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 06, 2009, 01:32:14 pm
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] <<smiley-cool + (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?
11  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 04, 2009, 05:57:38 pm
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
12  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 02, 2009, 06:23:55 pm
well thank you very much. I am trying to perform my work in polled mode--one time display of the values. When I ran your code, I receive a number of about 12,000.  One concern was whether your coding involved the 32 bit output of the Inertia Link in IEEE 754 format-sign (+/-) is first byte, exponent follows in the next byte, then rest are base value. This is how I understand it. I was concerned that the shifting is overriding this format?
13  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: May 02, 2009, 12:24:03 pm
Well I have made huge progress and have 1 more step. I have all incoming bytes organized by the accelerations and angular rates. The final code I am using is the following. It simply organizes the incoming bytes to their corresponding desired outputs. I want to get the 4 inputs organized into 1. My understanding is the followin: You have 4 bytes (8 bit words) for Acceleration X for example, correct. If the first 2 bits are say (10000001) and (00011000), then add 8 zeros to the first word resulting in (1000000100000000) and add to second bit resulting in 1000000100011000 ( a 16 bit word). This value precedes the decimal point. You repeat the procedure for the last two bits resulting in a value after the decimal point. The combination of Result1.Result2  produces the final 32 bit word resulting in the single result of Acceleration X when read in DEC.
 
If my procedure is correct, can you use the shift command to tack on the following zeros?
 
float incomingByte = 0;     // for incoming serial data
int i;
char a;
char b;
char c;
char d;
char e;
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) {
                       for (i=0; i<1; i++) {// read the incoming byte:
                       incomingByte = (float)Serial.read()/10.0;
                       Serial.print("\n\nHeader: ");
                       Serial.println(incomingByte*10);
                       }    
                       Serial.print("\n");
                        
                       for (i=1; i<5; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Acceleration in X: ");
                       Serial.println(incomingByte*10);
                       }  
                       Serial.print("\n");
                      
                       for (i=5; i<9; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Acceleration in Y: ");
                       Serial.println(incomingByte*10);
                       }  
                       Serial.print("\n");
                      
                       for (i=9; i<13; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Acceleration in Z: ");
                       Serial.println(incomingByte*10);
                       }  
                       Serial.print("\n");
                      
                       for (i=13; i<17; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Angular Rate in X: ");
                       Serial.println(incomingByte*10);
                       }  
                       Serial.print("\n");
                      
                       for (i=17; i<21; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Angular Rate in Y: ");
                       Serial.println(incomingByte*10);
                       }
                       Serial.print("\n");
                      
                       for (i=21; i<25; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Angular Rate in Z: ");
                       Serial.println(incomingByte*10);
                       }
                       Serial.print("\n");
                      
                       for (i=25; i<29; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Check Sum: ");
                       Serial.println(incomingByte*10);
                       }
                       Serial.print("\n");
                      
                       for (i=29; i<31; i++) {
                       incomingByte = (float)Serial.read()/2560.0;
                       Serial.print("Timer: ");
                       Serial.println(incomingByte*10);
                       }
             }  
}          
void loop() {}

Thank you. This is my last step
14  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: April 30, 2009, 11:57:55 am
The continuation mode was set to assure that reasonable data was being received. Thanks to your coding, all works well and numbers look reasonable. I just need to convert a ASCII DEC printout to normal decimals (1.00 g) for example. I was trying to find this last night. I will convert to polled mode--for this is what we will use for our application. For proper organization, dont i need a BYTE output other than a y with a double dot on top?

thanks
15  Forum 2005-2010 (read only) / Troubleshooting / Re: Serial Communication on: April 30, 2009, 11:03:33 am
yes it does command in certain number of ordered bytes. the link is the following:

http://www.microstrain.com/pdf/dcp/Inertia-Link-3DM-GX2-data-communications-protocol.pdf

My concern is that if I put the final print value as BYTE, then I get a y with a double dots over it.

Thanks
Pages: [1] 2