serial data reading with pico

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
filip12241224
Posts: 9
Joined: Tue Jul 19, 2022 4:33 pm

serial data reading with pico

Post by filip12241224 » Tue Jul 19, 2022 5:07 pm

.
Last edited by filip12241224 on Thu Sep 01, 2022 5:47 pm, edited 1 time in total.

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

Re: serial data reading with pico

Post by Roberthh » Tue Jul 19, 2022 6:25 pm

Reading and writing serial data is done by the machine.UART class. See the documentation at https://docs.micropython.org/en/latest/ ... serial-bus.

To tell, whether the set-up is correct, you can do a loopback test.
  • Connect the max3232 level converter at the TTL side to the Pico, e.g. GPIO0 for TX (Pico out) and GPIO1 for RX (Pico in). Do not forget to connect the max232 GND with the PICO GND pin.
  • Connect RX and TX at the rs232 side, e.g. with a jumper cable,
  • Run in REPL:

Code: Select all

from machine import UART, Pin
uart = UART(0, tx=Pin(0), rx=Pin(1))
uart.write("test message")
print(uart.read())
You should read back the message you have written.

filip12241224
Posts: 9
Joined: Tue Jul 19, 2022 4:33 pm

Re: serial data reading with pico

Post by filip12241224 » Tue Jul 19, 2022 6:37 pm

.
Last edited by filip12241224 on Thu Sep 01, 2022 5:47 pm, edited 1 time in total.

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

Re: serial data reading with pico

Post by Roberthh » Tue Jul 19, 2022 6:39 pm

Try to swap the RX/TX at the PICO. The Pico TX must be connected with the Data in Pin of the max3232 TTL side, and PICO RX with max3232 out.

filip12241224
Posts: 9
Joined: Tue Jul 19, 2022 4:33 pm

Re: serial data reading with pico

Post by filip12241224 » Tue Jul 19, 2022 6:48 pm

.
Last edited by filip12241224 on Thu Sep 01, 2022 5:47 pm, edited 1 time in total.

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

Re: serial data reading with pico

Post by Roberthh » Tue Jul 19, 2022 7:08 pm

Is the max3232 converter powered?

filip12241224
Posts: 9
Joined: Tue Jul 19, 2022 4:33 pm

Re: serial data reading with pico

Post by filip12241224 » Tue Jul 19, 2022 7:29 pm

.
Last edited by filip12241224 on Thu Sep 01, 2022 5:47 pm, edited 1 time in total.

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

Re: serial data reading with pico

Post by Roberthh » Tue Jul 19, 2022 7:40 pm

Just to confirm: for the loopback test, you have to connect at the rs232 side rx and tx and no other connection to rx and tx at the rs232 side. RS232 GND does not matter.

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

Re: serial data reading with pico

Post by Roberthh » Tue Jul 19, 2022 7:42 pm

The default baud rate for UART is 115200. If that is too high, you can set the baud rate as the second parameter, e.g.:

uart=UART(0, 9600, tx=Pin(0), rx=Pin(1))

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

Re: serial data reading with pico

Post by Roberthh » Wed Jul 20, 2022 10:26 am

Yes. It is hard to tell from a distance what could be wrong.

Post Reply