Hi! I've just set up 3 XBee series 2.5 modules using X-CTU. Everything went pretty fine following the instructions in this document (http://www.embedded.arch.ethz.ch/xbee-setup.pdf - very good & clear!).
I am using sparkfun's xbee explorer for my coordinator module, and 2 duemilanoves with xbee shields for the routers. One router has a potentiometer (knob) attached, the other an ADXL322 accelerometer. When in wireless mode, I am getting odd readings from the accelerometer but not from the pot. If I have the arduino with the accelerometer connected via usb, whether or not I also have the xbee shield installed, I get correct readings.
So - wireless communication from 2 routers to the coordinator works, but for some reason the data flow from the accelerometer is affected by the xbee communication. Does anyone know why, and how to solve this?! I am hoping it is something that can be solved either in the firmware setup of the xbee, or in my arduino code....
Any suggestions most welcome, thanks!
Here is a sample of the readings:
.A 113 126 125
.A 113 126 124
.A 113 127 124
.A 113 126 124
.A 113 126 124
.A 113 126 124
.A 114 127 125
.A 113 126 125
.A 113 126 124
// up to hear they are correct, then it seems to reset to 0 and work its way up again...??
.A 113A 0 0 2
.A 5 6 7
.A 12 15 14
.A 21 25 23
.A 31 36 33
.A 42 48 43
.A 54 61 55
.A 65 73 67
.A 75 85 79
.A 87 98 91
.A 98 110 101
.A 104 117 109
.A 108 121 A 0 0 3
.A 5 6 8
.A 12 14 14
.A 21 24 23
.A 31 36 33
.A 42 49 44
.A 53 61 55
.A 64 73 67
.A 76 85 80
.A 87 99 92
Here's the arduino code:
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a #define rather than a normal variable lets
// use this value to determine the size of the readings array.
#define NUMREADINGS 10
int readingsX[NUMREADINGS]; // the readings from the X-axis analog input
int totalX = 0; // the running total of X
int averageX = 0; // the average for X
int readingsY[NUMREADINGS]; // the readings from the Y-axis analog input
int totalY = 0; // the running total of Y
int averageY = 0; // the average for Y
int readingsZ[NUMREADINGS]; // the readings from the Z-axis analog input
int totalZ = 0; // the running total of Z
int averageZ = 0; // the average for Z
int index = 0; // the index of the current reading
int inputXPin = 3; //X-axis input
int inputYPin = 2; //y-axis input
int inputZPin = 1; //Z-axis input
int groundPin = 18; //analog input pin 4
int powerPin = 19; //analog input pin 5
void setup()
{
Serial.begin(57600); // initialize serial communication with computer
pinMode(groundPin, OUTPUT);
pinMode(powerPin, OUTPUT);
digitalWrite(groundPin, LOW);
digitalWrite(powerPin, HIGH);
for (int i = 0; i < NUMREADINGS; i++)
readingsX = 0; // initialize all the readings to 0
-
for (int e = 0; e < NUMREADINGS; e++)*
-
readingsY[e] = 0;*
-
for (int f = 0; f < NUMREADINGS; f++)*
-
readingsZ[f] = 0;*
}
void loop()
{ -
totalX -= readingsX[index]; // subtract the last reading*
-
totalY -= readingsY[index];*
-
totalZ -= readingsZ[index];*
-
readingsX[index] = analogRead(inputXPin); // read from the sensor*
-
readingsY[index] = analogRead(inputYPin);*
-
readingsZ[index] = analogRead(inputZPin);*
-
totalX += readingsX[index]; // add the reading to the total*
-
totalY += readingsY[index];*
-
totalZ += readingsZ[index];*
-
index = (index + 1); // advance to the next index*
-
if (index >= NUMREADINGS) // if we're at the end of the array...*
-
index = 0; // ...wrap around to the beginning*
-
averageX = totalX / NUMREADINGS; // calculate the average*
-
averageY = totalY / NUMREADINGS;*
-
averageZ = totalZ / NUMREADINGS;*
-
averageX = map(averageX, 0, 1023, 0, 255);*
-
averageY = map(averageY, 0, 1023, 0, 255);*
-
averageZ = map(averageZ, 0, 1023, 0, 255);*
-
Serial.print("A"); // to identify as coming from accelerometer*
-
Serial.print(" ");*
-
Serial.print(averageX); // send it to the computer*
-
Serial.print(" ");*
-
Serial.print(averageY);*
-
Serial.print(" ");*
-
Serial.print(averageZ);*
-
Serial.println();*
}