He creado una interfície con processing que cuando me pongo encima de un cuadrado con el cursor, el xbee (actúa como coordinador) en teoría está enviando una H o L para encender y/o apagar un led controlado con arduino.
En la misma placa arduino, tengo otro xbee (actúa como router) que es el que recibe y arduino tiene el programa que se muestra más abajo para recibir datos:
Pues bien, el protocolo no funciona, ya que processing en principio si que envía los datos que le llegan desde el puerto serie al xbee (coordinador) pero arduino no recibe la comunicación mediante el xbee (router) y no enciende el led.
¿A alguien se le puede acudir el error que tengo?
Muchas gracias.
Programa Interficie Processing (Funciona)
Programa Arduino para recibir paquetes de datos
En la misma placa arduino, tengo otro xbee (actúa como router) que es el que recibe y arduino tiene el programa que se muestra más abajo para recibir datos:
Pues bien, el protocolo no funciona, ya que processing en principio si que envía los datos que le llegan desde el puerto serie al xbee (coordinador) pero arduino no recibe la comunicación mediante el xbee (router) y no enciende el led.
¿A alguien se le puede acudir el error que tengo?
Muchas gracias.

Programa Interficie Processing (Funciona)
Código:
[I]import processing.serial.*;
Serial myPort; // Create object from Serial class int val;
// Data received from the serial port
char[] encendre={0x7E,0x00,0x0F,0x10,0x00,0x00,0x13,0xA2,0x00,0x40,0x89,0x21,0xAF,0xFF,0xFE,0x00,0x00,0x48};
char[] apagar={0x7E,0x00,0x0F,0x10,0x00,0x00,0x13,0xA2,0x00,0x40,0x89,0x21,0xAF,0xFF,0xFE,0x00,0x00,0x4C};
char checksum1=0x00;
char checksum2=0x00;
void setup()
{
size(200, 200);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
for(int i=3;i<18;i++)
{
checksum1+=encendre[i];
}
checksum1=char(0xFF-(checksum1%0xFF));
println(checksum1);
for(int i=3;i<18;i++)
{
checksum2+=apagar[i];
}
checksum2=char(0xFF-(checksum2%0xFF));
println(checksum2);
}
void draw()
{
background(255);
if (mouseOverRect() == true) // If mouse is over square,
{
fill(204); // change color and
for(int i=0;i<18;i++) // set the LED on
{
myPort.write(encendre[i]); // send an H to indicate mouse is over square
}
myPort.write(checksum1);
delay(1000);
println("hI");
}
else { // If mouse is not over square,
fill(0); // change color and
myPort.write('L'); // send an L otherwise }
for(int i=0;i<18;i++) // set the LED off
{
myPort.write(apagar);
}
myPort.write(checksum2);
println("bye");
rect(50, 50, 100, 100); } // Draw a square
}
boolean mouseOverRect() // Test if mouse is over square
{
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}

Programa Arduino para recibir paquetes de datos
Código:
const int ledPin = 6; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
Última edición por un moderador: