1

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!

toyota Supra
  • 560
  • 2
  • 6
  • 9
Ron
  • 19
  • 1
  • " so I assume it has something to do with the Pi software" Why this is (unusual) Linux/python code not specific to Pi. Have you checked the Arduino code? Why don't you try some proper diagnostics to see what is actually happening? – Milliways Aug 02 '22 at 09:28
  • @Milliways thanks for the comment. Well, I know that the codes aren't the problem because the Teensy UART works just fine when I connect it to another Teensy, (which means both the code and the board are fine) and the Python code works as well, when I connect it to a PC (and not Pi). That's how I isolated the problem. And therefore, I suspect there is something about the Pi. – Ron Aug 02 '22 at 09:57
  • PCs do not have GPIO. You presumably used a different method of connection which is not relevant to the Pi. 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

0 Answers0