Receive data on lopy through serial
@robert-hh how exactly i can do that? Could you give me a hint
@monersss No Idea. You could try loopback tests on both devices (connect Tx and Rx ). Since the driver in both cases buffers what it receives, you could send a message and receive it after that. Then you know that both sides are working by themselves.
@robert-hh com ports are ok since i am able to receive message from lopy on putty or Python connected to serial USB. Do you have any other idea why sending to lopy in this setup may not work?
@monersss You can simply open Python in a cmd window. Then you do not have Atom with all its known and unknown features in place.
Since you are connected with two serial interfaces between LoPy and PC, you have to take care to use the right COM port for your test.
To avoid any confusion with the COM ports, you could connect to the Lopy REPL via Telnet, and supply the Lopy for instance with a separate 5V supply, e.g. from a smartphone charger.
@robert-hh Yes i am connected to lopy both via serial USB and via pins to my computer at the same Time. I run uart script with atom and send Python script via serial. Unfortunately in atom i do not receive any message - none is printed. Sending data from atom to Python works ok... What other way i can check if receive on lopy works?
@monersss I tried to recap that with my PC, using python3, and it works. if you have connected at the same time the LoPy using USB, there may have happened a reassignment of the COM ports.
@robert-hh I have script in Matlab to send the message to lopy over serial:
ser = serial.Serial("/COM6", 9600, timeout = 10)
I have connected to lopy via pins 3 and 4 and running this code from atom:
from machine import UART
uart = UART(1, baudrate=9600, timeout_chars=2000)
y = uart.read(10)
I am able to receive message from Lopy to my computer over serial ( i have checked that on putty), but unfortunately sending message from computer using python does not work, the output is 'None'. Am i missing something in the uart.read part?
robert-hh last edited by robert-hh
@monersss This is not complicated, but has a lot of details.
Handling of the serial interface is done through the machine.UART module. See the documentation about defining and using it. https://docs.pycom.io/chapter/firmwareapi/pycom/machine/UART.html
That works well for all UART ports expect UART 0, which is connected to the USB/UART bridge. This port then can used by sys.stdin.buffer and sys.stdout.buffer for receivings and sending. You have to use the buffer methods, to achieve transparent transmission. If the data you send may contain 0x03, them you have to disable keyboard interrupt, by micropython.kbd_intr(-1).https://docs.pycom.io/chapter/firmwareapi/micropython/micropython.html
Once you have the basic communication done, you need to define a protocol. Ususally you would send a block of data, like up to 64 bytes, with some management values. If you do not care about time, then the easiest protocol would be to echoe the received data, and the sender would compare the reponse with what it has sent. Instead, you can add the usual protocol elements like sequence numbers and integrity check values.