Arduino unable to use data sent by Processing

I am trying to have Processing read a file and send the contents to the arduino to use. I have made my script so basic that when the arduino receives anything from the serial port, it will turn on the built in LED. After getting my arduino to wait for serial input and executing my processing script, the tx led flashes on the arduino, the Processing code executes yet the built in LED does not turn on. I have tested my script with arduino's serial monitor and everything works fine, it is only from Processing. I am sure I am connecting to the right port because I have listed the ports, there is only one port and I have also tried putting the port name instead of the index in.

I have tried sending both strings, chars and ints from Processing, I have tried Serial.read(), Serial.readString(), Serial.readByte and quite literally copy/pasting codes that others have said worked for them with nothing able to work. Is there any way to debug without the serial monitor?

Processing code

import processing.serial.*;
Serial myport;
int portindex=0; // Arduino USB port number from the serial list

void setup(){
myport = new Serial(this,Serial.list()[portindex],115200); // Initialize port
      // Sending the content of the array 
      myport.write(1);
}

Arduino code

int data;
char buffer;
String cumBuffer;
byte bytebuffer;

void setup() {
  Serial.begin(115200); // Starts serial port
  pinMode(LED_BUILTIN, OUTPUT); // on board LED, due = 13
}

void loop() {

  if (Serial.available() > 0) {
    digitalWrite(13, HIGH);
    delay(3000);
    bytebuffer = Serial.read(); // Serial.read()-'0'; 
  }

  if(bytebuffer==1){
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(500);
  }
}

I don't see in your processing code where you send anything to arduino rather than single byte 1

Yes I've tried sending strings, chars, and ints, none of which seemed to work. Each of them for whatever reason is not being used by the arduino

are you selected there the actual port number what your arduino connected to?

Yes that selects the port at index 0 in the list of ports
I have also tried the following which is the same since COM4 is the only listed port

myport = new Serial(this,"COM4",115200);

Which Arduino? Uno/Mega/Nano/ProMini reset when you open the serial port. If you use one of those, try to add a delay of e.g. 5 seconds (not sure how long is needed, you might need longer) to your processing code before you send the data.

I'm using the due and it physically takes me about that long or longer to switch tabs and run the Processing script

I got it working. Just make sure to create the port object only once in the setup loop :confused:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.