UART on Lopy not recognizing non-default pins



  • I'm trying to setup a LoPy 1.0 with expansion board 2.0 to read GPS data and write that data to an SD card. In the process of debugging the system I noticed that the SD and Uart1 share the use of pin G11/P4. I figured the best option would be to redefine the UART pins in order to be able to use both the UART and SD card at the same time.

    My problem is that when I change the pins to something like P20 and P21 (like in the example) the board will not recognize input and instead continues to only accept data on the G11/P4 pin. Below is some test code that I wrote to try to figure this out. Any help would be greatly appreciated.

    from machine import UART, Pin
    from micropyGPS import MicropyGPS
    import time
    
    uart = UART(1,9600, pins = ('P21','P22'))
    uart.init(9600,bits = 8, parity = None, stop = 1)
    
    while(True):
        if(uart.any()):
            a = uart.read(100)
            print(a)
        else:
            print("No data")
    


  • @eric73 This seems to have solved my problem! Thanks!



  • @paloma
    Hello i have fall in same trap than you (but with i2c pin)

    uart = UART(1,9600, pins = ('P21','P22'))

    You set P21 and P22 as TX/RX, but please notice that when you call

    uart.init(9600,bits = 8, parity = None, stop = 1)

    This function have again internaly default value for RX/TX pin according to pycom documentation -> uart.init(baudrate=9600, bits=8, parity=None, stop=1, * , timeout_chars=2, pins=(TXD, RXD, RTS, CTS))

    So i strongly think that if you change your function call by

    uart.init(baudrate=9600, bits=8, parity=None, stop=1, pins=('P21', 'P22'))

    it will work as you want



Pycom on Twitter