New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UART on Pico with MicroPython has no documentation, please at least include example #19
Comments
Yeah, unfortunately the MicroPython docs haven't been fully updated to reflect the RP2040 port yet micropython/micropython#6855 I've not tried using the Pico's MicroPython UART myself, but I recall seeing this issue which might give you some useful pointers / example code? |
i've been playing around with the uart on the raspberry pico's micropython port hooking up an esp8266 the following code works, it's not great (came from the previous thread)
giving
one gotcha was that although it worked at 115200 I was losing characters now and again if more than 20 or so characters being returned. i could probably have dropped the baudrate only a little but i dropped it all the way to 9600 and no problems |
I think it is a decent example, but it is very different from the others. It only has two UART methods, where an example like i2c.py or spi.py has several. The example above also defines a class. Many people new to the Pico and/or Python probably do not know that "self.any()" refers to UART. No offense @ukscone, I just think the official example for UART should be more "Python basic" and cover more UART functionality. |
We take pull requests. |
Understood. Give me a day please. |
none taken as I agree with you. i was just giving an idea of what actually currently works rather than what is (not) currently documented as what is currently in the micropython docs doesn't actually work :) in the mentioned thread earlier in this thread there are a couple of example-y type things that use "plain" micropython as it currently works on the pico that might be better to flesh out |
not sure if this is any better as an example but it has no class now (in both meanings of the word :) ) but it works and also added the ability to have multiply terminators (i'm a python n00b so please be kind about that bit :) ) that seems to do what I expect
|
In the same format and spirit as the I2C and SPI examples, I think this is a decent example that covers the basic functions of UART on the Pico: from machine import UART, Pin
uart1 = UART(1, baudrate=9600, tx=Pin(8), rx=Pin(9), bits=8, parity=None, stop=1)
uart1.write(b'UART on GPIO8 & GPIO9 at 9600 baud\n\r')
uart0 = UART(0)
uart0.write(b'UART on GPIO0 & GPIO1 at 115200 baud\n\r')
rxData = bytes()
while uart0.any() > 0:
rxData += uart0.read(1)
print(rxData) |
I have scoured for some reference or documentation for the use of UART with MicroPython on the Pico with no luck. The "Raspberry Pi Pico Python SDK" loosely references the MicroPython documentation when discussing UART (pg 14). However, MicroPython's documentation on UART does not seem to apply to the Pico (https://docs.micropython.org/en/latest/library/machine.UART.html), because I don't even think the init() function got ported to the Pico.
I am really lost. I even looked through the "Get started with MicroPython on Raspberry Pi Pico" book and found no examples or references.
Maybe I am being really dumb and missing the documentation on this port. Thank you in advance.
The text was updated successfully, but these errors were encountered: