I'm trying to get communication though UART with a freedom board working with Python3 on Raspberry 3 Jessie. This is my first attempt and I don't have any experience in that. The code of the freedom board is maintained by someone else, I have only control over the pi.
Problem 1: When I try to send something with uart.write("Test".encode())
the whole program hangs on this line and doesn't respond anymore.
Here is a test I tried:
uart = serial.Serial('/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS, timeout=1)
uart.write("Test".encode())
Problem 2: The code doesn't seem to be able to received data.: When I try do run a program to simply receive and print everything I get, it doesn't seem to receive anything at all.
uart = serial.Serial('/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS, timeout=1)
while True:
rec = uart.read(2)
print("Rec: {0}".format(rec))
time.sleep(0.1)
I get the following output:
Rec: b''
Rec: b''
Rec: b''
Rec: b''
I assume that read() runs into a timeout after 1 second because it didn't receive anything and then just prints an empty binary-string, is that correct?
Some questions:
According to elinux.org/RPi_Serial_Connection I have to set "Serial" setting in raspi_config to disabled in order to use it for this purpose. Is that correct?
What can I do, when write() doesn't return properly and hangs the whole code?
is
/dev/ttyAMA0
the right port? I have connected the GPIO pins 14 and 15 for TX and RX. Afteruart = serial.Serial(......)
I can test the connection withuart.isOpen()
and it returns true. Because of this I think it is correct. Right?I don't receive anything at all. What can I do?
Thanks in advance for any help.
ttyAMA0
as the breakout UART since by default on the Pi 3 it is not. If you haven't done that, then you should... – goldilocks Mar 17 '17 at 09:41