I am trying to send data between RPi 2 (model B)
and Teensy 3.2
using the GPIO on the Pi (GPIO 14 and 15) and Serial2 on the Teensy (pins 9 and 10).
The problem is, I can only send data from the Pi to the Teensy, but not the other way round.
Python:
import serial
ser = serial.Serial("/dev/ttyAMA0", 9600, timeout=3)
print(ser.is_open) # True
while True:
data = ser.readline()
print("Data: {}".format(data))
Teensy:
void setup() {
Serial2.begin(9600);
Serial2.setTimeout(500);
}
void loop() {
Serial2.println("hello");
delay(1);
}
The Python code always ends up in a timeout (reading empty data).
Things I've tried and didn't help:
Code:
- Changing the timeout, and without timeout
- Loop delay (to slow down read/write speed)
- Testing with read() and print() instead of readline() and println()
Pi:
- Restart (of course)
- Disable and re-enable the UART via raspi-config ("would you like the serial port hardware to be enabled")
- Disable "login shell over serial" (again raspi-config), I read somewhere it might help
- Using sudo
But nothing helped.
I also checked this: UART Send/Receive not working but with no success.
• When "login shell over serial" is enabled, sudo
is required in order to run the Python code (access the port). When it is disabled, it isn't required.
• When I check ls -l /dev/* output, it says "*serial0 -> ttyAMA0
, and one line above serial
. That's all it says about serial. (Not quite sure if that even helps)
• The file /boot/config.txt
has enable_uart=1
I checked the wiring and everything seems to be fine, so I assume it has something to do with the Pi software.
I thought maybe the RX pin is already used by something else, but I couldn't find if, and how I can check it.
What else can I try? Is there something I am missing? Thanks in advance for any help!
Show a photo of the Pi connections.
Are the GPIO in the correct mode? What does piscope show when you send/receive data? – joan Aug 02 '22 at 10:48