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 = uart.read(5) print('\nREAD: ' + str(s))This is the output:
HELLO WRITTEN: 5 READ: NoneThe gateway sends for example "Hello" to the Fipy. Why is uart.readany() null and why do I get None as result of uart.read()?
-
@fellowes22 try UART(1, ..)
UART0 is connected to P0 and P1 and used for REPL. -
I also tried this. This is the result:
WRITTEN: 5 READ: None uart.any --> 0 -
@fellowes22 try to swap rx and tx
-
@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 (
anywill return 0) andreadwill timeout and returnNone.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
-
@jcaron @robert-hh Thank you guys. It works right now. The problem was RX and TX. I swap them, it works right now.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login