Program slower when I send data to Arduino

Hi @bking,

Now I have your sketches running using a Mega with output on Serial2 va ttl-to-usb and Putty window on the PC.

With the Processing frameRate < 5 the comms worked fine. With comms running and Ard reset it never recovered. I tried various changes inside recvWithStartEndMarkers to throw away any chars arriving faster than it could use, but nothing made it better. I added Serial2.prints to see what was doing and it went into recvWithStartEndMarkers and hung up. It seems like the Arduino or serial really can’t handle over-run. In fact I have a note about this on a project.

So I tried making the Ard send a char when it’s ready, and Processing sends. This works, runs with frameRate = 120 and recovers from pressing the reset button. I think it’s sending to the Ard every other draw. To use this idea put this at the end of the Ard loop() function.


  Serial.print("X");
}

In Processing send to Ard only when it asks:

    char in_ch;
    while (arduinoport.available() > 0)
    {
      in_ch = (char) arduinoport.read();
      if (in_ch == 'X')
      {
        while (arduinoport.available() > 0) {arduinoport.read();}
        arduinoPos();
        iXmtCount++;
      }
      break;
    }
1 Like