I am trying to modify the tweet-a-watt project and push the data to pachube with an Ethernet shield instead of sending to twitter from my PC. I’m having some trouble reading the xbee analog inputs 0 and 4 (volts and amps). I have the xbee tx is setup just like the Tweet-A-Watt project calls for:
MY=1, SM=4, ST=3, SP=C8, D4=2, D0=2, IT=13, IR=1
I’m basically using the XBee_Test_IOSamples sketch that comes with Xbee.h library to read the data. When I read xbee analog inputs, I get this:
Volts = ( 163.00 211.00 322.00 489.00 650.00 766.00 826.00 837.00 785.00 665.00 493.00 335.00 224.00 172.00 164.00 226.00 351.00 524.00 679.00 )
Current = ( 322.00 489.00 650.00 766.00 826.00 837.00 785.00 665.00 493.00 335.00 224.00 172.00 164.00 226.00 351.00 524.00 679.00 0.00 0.00 )
You’ll notice that the current values are the same as the voltage values, just shifted two spots to the left. Anyone know what I am doing wrong?
Here’s my sketch:
#include <XBee.h>
XBee xbee = XBee();
Rx16IoSampleResponse ioSample = Rx16IoSampleResponse();
void setup() {
xbee.begin(9600);
}
void loop() {
float volts[19];
float current[19];
//attempt to read a packet
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
// got something
if (xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) {
xbee.getResponse().getRx16IoSampleResponse(ioSample);
Serial.print("Received I/O Sample from: ");
Serial.println(ioSample.getRemoteAddress16(), HEX);
Serial.print("Sample size is ");
Serial.println(ioSample.getSampleSize(), DEC);
for (int k = 0; k < ioSample.getSampleSize(); k++) {
volts[k] = ioSample.getAnalog(0, k);
current[k] = ioSample.getAnalog(4, k);
}
// Print array with voltage and current ADC values from Xbee
Serial.print("Volts = ( ");
for (int i = 0; i < samples; i++) {
Serial.print(volts[i]);
Serial.print(" ");
}
Serial.println(" )");
Serial.print("Current = ( ");
for (int i = 0; i < samples; i++) {
Serial.print(current[i]);
Serial.print(" ");
}
Serial.println(" )");
}
else {
Serial.print("Expected I/O Sample, but got ");
Serial.print(xbee.getResponse().getApiId(), HEX);
}
}
else if (xbee.getResponse().isError()) {
Serial.print("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
}
}