Serial communication using PySense
Mellow last edited by Mellow
Currently i am trying to communicate between a LoPy4 on a PySense and a Raspberry Pi using UART.
I know how i would achieve this in code but the part i am stuck at is selecting the pins.
Judging from the Pinout PDF provided for the PySense i know i can use the external IO header.
Would it be as easy as just choosing two pins for example P10 and P11 and connecting these to my rpi using some cables? Or is Flow control also required which would mean i would select two more pins?
Thanks in advance
@robert-hh I managed to get it to work! Thanks for the help!
I tried some code i found on the forum so i think it had something to do with my code in the end.
I'll try to update this thread with the working code once i finished working on it
@mellow If you disconnect for a moment the rpi and just connect P10 and P11 on your Pysense. After init'ing the UART, if you then uart.write a short message, you shoudl be able to receive it with uart.read(). if that works, the you know the taha is getting out and in from the pysense. You could do a similar test on the rpi.
@robert-hh I just checked to be sure and can confirm they are swapped.
Could you rephrase the second part of your question? i am not sure what u mean by that.
This is the code i am running as far as i know i thinks this should work
I connected the header pins 7 and 8 which correspond to P10 and P11 to my rpi along with GND
import socket import machine import time uart1 = UART(1, 115200, pins=('P11','P10'), bits=8, parity=None, stop=1) uart1.init(baudrate=115200, bits=8, parity=None, stop=1) x = 0 while x < 100: if uart1.any(): data = uart1.readall() print(data) time.sleep(0.25) x += 1
import serial with serial.Serial('/dev/serial0', 115200, timeout=10) as ser: ser.write(b'test')
@mellow Just to ask a silly question? Did you cross TX and RX?
And a test. If at the Pysense connect TX and RX, can you receive what you send?
Allright currently i have P10 and P11 connected to the RX, TX and ground to the GPIO of the pi and changed the pins in my code to this aswell. But when i run it none of the test messages arrive.
Is there anything i am missing?