I have a very simple configuration of a Raspberry Pi Pico H (2021) connected to a Raspberry Pi 4 via USB both are on the latest firmware versions. My end goal is to send temp/humidity data over to the Raspberry Pi 4. I am able to read temp/humidity data from my sensor with no issue, but when I try to send data over USB I run into a lot of problems:
Here is a sample of the code I have on the Pico (micropython 1.22.2)
import time
while True:
print('hello')
time.sleep(1)
Here is what I have running on my raspberry pi 4 (python 3.11):
import time
import serial
ser = serial.Serial('/dev/ttyACM0', 19600, timeout=30)
ser.flushInput()
while True:
line = ser.readline()
if line:
print(line.decode('utf-8'), end='')
When I run my code on the pico, it prints "hello" with no issues. When I run my code on my Pi 4, it will either fail immediately and say the "device reports readiness to read but returned no data", or it will return fragments of the word "hello" with no discernable pattern in responses and then fail with device reports readiness to read but returned no data. For reference, I did check to make sure that the USB device was registered under /dev/ttyACM* and it was. It never has any connection issues, and only has problems when I run the code on the raspberry pi 4 and the pico at the same time
All I want to do is send temp/humidity data over the USB, which is why I made this simple test case. My question here is what am I missing? I reimaged my Pi and flashed the Pico with latest OS and firmware, no other processes should be running that would interfere with serial communication. The only device attached via usb is the Pi Pico, and I tried over a few different USB ports and cables and the same issue occurs, I even tried with a different Pi Pico and had the same issue so I don't think it's the hardware. The only thing I haven't tried is a new Pi 4 but I only have one. It was also new out of the box.
Any help here is appreciated. I would like to believe that I'm not stressing out the hardware but I'm not sure. If there's a better method to approach this let me know.
These questions are always hard to answer, since I do not know what kind of setup do you have. But two things can be improved, and my suspicion is based on what you said here:
"it will either fail immediately and say the "device reports readiness to read but returned no data", or it will return fragments of the word "hello" with no discernable pattern in responses and then fail with device reports readiness to read but returned no data."
This sounds like you have a baudrate problem and generally that you are reading data too quickly.
Also, on the pico side, you are just printing Hello every second, this is not optimal, try to also include serial commands on that side as well.
For now, I would assume that if you tried something like this on your Pi 4:
I have another answer, where I give an example of prompting a reaction from arduino: https://stackoverflow.com/a/77967320/16815358