Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7512

Automation, sensing and robotics • Re: Reading JSON from Arduino via Serial Missing Parts of Message

$
0
0

Code:

    if (serial.available() > 0):        data = serial.readString()        # read available data as string        print(data)    return data
That is going to truncate data at times.

If some data has arrived, but not all, you will only read what has arrived, not what hasn't.

You need to keep reading data until you know you have complete data. That involves considering some data may have not yet arrived but will, some time in the future.

Code:

    serial.writeString("d") #send command "d" to request data from Arduino    if (serial.available() > 0):
I am a little surprised you see any data, that the Arduino has replied before you check if anything has.

Doing it properly isn't straight forward. I will see if I can find any useful examples I have.

Statistics: Posted by hippy — Fri Jul 04, 2025 3:25 pm



Viewing all articles
Browse latest Browse all 7512

Trending Articles