[Solved :]UART read
I have a serial device that I would like to integrate with my LoPy via UART ( P3 and P4 pins). Currently, if I connect the serial device's Tx and Rx with my computer via 9 pin DB9 connector ( COM 1 port: pin 2 and 3 ) and TeraTerm or similar with 9600/8/none/stop serial configuration..... on sending two ~~ or "escape" key sequence the serial device wakes up and then if I type "R it gives output. Or instead of ~~R I could also use CTRL+E
So I tried to replicate that in code but I don't seem to get ANY response except "None" using ~~R or CTRL-E, what am I missing here. Also, I tried swapping the Tx and Rx line as well just in case:
from machine import UART # Tx and Rx (``P3`` and ``P4``) import struct import time import pycom pycom.heartbeat(False) uart1 = UART(1, baudrate=9600) uart1.init(9600,bits=8,parity=None, stop=1) uart1.write(b'0x1B') # LETS TRY THE ESCAPE ESCAPE R which should be 27 27 82 in ASCII or 1B 1B 82 in Hex uart1.write(b'0x1B') uart1.write(b'0x82') # Or try CTRL-E which is Decimal 05 or hex 05 #uart1.write(b'0x05') recv=uart1.read(15) # read up to 5 bytes print(recv)
Thanks a lot.
robert-hh last edited by
@dda The ASCII code of R is 0x52 or decimal 82, not 0x82
@dda Yep that will be it. Some sort of RS232 -TTL will be required, unless the device has a TTL connection buried inside. They usually do then use a TTL -> RS232 or RS485 to present the external serial interface.
Its a 9 pin RS232, so I see the problem now.....the voltage and logic is way different for both. So, I guess the way around might be to use a RS232 to TTL-UART converter, unless there is another work around to it.
Might be a stupid question but is the computer serial port a TTL UART (0-3V) or an RS232 serial port.
Many serial ports (DB9) on a PC are RS232 (very different voltage) and not a TTL UART which is on the PyCOM.