Hello everyone,
I would like to read accelerometer data with the sampling rate of more than 50Hz and transmit readings to the host computer via XBee to XBee communication.
I’m using
- Arudino UNO
- ADXL 335 3-axis accelerometer (50Hz sampling rate)
- XBee Series 2 modules
As shown in the following code, I am sending every readings on arduino to the host PC via xbee (sampling rate 50Hz, when I trace number of reading per seconds on arduino, it also showed around 50) . But, on the receiving side, it gets only around 37 packets per second. When I change the Baud Rate of XBee and serial port to higher values (38400, 57600,115200), more packets are received within a second but packet transmission becomes unstable and stops at some points.
Can anybody help me solve this issue? Is it due to delay of XBee packet transmission?
Regards,
Nyein
/*
ADXL335,Arduino and XBee.
*/
#include
XBee xbee = XBee();
// these constants describe the pins. They won't change:
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1;
int ADCx,ADCy,ADCz;//
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40a097f2);//Change address of computing node
uint8_t payload[7];
int pcount=0;
long previous,current;
int delt;
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
analogReference(EXTERNAL);
delay(1000);
previous=millis();
}
void loop()
{
current=millis();
ADCx = analogRead(xpin);
ADCy = analogRead(ypin);
ADCz = analogRead(zpin);
delt=current-previous;
previous=current;
payload[0] = ADCx >> 8 & 0xff; // payload[0] = MSB.
payload[1] = ADCx & 0xff; // 0xff = 1111 1111, i.e. cuts of the MSB from pin5 and all is left is the LSB
payload[2] = ADCy >> 8 & 0xff; // payload[0] = MSB.
payload[3] = ADCy & 0xff;
payload[4] = ADCz >> 8 & 0xff; // payload[0] = MSB.
payload[5] = ADCz & 0xff;
payload[6]=delt;
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
xbee.send(zbTx);
}