I have a pair of XBee Series 2 radios which are causing me fits.
Configuration:
2x XBee radios, Series 2
-
Latest Firmare
-
One acting as a Coordinator and the other as a Router
-
Product Family: XB24-ZB
-
Function Set: ZigBee {Coordinator, Router} AT
Sparkfun RedBoard
Sparkfun XBee shield
Sparkfun Wireless Joystick kit
Arduino Code:
/*****************************************************************
XBee_Serial_Passthrough.ino
Set up a software serial port to pass data between an XBee Shield
and the serial monitor.
Hardware Hookup:
The XBee Shield makes all of the connections you'll need
between Arduino and XBee. If you have the shield make
sure the SWITCH IS IN THE "DLINE" POSITION. That will connect
the XBee's DOUT and DIN pins to Arduino pins 2 and 3.
*****************************************************************/
// We'll use SoftwareSerial to communicate with the XBee:
#include <SoftwareSerial.h>
// XBee's DOUT (TX) is connected to pin 2 (Arduino's Software RX)
// XBee's DIN (RX) is connected to pin 3 (Arduino's Software TX)
SoftwareSerial XBee(2, 3); // RX, TX
void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
Serial.begin(9600);
Serial.println("Starting Serial");
XBee.begin(9600);
Serial.println("Starting serial connection to XBee");
}
void loop() {
if (Serial.available() > 0) { // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available() > 0) { // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
}
Wireless Joystick controller code:
/* Wireless Joystick Tank Steering Robot Example
* by: Alex Wende
* SparkFun Electronics
* date: 9/28/16
*
* license: Creative Commons Attribution-ShareAlike 4.0 (CC BY-SA 4.0)
* Do whatever you'd like with this code, use it for any purpose.
* Please attribute and keep this license.
*
* This is example code for the Wireless Joystick to control a robot
* using XBee. Plug the first Xbee into the Wireless Joystick board,
* and connect the second to the SparkFun Serial Motor Driver.
*
* Moving the left and right joystick up and down will change the
* speed and direction of motor 0 and motor 1. The left trigger will
* reduce the maximum speed by 5%, while the right trigger button
* will increase the maximum speed by 5%.
*
* Connections to the motor driver is as follows:
* XBee - Motor Driver
* 5V - VCC
* GND - GND
* DOUT - RX
*
* Power the motor driver with no higher than 11V!
*/
#define L_TRIG 6 // Pin used for left trigger
#define R_TRIG 3 // Pin used for right trigger
#define L_JOYSTICK A3 // Pin used for left joystick
#define R_JOYSTICK A0 // Pin used for right joystick
int8_t speedLevel = 20; //Maximum speed (%) = speedLevel * 5 (units are percent)
void setup() {
Serial1.begin(9600); // Start serial communication with XBee at 9600 baud
delay(10);
Serial1.print("W7001\r\n"); // Set the bit in enable register 0x70 to 0x01
pinMode(L_TRIG,INPUT_PULLUP); // Enable pullup resistor for left trigger
pinMode(R_TRIG,INPUT_PULLUP); // Enable pullup resistor for right trigger
}
void loop() {
int16_t leftStick, rightStick; // We'll store the the analog joystick values here
char buf0[10],buf1[10]; // character buffers used to set motor speeds
// Reduce top speed
if(digitalRead(L_TRIG) == 0)
{
speedLevel -= 2;
if(speedLevel < 2) speedLevel = 2;
while(digitalRead(L_TRIG) == 0)
{
delay(2);
}
}
// Increase top speed
if(digitalRead(R_TRIG) == 0)
{
speedLevel += 2;
if(speedLevel > 20) speedLevel = 20;
while(digitalRead(R_TRIG) == 0)
{
delay(2);
}
}
// Read joysticks
// Convert analog value range to motor speeds (in %)
leftStick = (5-(analogRead(L_JOYSTICK)/93))*speedLevel;
rightStick = (5-(analogRead(R_JOYSTICK)/93))*speedLevel;
// Build motor 0 buffer
if(leftStick > 0)
{
sprintf(buf0,"M0F%d\r\n",leftStick);
}
else
{
sprintf(buf0,"M0R%d\r\n",abs(leftStick));
}
// Build motor 1 buffer
if(rightStick > 0)
{
sprintf(buf1,"M1F%d\r\n",rightStick);
}
else
{
sprintf(buf1,"M1R%d\r\n",abs(rightStick));
}
// Send motor speeds
delay(5);
Serial1.print(buf0);
delay(5);
Serial1.print(buf1);
}
When I connect one XBee to the Joystick controller, and the other to a Sparkfun USB XBee explorer, I can see the stream of commands from the controller to the other XBee in X-CTU. This confirms that the two can talk to each other just fine.
I followed the Sparkfun XBee shield hookup guide here: https://learn.sparkfun.com/tutorials/xb … okup-guide. I have the switch on the shield set to DLINE. I have connected one of the XBees to the joystick controller, and the other to the XBee shield.
The problem is that I am not seeing anything on the Arduino Serial Monitor as described in the Hookup guide, except for the two lines which get printed out by the setup function.