UART - send and receive data

  • Hello together

    I have a question regarding UART at FiPy. In the future the FiPy will be integrated into a gateway. The data comes via UART (P3 / P4) from the Gateway. To test this with the Expansion Board, I wrote the following code:

        uart = UART(0, baudrate=115200, timeout_chars=1200) // PIN P3 & P4
        uart.init(115200, bits=8, parity=None, stop=1)
        writtenstr = uart.write('HELLO')
        print('\nWRITTEN: ' + str(writtenstr))
        s =
        print('\nREAD: ' + str(s))

    This is the output:

    WRITTEN: 5
    READ: None

    The gateway sends for example "Hello" to the Fipy. Why is uart.readany() null and why do I get None as result of

  • @jcaron @robert-hh Thank you guys. It works right now. The problem was RX and TX. I swap them, it works right now.

  • @fellowes22 To test the code independently of the connection with your gateway, just connect RX to TX to see if you receive back what you send.

    Note that here, you would receive something only if the gateway sends any data within one tenth of a second of the script being started (you set the timeout to 1200 chars, which at 115200 bits/s is about 0.1 s). If this is not the case, there are 0 characters available in the buffer (any will return 0) and readwill timeout and return None.

    You probably want to add a loop after you open the connection to wait for data to come in.

    Other possible issues may include:

    • swapped RX/TX as suggested by @robert-hh
    • levels (3.3V / 5V)
    • flow-control mismatch
    • speed/bits/parity settings mismatch
    • the gateway may wait for a specific command before it sends back anything

  • @fellowes22 try to swap rx and tx

  • I also tried this. This is the result:

    WRITTEN: 5
    READ: None
    uart.any --> 0

  • @fellowes22 try UART(1, ..)
    UART0 is connected to P0 and P1 and used for REPL.

Log in to reply

Pycom on Twitter