Hello everybody!
I’m newbie in Processing. I’m writing here hoping that someone will be able to help me… Thanks in advance;)
I’m trying to communicate two XBEE S1 modules between the computer and an Arduino Mega, in AT mode. The configuration of the XBEEs were done, and works well, I just need to program the communication from Processing to Arduino through the Serial Port.
I had found a lot of examples, were the Arduino send data to Processing, but neither in the other direction (From Processing to Arduino).
This are the sketches that I’ve created, but I do no get connect them and no receive any data:
_PROCESSING_Tx
/** Processing sketch */
import processing.serial.*;
Serial xbee;
void setup() {
size(300, 300);
println(Serial.list()); // print list of available serial ports
// you might need to change the Serial.list()[VALUE]
xbee = new Serial(this, Serial.list()[5], 9600);
}
void draw() {
}
void keyPressed(){
if (key == '0') {
xbee.write('0');
println("ENVIO 0");
}
if (key == '1') {
xbee.write("1");
println("ENVIO 1");
}
if (key == '2') {
xbee.write("2");
println("ENVIO 2");
}
if (key == '3') {
xbee.write("3");
println("ENVIO 3");
}
}
_ARDUINO_Rx
/** Arduino sketch */
#include <SoftwareSerial.h>
#define xbeeRx 10 // XBee DOUT
#define xbeeTx 11 // XBee DIN
SoftwareSerial xbee = SoftwareSerial(xbeeRx, xbeeTx);
char serialData;
void setup() {
Serial.begin(9600);
xbee.begin(9600);
pinMode(xbeeRx, INPUT);
pinMode(xbeeTx, OUTPUT);
serialData = (char)(('0'));
if (xbee.isListening())
Serial.println("El puerto XBEE esta a la escucha!");
}
void loop() {
if (xbee.available()) {
serialData = xbee.read();
Serial.println("HAS REBUT: ");
Serial.println(serialData);
if (serialData == '0') {
Serial.println("HAS REBUT UN 0");
}
if (serialData == '1') {
xbee.println("HAS REBUT UN 1");
}
if (serialData == '2') {
xbee.println("HAS REBUT UN 2");
}
if (serialData == '2') {
xbee.println("HAS REBUT UN 3");
}
}
}
Waiting for your proposals, thanks for your time and help!
Best!