Hi
Hope I posted in the right place. Can't seem to find another example to guide me through the project below but if there is already a tutorial of sorts out there please point me in the direction.
My issue is making sense of the data I am receiving.
Basically I have a remote sensor which consists of an accelerometer (adxl335) and a thermometer (tmp36) and a xbee series 2 endpoint all plugged into an arduino uno.
On the other end I have a coordinator series 2 xbee on a usb explorer board hooked to a laptop.
Code on the arduino...
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;
int minVal = 265;
int maxVal = 402;
double x;
double y;
double z;
int tempSensor = 3;
void setup(){
// analogReference(EXTERNAL); //aref for adxl if used
Serial.begin(9600);
}
void loop(){
int xRead = analogRead(xPin);
int yRead = analogRead(yPin);
int zRead = analogRead(zPin);
int xAng = map(xRead, minVal, maxVal, -90, 90);
int yAng = map(yRead, minVal, maxVal, -90, 90);
int zAng = map(zRead, minVal, maxVal, -90, 90);
x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);
Serial.print("x: ");
Serial.print(x);
Serial.print(" | y: ");
Serial.print(y);
Serial.print(" | z: ");
Serial.println(z);
// temperature readings
int reading = analogRead(tempSensor);
float voltage = reading * 5.0;
voltage /= 1024.0;
Serial.print(voltage);
Serial.println(" volts");
float temperatureC = (voltage - 0.5) * 100;
Serial.print(temperatureC);
Serial.println(" degrees C");
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF);
Serial.println(" degrees F");
// delay(1000);
}
Then I use Processing on the laptop to list it out for me...
import processing.serial.*;
Serial myPort;
void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[0],9600);
}
void draw() {
if (myPort.available() >27) {
int[] xbeeData = new int[28]; // new array
for (int i=0; i<28; i++) {
xbeeData[i] = myPort.read();
if (xbeeData[0] != 126) { // resets if xbee data is incomplete
break;
}
}
if (xbeeData[0] == 126) {
String xbeeAddr = xbeeData[4] + "," + xbeeData[5] + "," + xbeeData[6] + "," + xbeeData[7] + "," + xbeeData[8] + "," + xbeeData[9] + "," + xbeeData[10] + "," + xbeeData[11];
String xbeeAnalogData = "" + xbeeData[20];
println("Whole string = " + xbeeData[0] + "," + xbeeData[1] + "," + xbeeData[2] + "," + xbeeData[3] + "," + xbeeAddr + "," + xbeeData[12] + "," + xbeeData[13] + "," + xbeeData[14] + "," + xbeeData[15] + "," + xbeeData[16] + "," + xbeeData[17] + "," + xbeeData[18] + "," + xbeeData[19] + "," + xbeeData[20] + "," + xbeeData[21] + "," + xbeeData[22] + "," + xbeeData[23] + "," + xbeeData[24] + "," + xbeeData[25] + "," + xbeeData[26] + "," + xbeeData[27]);
}
}
}
Sample data I receive looks like this:
126,0,96,144,0,19,162,0,64,151,30,131,177,172,65,32,121,58,32,51,53,57,46,52,57,32,124,32
126,0,96,144,0,19,162,0,64,151,30,131,177,172,65,49,48,49,46,51,49,13,10,48,46,55,50,32
126,0,96,144,0,19,162,0,64,151,30,131,177,172,65,46,50,55,32,100,101,103,114,101,101,115,32,67
126,0,96,144,0,19,162,0,64,151,30,131,177,172,65,114,101,101,115,32,70,13,10,120,58,32,50,46
126,0,96,144,0,19,162,0,64,151,30,131,177,172,65,32,121,58,32,51,53,57,46,52,57,32,124,32
etc.
before when I was just using a tmp36 (without an accelerometer) it was easy to interpret the temperature readings. The number of datasets is all over the place along with everything else and stumbling around trying to figure out how to interpret this. Not sure if I should be sending the info differently or if my endpoint sleep wake time is bad or what.
Any help appreciated. Thanks'
Mike