Not able to read the serial port using serial module of PC's python

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
cvikash
Posts: 6
Joined: Fri Feb 28, 2020 8:32 am

Not able to read the serial port using serial module of PC's python

Post by cvikash » Mon Mar 02, 2020 4:22 pm

Hello all,
I'm new to micropython and don't really understand a lot of things about micropython. I'm trying to write a string using UART(1,9600).write('abc') on serial port COM4 and read it at the PC's python using serial.read(). But when I try to read the data and print it, nothing happens, not even any error message pops up.
Here is the code from micropython and PC's python.
fig1.PNG
fig1.PNG (6.15 KiB) Viewed 2835 times
fig2.PNG
fig2.PNG (4.99 KiB) Viewed 2835 times

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Not able to read the serial port using serial module of PC's python

Post by jimmo » Mon Mar 02, 2020 10:16 pm

How is UART1 on the Pyboard connected to your PC? Do you have an additional FTDI cable or something? Or is COM4 the USB/UART that the REPL runs on?

What type of board are you using? Looks like STM32, but is it a pyboard or a ST dev kit or something else?

cvikash
Posts: 6
Joined: Fri Feb 28, 2020 8:32 am

Re: Not able to read the serial port using serial module of PC's python

Post by cvikash » Tue Mar 03, 2020 8:40 am

Thank you for your reply! No, I don't have any additional cable. COM4 is the USB/UART that the REPL runs on.
Yes the board that I'm using is pyboard v1.1.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Not able to read the serial port using serial module of PC's python

Post by jimmo » Tue Mar 03, 2020 9:45 am

UART (1) is a regular UART, i.e. not connected to the USB in any way. It's on pins X9 and X9.

If you want to write to the "virtual" UART that's made available by USB, then you need to use pyb.USB_VCP -- https://docs.micropython.org/en/latest/ ... B_VCP.html

cvikash
Posts: 6
Joined: Fri Feb 28, 2020 8:32 am

Re: Not able to read the serial port using serial module of PC's python

Post by cvikash » Tue Mar 03, 2020 11:49 am

Thanks a lot Jimmo! :) Virtual UART provided by USB is working fine.

Post Reply