Arduino to Raspberry Pi Serial Communication Shows Question Marks

I’m trying to set up communication between an Arduino and a Raspberry Pi 5 using RX and TX pins. Both devices appear to be sending and receiving messages, but the messages (which are strings) show up as question marks (?) in the serial monitor.

When I run the same code using USB communication instead, everything works fine — the strings are displayed correctly. I’ve double-checked the wiring (at least 20 times), and it seems solid.

Could the issue be with my level shifter? I’m using the bidirectional Pololu 2595. Has anyone had similar issues with this model, or have any suggestions on what might be going wrong?

Raspberry pi code:

#!/usr/bin/env python3
import serial
import time

if __name__ == '__main__':
    ser = serial.Serial('/dev/ttyAMA0', 9600, timeout=1)
    ser.reset_input_buffer()

    while True:
        ser.write("Hello from Raspberry Pi!\n".encode('utf-8'))
        line = ser.readline().decode('utf-8').rstrip()
        print(line)
        time.sleep(1)

Arduino code:

void setup() {
  Serial.begin(9600);  // Let's use a standard baudrate
  delay(1000);
}

void loop() {
  if (Serial.available() > 0) {
    // Simple echo functionality
    String message = Serial.readString();
    Serial.print("Arduino received: ");
    Serial.print(message);
    Serial.flush();
  }
}

This is from a high level, as I dont use the frameworks you are using, so this is how I would expect this setup to work.

Pi - Arduino board (not sure which one you are using) UART-UART
.. So RX to TX and TX to RX,
You have a level shifter as one board is working at 3.3V while the other is 5V.

Normally I would expect to see a 2nd uart/serial port as the “monitor” e.g. this could be the USB-UART/RS232 on the arduino.

We can see the UART-UART is the same board (and I would assume the other RS232/UART parameters are the same, i.e. 8 data bits, 1 stop bit, no flow control.

What I cant see is the setup from what board to your “serial monitor”.
This being a 2nd serial port on something would have its own serial settings/baud etc that should match what ever hardware is sending to it.

In both cases you are using a read line command. This command is dependent on the end-of-line terminator being recognized, which is adding an unneeded constraint to the communication. Change both codes to read characters and display the characters (in HEX preferably) as they are received. This will tell you whether anything at all is being received and, if so, what might be stopping it showing as a message.

Um, I’m just passing by.

Not an expert by any means.

? would also be a problem with different speeds. Though both your codes are 9600.

Another thing that sort of stands out for me is UTF-8. Shouldn’t it be UTF-7?

I seem to remember reading an article recently on ASCII codes and the EMOJI stuff.
And for most comms UTF-7 is suffice.
UTF-8 has all the extra characters. Ok, it is backward compatible.
But why complicate things using an extended character set if you only need the basic stuff?

Sorry. Probably I’m wrong. But sometimes things you skip over end up being the problem.

Good luck.

Oh, just asking:
The 3.3v vs 5v part:
What voltages are used by each machine/device?
(Are they both 3.3v or is one 3.3 and the other 5v?)

Hi @bonoo293540

Welcome to the forum!

Generally when you’re getting ? in the serial output with UART communication it will be either be that the Baud rate is not set correctly or there is an issue with the connection. Looking at your code the baud rate looks to be fine for a Pi5 to communicate with an Arduino, assuming you’re using the Arduino IDE, it would be worth double checking that the baud rate is also set to 9600, if it’s anything else you will get [?] instead of what you were expecting.

You would need to make sure that you have GPIO14 attached to PIN 0 on the Arduino and GPIO15 attached to PIN1 on the Arduino.

To rule out the shifter, you could look at using one of the other available channels to see if you get different results.