usbtemp / usbtemp-python3

USB thermometer Python3 library with example application
MIT License
5 stars 3 forks source link

Read/write error on Ubuntu ARM #1

Open Antovigo opened 1 year ago

Antovigo commented 1 year ago

Hello, I am trying to measure temperature with the blue version of the usbtemp thermometer, from an Odroid C4 microcomputer, running an ARM version of ubuntu. When I run the provided python script, I always get a "Read/Write error".

I tried running the program step by step to trace the problem back, for example:

import serial

uart = serial.Serial('/dev/ttyUSB0')
uart.reset_input_buffer()
uart.reset_output_buffer()
uart.baudrate = 9600
uart.write(b'\xf0')
uart.read(1)

In that case the program stalls and the read command never returns. If I instead instantiate the Serial object with timeout = 1, then the read command returns an empty bytes string after one second. Since it's an empty string, this is what triggers the "Read/Write error' in the python script. (The write command returns 1)

When I connect the thermometer to my laptop, which is also running Ubuntu, I can run the script and get a temperature reading, so it's not a problem with the hardware. Any idea what could happen?

jaka commented 1 year ago

Can you check if there is any process that is using /dev/ttyUSB0 ? Hint: lsof /dev/ttyUSB0

I assume you have verified (e.g. with dmesg) that /dev/ttyUSB0 is the correct device.

Antovigo commented 1 year ago

Thanks for your reply. lsof does indeed list Python3 as a process that uses /dev/ttyUSB0, if I run it while the read command is waiting.

I assume you have verified (e.g. with dmesg) that /dev/ttyUSB0 is the correct device

I should have started with that, sorry. When I plug the thermometer, I get an "unsupported device" error for each driver:

[ 2184.188488] usbserial: USB Serial support registered for pl2303
[ 2242.828298] usb 1-1.1.7: new full-speed USB device number 7 using xhci-hcd
[ 2242.929386] usb 1-1.1.7: New USB device found, idVendor=067b, idProduct=23a3
[ 2242.929392] usb 1-1.1.7: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2242.929394] usb 1-1.1.7: Product: USB-Serial Controller 
[ 2242.929397] usb 1-1.1.7: Manufacturer: Prolific Technology Inc. 
[ 2242.929399] usb 1-1.1.7: SerialNumber: EJCZb116L16
[ 2242.960003] usb 1-1.1.7: Unsupported device
[11983.869428] usbcore: registered new interface driver cp210x
[11983.869467] usbserial: USB Serial support registered for cp210x
[12208.431850] usb 1-1.1.7: USB disconnect, device number 7
[12220.735943] usb 1-1.3: new full-speed USB device number 8 using xhci-hcd
[12220.885384] usb 1-1.3: New USB device found, idVendor=067b, idProduct=23a3
[12220.885391] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[12220.885393] usb 1-1.3: Product: USB-Serial Controller 
[12220.885395] usb 1-1.3: Manufacturer: Prolific Technology Inc. 
[12220.885398] usb 1-1.3: SerialNumber: EJCZb116L16
[12220.911947] usb 1-1.3: Unsupported device

Both pl2303 and cp210x are present in the output of lsmod, if I understand correctly it means that the drivers are here. Is it possible that the device is just not compatible with my ARM board?

jaka commented 1 year ago

Can you paste output of uname -a? Do you have installed at least Ubuntu 20.10?

Antovigo commented 1 year ago

The kernel is from 2022:

Linux odroid 4.9.277-82 #1 SMP PREEMPT Fri Feb 18 14:35:13 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
jaka commented 1 year ago

Kernel should be at least 5.5, or be patched with https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/drivers/usb/serial/?id=ebd09f1cd417fce9c85de3abcabf51eadf907a2a 4.9.227 was released on 28th July 2021 and does not support PL2303GL.

Can you upgrade? Or patch?

Antovigo commented 1 year ago

Ok, it sounds like this is the issue. I will try to patch my kernel! Thanks for your help.