Skip to main content
2 of 6
edited body
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31

Since you can't use the serial monitor to "see" the incoming data from Processing, here are 2 test sketches that may help you determine if data is received on the Arduino.

Upload the Arduino sketch first. Leave the serial monitor closed. Now run the Processing sketch.

I'm using frameRate(1) in the Processing sketch to send the data once per second, so the mouse X/Y values in the Processing window will be slow to update.

You should see the LED on the Arduino flash on then off quickly as the data is received. If you have a I2C LCD available, you could connect it to the Arduino and print out the incoming data.

As chrisl mentions in the comments, there is still much work to be done to get the raw data in the format you require.

Arduino

int x = 0;
const byte ledPin = 2;

void setup(){
  Serial.begin(9600);
  pinMode(2, OUTPUT);
}

void loop(){
  if(Serial.available() > 0){
    x = Serial.read();
    digitalWrite(ledPin, HIGH);
  }
  else{
    digitalWrite(ledPin, LOW);
  }
}

Processing

import processing.serial.*;
Serial port;
void setup() {
  size(500,300);
  background(148);
  try{
    port = new Serial(this , Serial.list()[0], 9600);
  }
  catch(Exception e){
    System.err.println(e);
    e.printStackTrace();
  }
  frameRate(1);
}

void draw() {
  background(148);
  //@chrisl comment: Finish your data, that you send with \n (newline).
  port.write(str(mouseX)+' '+str(mouseY) + "\n");
  text(mouseX,250,50);
  text(mouseY,250,70);
}
VE7JRO
  • 2.5k
  • 19
  • 28
  • 31