About to lose my mind - how do I read uart data FROM pico TO a pi zero through GPIO pins?

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

About to lose my mind - how do I read uart data FROM pico TO a pi zero through GPIO pins?

Post by /RaspberryPi »

EDIT: Dear god - I'm not sure if I should be happy or mad. I didn't have a feaking newline ("\n") character at the end of my string so readline() was just waiting and waiting and waiting...
Problem solved...
I've spent the last week reading everything I can find - and I'm about to lose my mind. I have a pico set up with a few temperature sensors. Everything is working correctly on the pico (as far as I can tell). Here is some test code I'm working with on the pico:
import os import utime from machine import ADC, UART, Pin led = Pin(25, Pin.OUT) def temperature(): return 27 - (((ADC(4).read_u16() / 65535)*3.3) - 0.706)/0.001721 uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1), bits=8, parity=None, stop=1) while True: print(temperature()) print(uart) uart.write(f"{temperature()}") #need a new line character here, so uart.write(f"{temperature()}\n") fixes the issue. utime.sleep(1) led.toggle() # so I know the pico is powered/working On the Pi Zero, I can read serial from the pico if I connect both via a micro usb micro usb connection. Such as:
import serial while True: ser = serial.Serial('/dev/ttyACM0', 9600) print(ser.readline().decode("utf-8".rstrip())) However, I cannot figure out how to read uart gpio data on the Pi Zero. I've tried a whole bunch of different methods, but the most progress I've made is with the following code on the pi zero (by progress, I just mean I don't get any errors):
import serial while True: ser = serial.Serial('/dev/ttyAMA0', 9600) print(ser.readline().decode("utf-8".rstrip())) But, I don't get any data back. When I run the script, it just sits there forever like it's listening, but nothing happens.
I have the pi zero and pico wired as follows:
Pi zero powered by USB
Pi Zero pin 1 (3v3) Pico pin 39 (VSYS) Pi Zero pin 6 (GND) Pico pin 3 (GND) Pi Zero pin 8 (UART Tx) Pico pin 2 (UART Rx) Pi Zero Pin 10 (UART Rx) Pico pin 1 (UART Tx) Pi Zero Pin 14 (GND) Pico pin 3 (GND) I've read just about every blog on the internet, I'm not sure what else to do at this point. Any ideas? What am I doing wrong?

submitted by /u/pconwell
[link] [comments]

More...
Post Reply

Return to “Raspberry Pi Forum”