[SOLUCIONADO] Problemas enviando datos desde Processing a Arduino a través del Serial Port

Hola a tod@s!

Soy nuevo en Processing. Escribo aquí esperando que alguien pueda echarme una mano;)

Estoy intentando comunicar 2 módulos XBEE S1 entre un ordenador y un Arduino Mega, en modo AT. La configuración de los XBEEs funciona bien pero no consigo enviar datos de Processing a Arduino a través del 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).

Estos son los sketches que he creado, pero que no consigo que funcione. Sólo necesito enviar algnos strings, o integers, para luego actuar en distintas opciones sobre el Arduino:

_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");
      }      
  }
}

Espero que alguien me pueda ayudar, GRACIAS!
Un saludo!

1 Like

¡Hola!

https://www.google.com/search?q="Processing+to+Arduino"+data

Por ejemplo, como:

y

1 Like

hi guys! SOLUCIONADO!! :star_struck:

Un saludo!

1 Like