UART
-
Hello,
I have trouble understanding UART communication on the FiPy.I use a FiPy 1.0, and Pysense but only for Vin, GND, TX0 and RX0 (simpler for me), the rest is done on a breadboard.
Using ATOM text editor, and the following test code :
uart = UART(1) uart.init(9600, bits=8, parity=None, stop=1, pins=('P3','P4')) compteur = 0 while True: pycom.rgbled(0x001000) uart.write("\x30\x31\x32\x33") time.sleep_ms(100) input = uart.read() if input is not None: compteur += 1 print("INPUT : " + str(compteur)) print(input) pycom.rgbled(0x000000) time.sleep_ms(1000)If I connect P3 and P4 with a jumper, I get :
INPUT : 1 b'0123' INPUT : 2 b'0123' INPUT : 3 b'0123' ...in the ATOM editor log (as expected).
However, when I try to read the output with a USB->RS232 converter, my COM debuging software (Docklight) receives (in hex)
D6 B6 96 06And the FiPy reads a giant byte string composed of hundreds (600-700) of '\x00', even though nothing is sent.
If I switch RX/TX then nothing happends, so that is not the issue. The FiPy is up to date.
Do you have any ideas or recommandations for further testing ?
PS : I can use this USB->RS232 converter and Docklight to succesfully chat with other devices such as industrial tiltmeters.
-
You are naming it wrong.
Have a look on the syntax highlighting of input. It is marked red, because input() is an internal function. Rename your variable to something safe like my_input and try it again.
-
Thanks for noticing that, ATOM does not highlight "input" as a keyword...
However, renaming dit not change the result.
-
So in the first post, I was trying reading data sent by the Pycom.
I tried today to read data sent to the Pycom with the following code :uart=UART(1, 115200, bits=8, parity=None, stop=1, pins=('P3','P4')) while True: if(uart.any()>0): compteur += 1 print("INPUT : " + str(compteur) + " (" + str(uart.any()) + ")") buf=uart.read() print(buf)I have a sensor wich sends an ASCII string (18 bytes long) every second. I can read it with an USB->RS232 converter. However, On the pycom, I get the following "gibberish", every 4-5 seconds :
INPUT : 9 (120) b'\x06\x06\xb4\x06d3yj\x06\x06\x06\xb4\x06\x0c\x19Z\r\x06\x06\x06\xb4\x06d3yj\x06\x06\x06\xb4\x06\x0c2Z\r\x06\x06\x06\xb4\x06dgyj\x06\x06\x06\xb4\x06\x0c\x19Z\r\x06\x06\x06\xb4\x06d3yj\x06\x06\x06\xb4\x06\x0c2Z\r\x06\x06\x06\xb4\x06d3yj\x06\x06\x06\xb4\x06\x0ceZ\r\x06\x06\x06\xb4\x06d\x19yj\x06\x06\x06\xb4\x06\x0c2Z\r\x06\x06\x06\xb4\x06d\x19yj\x06\x06\x06\xb4' INPUT : 10 (120) b'\x06\x0ceZ\r\x06\x06\x06\xb4\x06d\x19yj\x06\x06\x06\xb4\x06\x0ceZ\r\x06\x06\x06\xb4\x06d\x19yj\x06\x06\x06\xb4\x06\x0c2Z\r\x06\x06\x06\xb4\x06dfyj\x06\x06\x06\xb4\x06\x0c2Z\r\x06\x06\x06\xb4\x06d\x19yj\x06\x06\x06\xb4\x06\x0ceZ\r\x06\x06\x06\xb4\x06deyj\x06\x06\x06\xb4\x06\x0cfZ\r\x06\x06\x06\xb4\x06d2yj\x06\x06\x06\xb4\x06\x0c\x19Z\r\x06\x06\x06\xb4\x06de'The COM parameters are correct (115200, 8, None, 1). I connected the COM GND of my sensor to the GND of the Pycom.
Does anyone has had a similar issue ? I can't find anything on the forum.
-
Solved : turns out I needed a USB<->TTL and not an USB<->RS232...
I did not know about the TTL standard, as I did not study eletronics at all. Gotta learn the hard way !
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