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]