xbee help!

Hello,

Im working on a project which consist of a hand held controller with additional sensors. Currently the serial communication between the arduino pro mini and the computer is through an usb cable.

I want the computer and the hand held controller to communicate wirelessly with xbee. Im trying to setup my wireless communication between the arduino and the computer without any luck.

xbee radio 1 is connected to an arduino pro mini using this tutorial: Dios — Kronos Robotics

and the other is connected to the computer using the usb explorer from sparkfun.

This is the picture of my setup:
http://www.eboy.no/documents/image.jpg

I want to transmit serial data from the wireless arduino/xbee setup (left) to the usb explorer/xbee setup right.

First I configured both radios to have the same ID and baud rate in x-ctu. Should I program the arduino before connecting it to the xbee transmitter or? Is this setup completely wrong? Do you recommend another setup?

Thanks for considering my problem.

You shouldn't have to change the baud rate to get two XBees to talk to each other. The only baudrate setting in XCTU is for communication between the XBee and the computer it is attached to. It's best to leave that at 9600 unless you're taking in data directly from a serial device with a fixed rate (e.g., a GPS unit) other than 9600.

If the two XBees have the same ID (I assume you mean "MY", set through ATMY), you might run into problems. You should set one of them to one MY address and the other to a different one. Then set the destination low addresses to match the MY addresses you're sending to:

XBee 0
MY = 0 ["I am XBee 0...
DL = 1 ... and I'm talking with XBee 1"]

XBee 1
MY = 1 ["I am XBee 1...
DL = 0 ... and I'm talking with XBee 0"]

Don't mess with DH unless you have to (you won't). It comes from the factory set to 0. The entire DH/DL destination address has to match, but it's really just DL that you need to work with.

Both XBees need to have the same PanID, and also be on the same channel. If you didn't change those, they should be fine with the factory settings. I assume those are Series 1 XBees, right? If not (that is, if they're Series 2.5) then one of them also needs to be set to be the Coordinator.

Hello,

Thanks for the replay! I manage to program my pro mini board wirelessly with this tutorial (without bootloading the pro mini, should I do it?): Wireless XBee/AVR Bootloading - SparkFun Electronics , however, I only succeed uploading the sketch occasionally (avrdude: stk500_recv(): programmer is not responding).

I followed your recommendation, should I do something else to the xbees?

When I interface with max/msp I use this code:

/******************************************************************************
 *  spi_eboy
 *  Boye Riis jr.
 *  Descember 12, 2009
 *
 *  Prototype eBoy Controller.
 *  SPI code adapted by Julian Bleecker
 *
 *  
 *  Arduino analog input 0 - FSR
 *  Arduino analog input 1 - FSR
 *  Arduino analog input 2 - FSR
 *  Arduino analog input 3 - FSR
 *  Arduino analog input 4 - FSR
 *  Arduino analog input 5 - FSR
 *
 *
 *  Arduino digital pin 13 - SCK      SPI clock      
 *  Arduino digital pin 12 - MISO      SPI master in, slave out
 *  Arduino digital pin 11 - MOSI      SPI master out, slave in
 *  Arduino digital pin 10 - SS      SPI slave select
 *  Arduino digital pin 9 - red LED 
 ******************************************************************************/

// digital accelerometer

#define DATAOUT 11//MOSI
#define DATAIN  12//MISO 
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss for /LIS3LV02DQ, active low

//define values for slip coding
int escapeChar = 101;
int delimiterChar = 100;


byte clr;
int t;


char spi_transfer(volatile char data) {
  //Writing to the SPDR register begins an SPI transaction
  SPDR = data;

  /*Loop right here until the transaction is complete. the SPIF bit is 
         the SPI Interrupt Flag. When interrupts are enabled, and the 
         SPIE bit is set enabling SPI interrupts, this bit will set when
         the transaction is finished. */
  while (!(SPSR & (1<<SPIF))) {
  };

  // received data appears in the SPDR register
  return SPDR;                    
}

void setup() {
  char in_byte;
  clr = 0;
  in_byte = clr;
  Serial.begin(19200);

  //define pin modes
  // set direction of pins
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);

  digitalWrite(SLAVESELECT,HIGH); //disable device

  // SPCR = 01010000
  // Set the SPCR register to 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<CPOL)|(1<<CPHA);
  clr=SPSR;
  clr=SPDR;

  // query the WHO_AM_I register of the LIS3LV02DQ
  // this should return 0x3A, a factory setting
  in_byte = read_register(15); //0x80

  // start up the device
  // this essentially activates the device, powers it on, enables all axes, and turn off the self test
  // CTRL_REG1 set to 10000111
  write_register(0x20, 135);

  // query the WHO_AM_I register of the LIS3LV02DQ
  // this should return 0x3A, a factory setting
  in_byte = read_register(15);

  //delay(250);    
}

