I have setup (and confirmed working) a XBee serial setup. -Series 1 XBee's-
I have the Sparkfun XBee shield on a redboard.
Arduino XBee set in ATI(2) mode, Coordinator
Remote XBee set in AT mode. DIO4 set as DI, DIO3 set as ADC
Using the following Code to test that I am getting Bits:
int readValue=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()>16){
for (int i=0; i<16; i++){
Serial.print(Serial.read(),HEX);
Serial.print(", ");
}
Serial.println();
}
/*
if (Serial.available()>14) {
if (Serial.read()==0x7E) { //Looks for the start of the Hex Bite
for (int i=0; i<11; i++) { //selects the number of bites to throw away
byte discard = Serial.read(); //Throws away the bites
}
readValue = Serial.read(); //Reads th remaining bites
Serial.print("LED is: ");
if (readValue ==0) {
Serial.println("Off");
}else if (readValue ==16){ //the value its looking for. Eg, pin 4 when on =16
Serial.println("On");
}
}
}
*/
}
I found that when only the DI is used, my bit length is 14. When Analog and Digital are both used I am at 16bit. So far I get it. The Bits being displayed by the serial monitor so I know that they are being sent (and I can manipulate the AI and DI to confirm it changes/works.
Here is where I am having trouble, I tried to load the example Xbee code for Series1_IO listed below, but cant for the life of me sort out what I am doing wrong. Ultimatly I would like to use the remote XBee to send two analog signals and idealy also send it a DO (but thats later). So I figured the serialsoftware lib would be a good place to start.
The Sparkfun Xbee shield has the DLine/UART switch, no matter what I do with the switch, or the RX/TX pins at the top of the code, I cant get any responce from the serial terminal on Arduino's IDE.
I have spent HOURS trying and searching the interwebs but Alas I cant seem to get this to work. In all likely hood I am overlooking something obvious and will feel shame when I see it. But I am really stumped.
/**
* Copyright (c) 2009 Andrew Rapp. All rights reserved.
*
* This file is part of XBee-Arduino.
*
* XBee-Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XBee-Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>.
*/
#include <XBee.h>
#include <SoftwareSerial.h>
/*
This example is for Series 1 XBee Radios only
Receives I/O samples from a remote radio with 16-bit addressing.
The remote radio must have IR > 0, at least one digital or analog input enabled
and DL set to the 16-bit address of the receiving XBee (the one connected to the Arduino).
This example uses the SoftSerial library to view the XBee communication. I am using a
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
with the Arduino Serial Monitor.
*/
// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 8 to TX of usb-serial device
uint8_t ssRX = 2;
// Connect Arduino pin 9 to RX of usb-serial device
uint8_t ssTX = 3;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
SoftwareSerial nss(ssRX, ssTX);
XBee xbee = XBee();
Rx16IoSampleResponse ioSample = Rx16IoSampleResponse();
// 64-bit response is same except api id equals RX_64_IO_RESPONSE and returns a 64-bit address
//Rx64IoSampleResponse ioSample = Rx64IoSampleResponse();
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
// start soft serial
nss.begin(9600);
}
void loop() {
if (Serial.available()>16){
for (int i=0; i<16; i++){
Serial.print(Serial.read(),HEX);
Serial.print(", ");
}
Serial.println();
}
//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);
nss.print("Received I/O Sample from: ");
nss.println(ioSample.getRemoteAddress16(), HEX);
nss.print("Sample size is ");
nss.println(ioSample.getSampleSize(), DEC);
if (ioSample.containsAnalog()) {
nss.println("Sample contains analog data");
}
if (ioSample.containsDigital()) {
nss.println("Sample contains digtal data");
}
for (int k = 0; k < ioSample.getSampleSize(); k++) {
nss.print("Sample ");
nss.print(k + 1, DEC);
nss.println(":");
for (int i = 0; i <= 5; i++) {
if (ioSample.isAnalogEnabled(i)) {
nss.print("Analog (AI");
nss.print(i, DEC);
nss.print(") is ");
nss.println(ioSample.getAnalog(i, k));
}
}
for (int i = 0; i <= 8; i++) {
if (ioSample.isDigitalEnabled(i)) {
nss.print("Digtal (DI");
nss.print(i, DEC);
nss.print(") is ");
nss.println(ioSample.isDigitalOn(i, k));
}
}
}
}
else {
nss.print("Expected I/O Sample, but got ");
nss.print(xbee.getResponse().getApiId(), HEX);
}
}
else if (xbee.getResponse().isError()) {
nss.print("Error reading packet. Error code: ");
nss.println(xbee.getResponse().getErrorCode());
}
}