Go Down

Topic: Irregular comms between 32U4 and Processing - "mostly" works. (Read 273 times) previous topic - next topic

Harrzack

This project has an A-Star 32U4 ("Arduino") talking to Processing over a CP2104 USB-Serial board.  And it has been MOSTLY successful - but there are many times when the Arduino doen't seem to send when it is supposed to.

There is a simple single-letter protocol between the two sketches so it will be known if the Arduino (the 'slave') program is up or looses power.

Both boards have LED's to indicate serial traffic.  When processing starts it looks for an "A" from the Arduino and begins sending data.

Frequently start Processing, and see the red outgoing LED blinking, but no receive activity on the A-Star board.  Often there is a delay - then suddenly the data starts coming in (joystick coords) and other times the 32U4 just sends nothing.

Just wondering if there is anything I could do to ensure more regular Serial from the Arduino side - Processing seems to be fine.

=Alan R.



Here is a snip of the Ard setup:

Code: [Select]
Serial.begin(57600);
while (!Serial);

ComLink.begin(57600);
byte flush = ComLink.read();  // see ir a read clears things up
tstBut.begin();
Serial.println("System is up!");







Here is the Processing main IO function. "evalData" is just and if-else check for values:

Code: [Select]
void serialEvent(Serial comPort) {
  String comBuf = comPort.readStringUntil('\n');
  if (comBuf != null) {
    comBuf = trim(comBuf);
    if (comBuf.equals("A")) {
      comPort.clear();
      isConnected = true;
      wasConnected = true;
      ardup = true;
      comPort.write("U");  // let Ard know we are up
   
    } else {
      ardCmd= comBuf.charAt(0);
      comPort.clear();
      ardup = false;
      evalData();
    }
  }
}
+++++++++++++++++++++++++++++++++++++
The completion date of a software project is 2 weeks from any given date.

sterretje

Please post complete code (or a minimal version that exhibits the behaviour; most of us don't like digging through massive codes).

Please post links to 3rd party libraries that you use (if any).

You use an 32U4 and a CP2104. Is the CP2104 connected to the RX1 and TX1 pins and do you use Serial1 for that? Your snippet does not show anything related to that except for possibly the ComLink which might indicate the use of SoftwareSerial which in that case would bring the question why you use SoftwareSerial on a device that has an additional serial port.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Harrzack

Sorry to be a bother - project is a bit to big to supply all code.  I did create "ComLink" from Serial1 with this code:   
Code: [Select]
auto& ComLink = Serial1;  //  Sreial1 is UART in U32U

I was just hoping for some general comments on working with Serial - not a full code analysis.

Thanks.

+++++++++++++++++++++++++++++++++++++
The completion date of a software project is 2 weeks from any given date.

sterretje

The Arduino snippet that you showed doesn't do anything with Serial1 (ComLink) except for a call to the begin() method. So how can we possibly know what's going on at the Arduino side?

I've never used processing so can't comment on that part.

If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up