// reads a register
char read_register(char register_name) {
  char in_byte;

  // need to set bit 7 to indicate a read
  register_name |= 128;

  // SS is active low
  digitalWrite(SLAVESELECT, LOW);

  // send the address of the register we want to read first
  spi_transfer(register_name);

  // send nothing, but here's when the device sends back the register's value as an 8 bit byte
  in_byte = spi_transfer(0);

  // deselect the device
  digitalWrite(SLAVESELECT, HIGH); 
  return in_byte;
}

// write to a register
void write_register(char register_name, byte data) {
  // clear bit 7 to indicate we're doing a write
  register_name &= 127;

  // SS is active low
  digitalWrite(SLAVESELECT, LOW);

  // send the address of the register we want to write
  spi_transfer(register_name);

  // send the data we're writing
  spi_transfer(data);
  digitalWrite(SLAVESELECT, HIGH);
}

void loop() {

  char message = Serial.read(); //what for max to send a r
  if (message=='r') {


    // read digital values from register
    slipOut(read_register(0x28)); //Read X LSB 32
    slipOut(read_register(0x29)); //Read X MSB 33

    slipOut(read_register(0x2a)); //Read Y LSB 34
    slipOut(read_register(0x2b)); //Read Y MSB 35

    slipOut(read_register(0x2c)); //Read Z LSB 36
    slipOut(read_register(0x2d)); //Read Z MSB 37

    // read analog values
    readAnalog();

    Serial.print(delimiterChar, BYTE);
  }

}


// read 6 analog values
void readAnalog() {
  for (t=0; t<6; t++) {
    slipOutInt(analogRead(t));
  }
}

void slipOut(byte output) {
  if ((output==escapeChar)||(output==delimiterChar)) Serial.print(escapeChar, BYTE);
  Serial.print(output, BYTE);
}

void slipOutInt(int output) {
  slipOut( byte(output & 0xff)); // explicitly mask the LSB using bitwise
  slipOut( byte(output >> 8)); // right-shift for MSB
}

When interfacing with max/msp I only got data once I starting the patch and then the data stops.

Should I add something else to the code when using xbees?

Thanks!

The remote xbee radio is powered by a 9V battery, and the xbee radio has a voltage of 3.28V after regulation.

xbee setup in x-ctu:

remote unit (the wireless)
ID: 28
DL:1
MY:0
baus rate: 19200
D3: do high
IU: disable
input address: FFFF

base unit (connected to the computer):

pan ID: 28
DL: 0
MY: 1
baud rate: 19200
D3: DI
IC: 8

I did not bootload my pro mini, should I?

I want the xbee radios to send/receive serial data from the arduino pro mini and that is not working probably.

Any suggestions?

Thanks! :wink:

I forgot to inform that im using series 1 xbees

If all that you're trying to do is to send serial data from an Arduino through one XBee to another XBee, you don't need the D3, IU, or IC settings. Those are for digital line passing. It looks like you have the right PANID, DL, and MY settings for communications.

I don't see any reference to the XBees at all in the code that you posted. If that code is what you expected to get your XBees working, that's at least part of your problem. It doesn't have anything in it to send data at all.

Here's what you should do:

Set up the Arduino with a counter that starts at 0 and just counts up one each time through the loop. In the loop, have the serial command to send the counter value out through the I/O pin connected to the XBee's DIN pin.

On the other end, connect to your XBee mounted on the USB Explorer through a terminal window. You should see the counts appearing in that window if everything is set up correctly. If that doesn't work, you have something set up incorrectly in your connections, or possibly your XBee settings. Until you can get that working, you should put aside the more complicated parts of your project.

Hello thanks for the reply!

For output of this code iam using so called slip coding for interfacing with max/msp. This because max/msp does not always give you the data in a correct array.
To get an output in max/msp you need to decode the slip values declared in the code. I have used this code for a while with usb connection with huge success and want to adapt it for a wireless solution.

To be ensure that i understood you right: do I have to tell the xbees to transfer serial data in the code? do i have to download the xbee library?

I tried my setup and I managed to upload some sketches without receiving errors, so it might be something wrong with my wiring somewhere....

Does the xbees have any limitations regarding the baud rate? I read that the xbees operates best at 19200 and that they might end up as the bottleneck?!! I prefer to send data at 115200

Hello,

Im not able to get xbee1 and xbee2 talking properly and wonder if my setup is wrong.

Currently I got an Arduino Pro mini which is connected to xbee1. This xbee should send serial data from the arduino to xbee2, which is connected to the computer. The data are then processed in max/msp.

