-1

So here are some pictures of the setup I have with an LED, 330 Ohm resistor, Arduino UNO, 2 XBee S1s, and many wires,

http://imgur.com/a/FpKob

For specifics, here is the wiring,

  • XBee Pin 1 (VCC) is connected to Arduino Uno Pin 3.3V
  • XBee Pin 2 is connected to Arduino Uno Pin 1 (TX)
  • XBee Pin 3 is connected to Arduino Uno Pin 0 (RX)
  • XBee Pin GND is connected to the minus column on the breadboard.
  • Arduino Uno Digital Pin 9 is connected to a 330 ohm resistor which is connected to an LED that is connected to the minus column on the breadboard
  • Arduino Uno Pin GND is connected to the minus column on the breadboard
  • And lastly I have another XBee connected to my laptop through a USB dongle

I'm trying to send data in the form of bits through my computer using a program called XCTU to turn the LED on and off. Here is the code for the Arduino,

int led = 9;
int bufferSize = 100;
byte readBuffer[100];
byte lastByte = 0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  digitalWrite(led, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  int toRead = Serial.available();
  if(toRead > 0){
    while(toRead > bufferSize){
      Serial.readBytes(readBuffer, bufferSize);
      toRead = toRead - bufferSize;
    }

    Serial.readBytes(readBuffer, toRead);
    lastByte = readBuffer[toRead - 1]; //reads last big in serial input

    if(lastByte == '1'){
      digitalWrite(led, HIGH);
    }
    else if(lastByte == '0'){
      digitalWrite(led, LOW);
    }
  }
  delay(250);
}

However, when I send a '0' through XCTU, the LED doesn't turn off. What could be causing this? Note that I did not use a shield to connect the XBee to the Arduino Uno, I soldered the pins to the appropriate spots because I thought it was possible after watching this video, https://www.youtube.com/watch?v=wtal7SWZek0

Also, I will be cross-posting this on arduino forums to get as much input on this as possible. I will update both topics frequently to attribute answerers for their input (https://forum.arduino.cc/index.php?topic=435027.msg2998240#msg2998240)

  • There's a whole lot missing here. I'd be helpful to know what you've tried to debug it. For instance, do you know that the xbees are talking to each other, etc. I would start by uploading a program to the uno that prints a string and then open the serial port on your computer and make sure you're seeing that string. That will confirm they are talking to each other and that you haven't reversed rx and tx. – mwwalk Nov 13 '16 at 3:55
  • @mwwalk I've tried what you suggested and I was unable to see the string. I tried reversing rx and tx many times but i haven't been quite successful. I know that both XBees are active because I was able to use the dongle to connect both of them to the computer (one at a time). – Chris Gong Nov 14 '16 at 6:45
0

So after experimenting with the SoftwareSerial library, it seemed that all the wiring was done correctly but the original code was replaced with,

#include "SoftwareSerial.h"

SoftwareSerial XBee(1, 0); //TX is 1, RX is 0 on the Arduino Uno
int LED = 9;

void setup()
{
  // Baud rate MUST match XBee settings (as set in XCTU)
  XBee.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop()
{
  if (XBee.available())  
  { 
    byte c = XBee.read();
    if (c == '1')
    {
      digitalWrite(LED, HIGH);

    }
    else if (c == '0')
    {
      digitalWrite(LED, LOW);
    }
  }
  delay(150);
}

and I am now able to turn an LED on or off with data sent from XCTU.

Note: I forgot to include this in my question but some configuration details were that the XBees I was working with were "XBee 1mW Wire Antenna - Series 1 (802.15.4)". Settings for each XBee configured in XCTU include,

Baud Rate: 9600

Data Bits: 8

Stop Bits: 1

no Parity nor flow control

Channel and Pan ID were identical across both XBees

For the XBee connected to the laptop, DH = 0, DL = 2, MY = 1, and CE = Coordinator[1]

For the XBee connected to the Arduino Uno, DH = 0, DL = 1, MY = 2, and CE = End Device[0]

*Credit to user PaulS on the arduino forum for helping me out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.