Micropython UART doesn't work on Picos RP2040

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
rjw
Posts: 7
Joined: Wed Jan 19, 2022 11:20 am

Micropython UART doesn't work on Picos RP2040

Post by rjw » Wed Jan 19, 2022 11:39 am

Hello,
I'm an absolutely beginner in Micropython Programming.
I don't know how I can ask for help.

I have installed the latest firmware, by enabling UART support and I have taken the example from
the Raspberry Pi Pico Python SDK.

It doesn't work.

After this I tried this code:

from machine import UART, Pin
import time
uart1 = UART(1, 9600, parity=None, stop = 1, bits = 8, tx=Pin(8), rx=Pin(9),timeout=10)
uart0 = UART(0, 9600, parity=None, stop = 1, bits = 8, tx=Pin(0), rx=Pin(1),timeout=10)
txData = b'hello world\n\r'
uart1.write(txData)
time.sleep(0.1)
rxData = bytes()
while uart0.any() > 0:
rxData += uart0.read(1)
print(rxData.decode('utf-8'))

It doesn't work.

Filip
Posts: 4
Joined: Sat Nov 20, 2021 9:50 pm

Re: Micropython UART doesn't work on Picos RP2040

Post by Filip » Wed Jan 19, 2022 2:27 pm

Some info is missing: How did you connect both UART-s?

User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Micropython UART doesn't work on Picos RP2040

Post by karfas » Wed Jan 19, 2022 3:23 pm

rjw wrote:
Wed Jan 19, 2022 11:39 am
It doesn't work.
... is a bit too less for a description of your problem.
What SHOULD it do (what do you expect) ? What DOES it ?
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython UART doesn't work on Picos RP2040

Post by Roberthh » Wed Jan 19, 2022 3:37 pm

Works fine here, after connecting GPIO1 (Pin 1) to GPIO 8 (PIN 12). GPIO0 (Pin 1) to GPIO9 (Pin 12) is required to communication the other way around.

rjw
Posts: 7
Joined: Wed Jan 19, 2022 11:20 am

Re: Micropython UART doesn't work on Picos RP2040

Post by rjw » Wed Jan 19, 2022 3:56 pm

You wrote:
Works fine here, after connecting GPIO1 (Pin 1) to GPIO 8 (PIN 12).
GPIO0 (Pin 1) to GPIO9 (Pin 12) is required to communication the other way around.

My Question:

Why is GPIO1 AND GPIO0 assigned to PIN 1?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython UART doesn't work on Picos RP2040

Post by Roberthh » Wed Jan 19, 2022 4:01 pm

Typo: GPIO1 (Pin 2) to GPIO 8 (PIN 12). For this test you have to connect TX to RX

rjw
Posts: 7
Joined: Wed Jan 19, 2022 11:20 am

Re: Micropython UART doesn't work on Picos RP2040

Post by rjw » Wed Jan 19, 2022 4:15 pm

You wrote in my summary of understanding by merging your 2 replies:

GPIO0 (Pin 1) to GPIO9 (Pin 12)
GPIO1 (Pin 2) to GPIO8 (PIN 12)

Is this a Typo too?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython UART doesn't work on Picos RP2040

Post by Roberthh » Wed Jan 19, 2022 4:43 pm

Right: GPIO8 is Pin 11. RX to TX. I wired it right, but wrote it wrong.

rjw
Posts: 7
Joined: Wed Jan 19, 2022 11:20 am

Re: Micropython UART doesn't work on Picos RP2040

Post by rjw » Wed Jan 19, 2022 5:03 pm

Source:
from machine import UART, Pin
import time
uart1 = UART(1, 9600, parity=None, stop = 1, bits = 8, tx=Pin(8), rx=Pin(9),timeout=10)
uart0 = UART(0, 9600, parity=None, stop = 1, bits = 8, tx=Pin(0), rx=Pin(1),timeout=10)
txData = b'hello world\n\r'
uart1.write(txData)
time.sleep(0.1)
rxData = bytes()
while uart0.any() > 0:
rxData += uart0.read(1)
print(rxData.decode('utf-8'))

Response:

MicroPython v1.18-5-g037b2c72a-dirty on 2022-01-19; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT

It doesn't work, no response at all.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Micropython UART doesn't work on Picos RP2040

Post by Roberthh » Wed Jan 19, 2022 5:13 pm

That's what I get, NOT using a fancy IDE, but just REPL in a terminal emulator (picocom):

Code: Select all

h
he
hel
hell
hello
hello 
hello w
hello wo
hello wor
hello worl
hello world
hello world

hello world

And this is your code, which I use:

Code: Select all

from machine import UART, Pin
import time
uart1 = UART(1, 9600, parity=None, stop = 1, bits = 8, tx=Pin(8), rx=Pin(9),timeout=10)
uart0 = UART(0, 9600, parity=None, stop = 1, bits = 8, tx=Pin(0), rx=Pin(1),timeout=10)
txData = b'hello world\n\r'
uart1.write(txData)
time.sleep(0.1)
rxData = bytes()
while uart0.any() > 0:
    rxData += uart0.read(1)
    print(rxData.decode('utf-8'))

Post Reply