Im working on a project involving an ArduIMU v2 flat and an Arudino pro mini.
Here is the IMU I am using: http://code.google.com/p/ardu-imu/wiki/Hardware
Basically, I have the IMU and the mini board set up for serial communication. For simplicity, I have the IMU outputting only one degree (Pitch) of raw accelerometer data. The communication works fine- as in- I get the same outputs via the mini board's serial monitor as i get on the IMUs. The problem I am having is manipulating the data into something usable. Here is the typical output followed by my current code.
490
490
491
492
492
493
493
494
494
496
497
499
499
499
500
500
501
502
504
504
503
504
505
505
503
504
504
508
522
496
488
533
536
#include <NewSoftSerial.h>
#define rxPin 8 // pin 8 will recieve serial comm
#define txPin 7 // pin 7 will transmit serial comm
#define controlPin 13
#define forward HIGH
#define reverse LOW
NewSoftSerial serialIMU(rxPin, txPin); // initialize digital pins for serial comm
byte imudata ;
void setup()
{
pinMode(controlPin, OUTPUT);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
// initialize serial communications at 9600 bps:
Serial.begin(9600);
serialIMU.begin(4800); // initialize bps for soft serial at 4800 bps.
}
void loop()
{
if (serialIMU.available() > 0){
imudata = serialIMU.read();
}
if (imudata >= 500){
digitalWrite(controlPin, forward);
}
else {
digitalWrite(controlPin, reverse);
}
Serial.print(imudata);
delay(1);
}
The problem arises when i either try to change the "imudata" type to 'int' instead of 'byte' or when i try converting the read bytes to an int. The program is supposed to simply turn the pin 13 LED to ON when the value is above 500, and turn it OFF when it is below. When i run the program as is, the LED just stays on and does not respond to the IF statement in the code above.
Also, in the testing i have done: I noticed that when i look at the IMU serial monitor it is outputting whole 3 digit numbers... i assume int's. I know this because i simply put a delay and watched it print. When i do the same at the end of the mini board program (the one above) it will print one digit at a time... i assume this is because it is a byte type?
Any conversions I've been trying just yield garbage numbers that do not respond to the movement of the IMU.
To clarify, there are TWO programs running here... the one on the IMU and the one on the mini pro. Its the one on the mini pro that is shown above and that is giving me trouble.
I'm pretty new at this, so let me know if something else needs clarification.
Thanks for your help.