0

I am trying to read data from an MLX90640 thermal camera using the GY-MCU90640 board based on this tutorial.

VIN is connected to 5V (4)
GND is connected to GND (6)
RX is connected to TX/GPIO14 (8)
TX is connected to RX/GPIO15 (10)

Serial is enabled without login shell using sudo raspi-config/Interfacing/Serial. I2C is disabled using sudo raspi-confi/Interfacing/I2C.

However, when trying to read some data using the following Python script, I only receive weird characters such as i)2iKbi!��(R�Bi!�(�ke�+ik. At least the lines are changing when moving my hand above the sensor, so I assume it is kind of working.

#!/usr/bin/env python
import time
import serial

ser = serial.Serial(
        port='/dev/serial0',
        baudrate = 9600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS,
        timeout=1
)

while 1:
        ser.write(serial.to_bytes([0xA5,0x15,0x01,0xBB]))  # configure for 9600 kbps baud rate
        x=ser.readline()
        print x

Not surprisingly the proposed main.py script to read thermal images fails with ValueError: invalid literal for int() with base 10: '+'.

3
  • 1
    There's a lot more in the program given in the tutorial. Have you tried it as released by the author? Sending the configuration string within your while loop looks particularly suspicious.
    – Bob Brown
    Commented Mar 21, 2020 at 0:03
  • @BobBrown indeed, I moved it above the loop, but still no luck. The main.py script fails with errors like ValueError: invalid literal for int() with base 10: '+'.
    – F1iX
    Commented Mar 21, 2020 at 14:32
  • how do you know that the data is garbage?
    – jsotola
    Commented Mar 21, 2020 at 21:00

2 Answers 2

2

GY-MCU90640 modules I have seen had a default baudrate of 115200, not 9600. Since your symptoms look exactly like baudrate mismatch, this is the first thing I would try to rectify.

Note that GY-MCU90640 also has an I2C interface which is much faster (around 400000 instead of 115200) and doesn't have any configuration options you can get wrong as the UART interface does. I would definitely use that instead of the UART.

0

When I see strange characters like this I immediately think about the serial setup. I would play around with the combination of baud rate, parity, byte size and stop bits until I got readable text coming back.

I note that the default baud rate (see image 1) for the device is 115200 and it seems they are proposing 8 bit word, no stop bit and no parity. Try something like:

ser = serial.Serial( port='/dev/serial0', baudrate = 115200, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1

3
  • Thanks for your reply! I tested 9600 and 115200, with both I receive stuff like )MC�v�|����dkC. With 460800 I do not receive anything. Configurations mentioned in the manual (e.g. ser.write(serial.to_bytes([0xA5,0x15,0x03,0xBD]))) do not change anything.
    – F1iX
    Commented Mar 21, 2020 at 13:59
  • Is there anything on the Raspberry 4 which could disturb the communication such as Bluetooth mentioned for older models?
    – F1iX
    Commented Mar 21, 2020 at 15:55
  • Given you have 2 unknowns, what the RPi serial connection is up to and the settings for the thermal camera module it might be a good strategy to split up the problem. I use Coolterm on my Mac (also runs on Windows) to work with devices that use a serial connection. It's easy to setup and change through the various combinations of serial port settings and you'll get immediate feedback when you get the values correct. Take a look at mac-usb-serial.com/docs/tutorials/… or coolterm.en.lo4d.com/windows for more information.
    – mhaselup
    Commented Mar 22, 2020 at 3:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.