Serial communication issue with esp8266

i have a problem when i try to communicate with an esp8266 true the RX/TX pins on my raspberry pi 4

here is my flow:

[{"id":"eb5487b1.abca58","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"1e06d3a3.a6a2ec","type":"debug","z":"eb5487b1.abca58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1050,"y":420,"wires":[]},{"id":"ad2f5d2e.86ba5","type":"serial in","z":"eb5487b1.abca58","name":"","serial":"fd5d78cd.1a5618","x":820,"y":420,"wires":[["1e06d3a3.a6a2ec"]]},{"id":"8e9f907b.ddef","type":"serial out","z":"eb5487b1.abca58","name":"","serial":"fd5d78cd.1a5618","x":1040,"y":520,"wires":[]},{"id":"6ad27693.5a81f8","type":"inject","z":"eb5487b1.abca58","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"TEST","payloadType":"str","x":830,"y":500,"wires":[["8e9f907b.ddef"]]},{"id":"e9dad7f7.564d08","type":"inject","z":"eb5487b1.abca58","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"1","topic":"","payload":"qweqw","payloadType":"str","x":830,"y":540,"wires":[["8e9f907b.ddef"]]},{"id":"fd5d78cd.1a5618","type":"serial-port","serialport":"/dev/ttyS0","serialbaud":"74880","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"\\n","responsetimeout":"10000"}]

and my esp8266 code:

String command;

void setup() {


void loop() {
  if (Serial.available())
    command = Serial.readStringUntil('\n');

    if (command.equals("TEST")) {
    } else {

what i get is ether complete gibberish or nothing at all

can someone point me to what i'm doing wrong ?

Hi, in order to make code more readable and importable it is important to surround your code with three backticks
like this

You can edit and correct your post by clicking the pencil icon.

See this post for more details - How to share code or flow json

Have you tried with one of the common preset speeds like 19200? Also, try forcing the serial port config to SERIAL_8N1 (link to docs)

yes, i tryed
i ended up on 74880 because the start up sequence on the esp8266 in at that rate.
also just tryed with the SERIAL_8N1 and nothing changed

Reading this article is mandatory for using serial interfaces in a Raspberry Pi computer.

Trying to jump directly to the conclusion here (which is risky but worth a try). I would recommend these steps:

1- Stop Linux from using the primary serial (which may be generating the garbage you reported).

Disable Linux serial console

By default, the primary UART is assigned to the Linux console. If you wish to use the primary UART for other purposes, you must reconfigure Raspberry Pi OS. This can be done by using raspi-config:

  1. Start raspi-config: sudo raspi-config .
  2. Select option 3 - Interface Options.
  3. Select option P6 - Serial Port.
  4. At the prompt Would you like a login shell to be accessible over serial? answer 'No'
  5. At the prompt Would you like the serial port hardware to be enabled? answer 'Yes'
  6. Exit raspi-config and reboot the Pi for changes to take effect.

2- Make sure you are using physical pins 8 (GPIO 14) and 10 (GPIO 15). Good jumper wires please.

3- Use /dev/tty0 in the serial node configuration (as it seems to be the case).

step 1: already done otherwise it would just block the connection and i wouldin't see anything on the serial node
step 2 : yes, i'm sure and i used the same jumper before for programming other microcontrolers and they worked perfectly

step 3 i use /dev/ttyS0

Have you tried switching to a different rate?

tryed them all

i'm correct in thinking that what i'm trying to do should work right ?

Maybe you want to test only the Node-RED part of your setup to ensure TX and RX pins are good ? You can easily connect TX and RX pins of the raspberry with a jumper wire, creating a loopback. This way whatever you transmit from the serial out node is sent to the serial in node. You can see in Node-RED log if the transmission is good. If not then the issue is certainly in the ESP side or a mismatch in the speed.

i tryed whith 2 x wemos d1 mini, and 3 different esp32 board whee 1 of them dont have a serial to usb converter and had to program it true a external serial-usb passing true the rx/tx pins

i also did what you suggested with the RPI and i got the transmission correctly when i loped the jumper

i got i working

i tun off my overclock on the Pi...

anyone know why it matters if i overclock for the serial connection ?

You need to set up higher UART clock for Raspberry Pi. The default UART clock rate is only at 3MHz, which means that you can't use higher serial speed at Pi.

You can add the following line to /boot/config.txt file. You can type "sudo nano /boot/config.txt" command and add this line:

Reboot and see if it works for the high speed.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.