Image.size() different than number uart bytes transmitted for jpg image

When writing a jpg image to uart, the number of bytes transmitted by the uart is much smaller than image.size(). The bytes sent by the uart appear to be a complete jpg image file as the uart transmission begins with Start of Image (0xFF, 0xD8) and ends with End Of Image (0xFF, 0xD9). Some examples of jpg image.size() and number of uart bytes transmitted using quality=30, 50 and 10:

img.size() → # UART Bytes
4571 → 705
6018 → 604
3214 → 638

Is this a bug in the image.size function, or is there another function to obtain the actual number of bytes that will be transmitted for a jpg image?

img = sensor.snapshot().compress(quality=30)
print("Size Image:", img.size())
uart3.write(img)

How did you setup the UART? When you init the UART you need to be particular about how you set it up as it can be configured to drop data.

uart3_baud = 1024000
uart3 = pyb.UART(3, uart3_baud, timeout_char=1000)

Tested with some other packets and all bytes were received correctly.

It’s very likely something on the receiving end, maybe an overflow. The same function used to get the image size is the same one used when returning a buffer for reading (i.e. when you call uart.write(img)). Also these numbers (~700 bytes) can’t be valid JPEG images.

EDIT:

uart3_baud = 1024000

Try a lower baudrate, 115200.

Just to note on this, we have DMA accelerated UARTs. If you use a protocol analyzer you’ll see that once we start sending data it’s sent back-to-back with no breaks at all. If your receiving processor doesn’t have DMA support then it’s likely it can’t handle a higher baud rate as there will be no pauses in the data sent.

The problem does appear to be with the receiving UART buffer on the ESP32. Thanks for pointing me in that direction :slight_smile: