Netherlands
Asked

Trouble Receiving Arduino Serial Data

I have an Arduino connected to my PC, where Synthiam ARC is running. Additionally, there are some EZ-Bs connected. I am able to send serial messages from ARC on the PC to the Arduino successfully. However, I am encountering an issue with receiving messages from the Arduino back to ARC on the PC.

When I send a message from the Arduino using serial.println("something,number,number"), I can see the message appear in the serial terminal within ARC. Despite this, my code seems unable to receive the message. I'm using a simple script as shown below:

:loop
$chunk = ComReadAll("COM4")
if ($chunk != "") 
  Print($chunk)
endif
Sleep(20)
Goto(loop)

This code does not print any output, although the COM port is opened with the correct baud rate of 115200. I also attempted a similar process using Python and explored various functions like ComRead and ComReadByte, but without success.

Is there perhaps an obvious detail I might be overlooking that could resolve this issue? Any insights or suggestions would be appreciated.


Related Hardware EZ-B v4
Related Controls Serial Toolbox Serial Terminal

ARC Pro

Upgrade to ARC Pro

Discover the limitless potential of robot programming with Synthiam ARC Pro – where innovation and creativity meet seamlessly.

PRO
Canada
#1  

Hi there! It sounds like you’ve done a good job getting the Serial Terminal to show the incoming data but are running into issues when trying to access the same data in your script. Let’s break down a couple of common causes and how to troubleshoot:


1. Port Sharing Conflicts

Issue:
When multiple skills (or scripts) try to read from the same COM port simultaneously, one might "consume" the data before the other has a chance to read it.

What to Try:

  • Exclusive Access: Close the Serial Terminal (or any other skills using COM4) before running your script. This ensures that your script is the only one accessing the buffer.
  • Dedicated Port: If possible, use a separate COM port for your scripting needs if the Arduino is connected via a multi-port USB adapter.

2. Buffer Consumption and Timing

Issue:
The data you see in the Serial Terminal might have already been read and removed from the buffer when your script tries to read it.

What to Try:

  • Disable Automatic Reading: Temporarily disable the Serial Terminal or Serial Toolbox skill that auto-reads from COM4 so your script can capture the incoming data.
  • Confirm Data Presence: Add some diagnostic prints in your script (or even use breakpoints if possible) to see if data is coming in at all.

3. Script Syntax and Best Practices

Your current ezScript is structured like this:

:loop
    $chunk = ComReadAll(COM4)
    if($chunk != )
        Print($chunk)
    endif
    Sleep(20)
    Goto(loop)

A couple of notes:

  • Empty String Comparison:
    Make sure you’re checking for an empty string correctly. For example, you might want to check:

    if($chunk != "")
    
  • Consistent Port Specifier:
    Ensure that the COM port "COM4" is spelled exactly as expected and that no other code or skill is using it.

Here’s a slightly revised version:

:loop
    $chunk = ComReadAll(COM4)
    if($chunk != "")
        Print($chunk)
    endif
    Sleep(20)
    Goto(loop)

4. Arduino Sending Code

While your Arduino is sending data via:

Serial.println(something, number, number);

Double-check these points:

  • Ensure that the baud rate in your Arduino sketch exactly matches 115200.
  • Confirm that the Arduino is not adding unexpected characters that might cause the receiving code to behave differently.
  • Test with a simple message (e.g., Serial.println("Hello");) to see if that reliably comes through.

Next Steps

  1. Test in Isolation:
    • Temporarily disable the Serial Terminal skill on COM4 so your script is the sole reader of the port.
    • Use the revised ezScript above.
  2. Monitor the Behavior:
    • Watch the ARC output window to see if your print statements show the expected messages.
  3. Double-Check Port Configurations:
    • Ensure that COM4 is indeed the correct port on your PC where the Arduino is connected, and that no conflicts exist.

Do these suggestions help you pinpoint the issue? Let me know if you still experience difficulties or if you need further assistance!


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.