I'm newbie with XBEE and I'm doing something wrong to comunicate different Arduino Mega 2560.
To start I just trying to active a simple BLINK example if I send a '1' or desactive it if I send '0'.
If I get this, I will be able to applicate to my project with other keypressed.
I have configurated my XBees with 1 Coordinators and 6 End-Devices in BROADCAST.
(In XCTU i can send messages from one to other correctly).
Then, with processing I open the serial port to send data from the computer, via coordinator connected to the computer, to the others XBEEs.
The XBEES are connected in Arduinos Mega, waiting for the data. In this
simple code, just waiting 0 or 1 to decide if blink or no blink the led.
But I'm doing something wrong because it does not work.
PROCESSING CODE
import processing.serial.*;
Serial myPort; // Create object from Serial class
int value = 0;
void setup()
{
size(200,200); //make our canvas 200 x 200 pixels big
String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to
match your port
myPort = new Serial(this, portName, 9600);
}
void draw() {
fill(value);
rect(25, 25, 50, 50);
}
void keyPressed(){
if (key == '0') {
myPort.write('0');
println("SEND 0");
}
if (key == '1') {
myPort.write("1");
println("SEND 1");
}
}
I review my code and now is working fine between 2 XBEE devices (1 Coordinator + 1 EndDevice).
char val; // Data received from the serial port
int ledPin = 13; // Set the pin to digital I/O 13
void setup() {
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (Serial.available())
{ // If data is available to read,
val = Serial.read(); // read it and store it in val
Serial.println("HOLA");
}
if (val == '0')
{ // If 0 was received
digitalWrite(ledPin, LOW);
Serial.println("HAS ENVIAT ORDRE 0");// otherwise turn it off
}
if (val == '1')
{ // If 1 was received
digitalWrite(ledPin, HIGH); // turn the LED on
Serial.println("HAS ENVIAT ORDRE 1");
}
}
Now I'm having problems with the comunication with more EndDevices, the answer is not immediate;(
I need to send a lot of '0' or '1' to comunicate the XBEEs.
I have setting them in broadcast mode, with DH 0000 and DL FFFF (with Digi XCTU software).
Any idea how I can get better communication with more than 1 EndDevice?