UART eats my 15th char!

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
jakub st
Posts: 2
Joined: Sun Nov 04, 2018 8:00 pm

UART eats my 15th char!

Post by jakub st » Sat Oct 05, 2019 5:59 pm

Hi! I'm New here, so hello to everybody!

I'm trying to read data from GPS module (GY-GPSV3-NEO). As you probably know it communicates via UART.
So first I tied to simulate any UART communication and catch some words.

I found and modified this code:

Code: Select all

	uos.dupterm(None, 1)
	uart = UART(0, 115200)
	ch = b""
	while ch != b"quit":
		if uart.any():
			ch = uart.read()
 			uart.write(ch)
	uos.dupterm(UART(0, 115200), 1)
	
and every time I send a string longer than 15 character it "eats" the 15th character. I don't know how exactly describe it.
hm..
I send "01234567890123456789"
And as answer I get the string without second five, so it is: "012346789012346789"
I've tried with

Code: Select all

uart.readinto(buf)
with buf declaration, or

Code: Select all

ch = uart.readline()
and always the same.
Where do I fail? Where is the problem?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: UART eats my 15th char!

Post by Roberthh » Sat Oct 05, 2019 6:28 pm

You do not fail. By default, the receive buffer has a size of 16. Due to the way it is implemented, the 16th character is lost. There was already discussion bout that, and that it should be fixed. You may avoid that problem by increasing the receive buffer with the keyword argument rxbuf=nnn, e.g.

uart = UART(0, 115200, rxbuf=256)

Trikkitt
Posts: 10
Joined: Mon Aug 13, 2018 8:50 am

Re: UART eats my 15th char!

Post by Trikkitt » Wed Jul 28, 2021 11:43 pm

Looks like this is still a significant bug. I've just wasted a day trying to figure out what is going on with my code. Turns out its a bug in Micropython that looks to have been introduced since I last updated (must be 3 years ago the version I had been using). Very frustrating - please just as a temporary fix change the default buffer size to 16 so that the default behaviour isn't to drop every 16th character received.

Trikkitt
Posts: 10
Joined: Mon Aug 13, 2018 8:50 am

Re: UART eats my 15th char!

Post by Trikkitt » Thu Mar 24, 2022 2:10 am

Well this appears to have got worse. I'm using 1.18 and now no matter what buffer size I try and use I lose the 16th digit. I'm also seeing random other character drops on serial receive. This is driving me nuts! To the point that might have to drop the use of micropython if it can't do something as simple as receive serial data. So frustrating. Any suggestions on what I can do to work around this issue?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: UART eats my 15th char!

Post by Roberthh » Thu Mar 24, 2022 6:39 am

How do youu set up UART?

Trikkitt
Posts: 10
Joined: Mon Aug 13, 2018 8:50 am

Re: UART eats my 15th char!

Post by Trikkitt » Thu Mar 24, 2022 9:14 am

Roberthh wrote:
Thu Mar 24, 2022 6:39 am
How do youu set up UART?
I've tried a few different method. I've tried it with just specifying the timeout value to 1000, setting the character time out to 1000, trying timeout figures of 20 and 2, trying the rxbuf set to 15,16, 100 and 256. All resulted 16th digit loss, or total data loss from the 16th digit seemingly at random, I couldn't tell why i'd see one result over the other.

Post Reply