Getting Gibberish value from Arduino UART port.

I am trying to make Arduino and Raspberry Pi communicate over the UART protocol. Tried the same code on Raspbian OS and got the correct value I was returning which was a simple char H. Made a container in Balena OS for the same thing and tested it out, weirdly, Arduino returns some gibberish value:

[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �
[Logs]    [11/4/2020, 4:22:33 PM] [arduino-uart] �

Hi

Did you follow the steps that we have for using serial on the Pi3 here https://www.balena.io/docs/learn/develop/hardware/i2c-and-spi/#serial ?
Do you get this log after doing this?

Yes. I did. This wasn’t the issue because I noticed that there were correct value once or twice. The value was returning in a loop from Arduino. The correct value was returned only once or twice in some runs. Most times it was just this gibberish.

Can you confirm that the baud rates on both the ends are the same?

Yes, it is. I am using the baud rate of 9600.

Hi,

just to be sure, could you please confirm the following?

  • Which version of Raspberry Pi are you using? If it is Raspberry Pi 3 do you have the pi3-miniuart-bt overlay applied?
  • Are you using the UART0 on GPIO14 and GPIO15 pins?

Also could you please describe your setup a bit more? Who is the reader and who is the writer in your testing application? Where do you read the logs from? In the snippet you attached the “garbage” is unicode ‘REPLACEMENT CHARACTER’ which is a placeholder for invalid input, not the actually received data.

Thanks