raspi-gpio get 0-15 #get gpio assignments
cd /tmp
wget <https://project-downloads.drogon.net/wiringpi-latest.deb>
sudo dpkg -i wiringpi-latest.deb
gpio readall # get all the pins
python hangs on serial write() - Raspberry Pi Forums
solution: avoid using ttyAMA0 for python and F28 communication
Used pySerial for sending and receiving data using UART
Welcome to pySerial's documentation - pySerial 3.4 documentation
'''
UART communicate of F28379D and raspberry pi through python
ref: <https://pyserial.readthedocs.io/en/latest/shortintro.html>
Yixiao Liu 11/15/2022
ttyAMA1 has gpio0(pin27) as TX and gpio1(pin28) as RX
connected with SCID of F28(pin 9 RX, pin 10 TX)
run F28 code first
'''
import serial
import struct
from serial import Serial
# initialize the serial port
ser = serial.Serial("/dev/ttyAMA1", 115200) #Open port with baud rate
'''
1) Send "**" as header from pi to F28 and receive 10 floats F28 sends back
'''
# write header for F28 to send 10 floats
ser.write(str.encode('*'))
ser.write(str.encode('*'))
# wait for 40 bytes(10 floats)
s = ser.read(40) # read 40 bytes
floats = struct.unpack('ffffffffff',s) # unpack 40 bytes as 10 floats
print(floats)
'''
2) Send "##" as header, then follow by 10 floats to F28
'''
# ser.write(str.encode('#'))
# ser.write(str.encode('#'))
# for i in range(10):
# ser.write(struct.pack('f',0.1*i + 0.234))
Open port /dev/ttyAMA1
for UART communication, pins can be found with raspi-gpio get 0-15
and gpio readall
ser.write
is used for writing data to F28, ser.read
is for reading data.
struct
is an easy way to pack the data into bytes or unpack the bytes into desired data types.
struct - Interpret bytes as packed binary data - Python 3.11.0 documentation