| Ligne 217 : |
Ligne 217 : |
| | [[Fichier:ENG-CANSAT-PICO-HowTo-UART.png|480px]] | | [[Fichier:ENG-CANSAT-PICO-HowTo-UART.png|480px]] |
| | | | |
| − | {{ambox|text=It is advised to use the UART(0) on GP0 & GP1. Indeed, UART(1) overlaps the SPI(0) used for Radio module. Alternative UART(1) position used to replicates REPL session. See the [[ENG-CANSAT-PICO-USER-GUIDE|Pinout]] for details.}} | + | {{ambox|text=It is advised to use the UART(0) on GP0 & GP1. Indeed, UART(1) overlaps the SPI(0) used for Radio module. Alternative UART(1) position overlaps the I2C(0) bus. See the [[ENG-CANSAT-PICO-USER-GUIDE|Pinout]] for details.}} |
| | | | |
| | <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
| − | from machine import UART | + | from machine import UART, Pin |
| | + | |
| | + | # UART(0) on GP0 & GP1 |
| | + | uart = UART( 0, baudrate=9600) |
| | | | |
| | # UART(1) on GP4 & GP5 | | # UART(1) on GP4 & GP5 |
| Ligne 226 : |
Ligne 229 : |
| | | | |
| | # Alternate position for UART(1) by using Bus Fabric feature | | # Alternate position for UART(1) by using Bus Fabric feature |
| − | uart = UART( 1, baudrate=9600, timeout=3000) | + | uart = UART( 1, rx=Pin(9), tx=Pin(8), baudrate=9600 ) |
| | + | </syntaxhighlight> |
| | + | |
| | + | The following snip of code duplicates the REPL over the {{fname|UART(0)}} . |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | from machine import UART |
| | + | from os import dupterm |
| | | | |
| | + | uart = UART(0, baudrate=19200, bits=8, parity=None, stop=1) |
| | + | os.dupterm( uart, 1 ) |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| | The {{fname|UART}} class is [https://docs.micropython.org/en/latest/library/machine.UART.html fully described into MicroPython documentation]. | | The {{fname|UART}} class is [https://docs.micropython.org/en/latest/library/machine.UART.html fully described into MicroPython documentation]. |
| | + | |
| | + | The {{fname|dupterm()}} function is [https://docs.micropython.org/en/latest/library/os.html#terminal-redirection-and-duplication described here into the MicroPython documentation]. |
| | | | |
| | {{underline|Tips & Tricks:}}<br />One of the key parameter of UART is the {{fname|timeout}} parameter which indicates the timeout (in ms) to receive the end-of-line on {{fname|UART.readline()}} . | | {{underline|Tips & Tricks:}}<br />One of the key parameter of UART is the {{fname|timeout}} parameter which indicates the timeout (in ms) to receive the end-of-line on {{fname|UART.readline()}} . |