Im controlling the arduino with max/msp and is able to send a r to arduino wirelessly (xbee1) (the build in led on the arduino is blinking when the patch in max/msp is activated), however, I cant get any serial data from the arduino correctly (the rx led on the second xbee is not blinking, only the tx led).
Any suggestions? For serial rx/tx communication, should I set up an arduino for each xbee as in this example: http://lab.guilhermemartins.net/2008/12/24/serial-comunication-with-xbee-arduino/

I just want to get serial data from a remote ardunio to the computer without wires!

Im using this code which is working perfect with a usb cable:

#include <Wire.h>

#define DEVICE (0x53) //ADXL345 device address
#define TO_READ (6) //num of bytes we are going to read each time (two bytes for each axis)
#define DATAX0 0x32 //X-Axis Data 0

byte buff[TO_READ] ; //6 bytes buffer for saving data read from the device
byte setPort = 0;

//define values for slip coding
int escapeChar = 101;
int delimiterChar = 100;
int anPin = 0; // set the analogIn for multiplex
int t;
int ledPin = 13;
int ledStatus = 0;
unsigned long then = 0;
unsigned long now = 0;
int timeout = 1000;

void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200); // start serial for output

//define pin modes
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(ledPin, OUTPUT);

//Turning on the ADXL345
writeTo(DEVICE, 0x2D, 0);
writeTo(DEVICE, 0x2D, 16);
writeTo(DEVICE, 0x2D, 8);
}

void loop()
{
char message = Serial.read();
if (message=='r')

{

//read adxl345
readFrom(DEVICE, DATAX0, TO_READ, buff); //read the acceleration data from the ADXL345

slipOut(buff[0]);
slipOut(buff[1]);
slipOut(buff[2]);
slipOut(buff[3]);
slipOut(buff[4]);
slipOut(buff[5]);

readMultiplexer();
readAnalog();

Serial.print(delimiterChar, BYTE);

ledBlink();
then = millis();
}
else
{
now = millis();
if ((now - then) > timeout)
{
ledBlink();
then = now;
}
else if (then > now)
then = 0;
}
}

void readMultiplexer()
{
int i = 0;

for (i=0; i<=7; i++)
{
setPort = i * 4;
PORTD = setPort;
slipOutInt(analogRead(anPin));
}
}

void readAnalog()
{
for (t=1; t<=1; t++)
{
slipOutInt(analogRead(t));
}
}

//Writes val to address register on device
void writeTo(int device, byte address, byte val)
{
Wire.beginTransmission(device);
Wire.send(address);
Wire.send(val);
Wire.endTransmission();
}

//reads num bytes starting from address register on device in to buff array
void readFrom(int device, byte address, int num, byte buff[])
{
Wire.beginTransmission(device);
Wire.send(address);
Wire.endTransmission();

Wire.beginTransmission(device);
Wire.requestFrom(device, num);

int i = 0;

while(Wire.available()) //device may send less than requested (abnormal)
{
buff* = Wire.receive(); // receive a byte*

  • i++;*
  • }*
  • Wire.endTransmission(); //end transmission*
    }
    void ledBlink()
    {
  • ledStatus = (ledStatus + 1) % 2;*
  • digitalWrite(ledPin, ledStatus);*
    }
    void slipOutInt(int output)
    {
  • slipOut( byte(output & 0xff)); // explicitly mask the LSB using bitwise*
  • slipOut( byte(output >> 8)); // right-shift for MSB*
    }
    void slipOut(byte output)
    {
    _ if ((output==escapeChar)||(output==delimiterChar)) Serial.print(escapeChar, BYTE);_
    _ Serial.print(output, BYTE);_
    }
    [/quote]

Im able to get both xbees talking to each other, however, I wonder if my setup is wrong.

Im controlling the arduino with max/msp and is able to send a r to arduino wirelessly (the build in led on the arduino is blinking when the patch in max/msp is activated), however, I cant get any serial data from the arduino correctly (the rx led on the second xbee is not blinking, only the tx led).

These two statements appear to say opposite things.

Which are you considering the 1st xbee, and which is the 2nd?

Create a simple sketch, where loop checks for serial data. If there is any, read a character, and print "Thanks".

Upload the sketch to the Arduino, and then send it a bunch of letters. See which lights flash on the PC XBee, and which flash on the Arduino XBee. Do you get a reply?

Hello, sorry for the late respons.

Im able to send/receive, however, the xbee radios are not happy with baud rate 115200, Im using 57600. And the other thing is that the xbees are not happy with fast rx/tx transfer of data. Any suggestions for effective and fast rx/tx communication for xbee radios?

Thanks ::slight_smile: