# Serial communication issue with esp8266

**URL:** <https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593>\
**Category:** General\
**Created:** [3 April 2021 09:47 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593 "2021-04-03T09:47:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 09:47 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/1 "2021-04-03T09:47:44Z")

</div>

Hi,  
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:

```auto
[{"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:

```auto
String command;

void setup() {
  Serial.begin(74880);

}

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

    if (command.equals("TEST")) {
      Serial.println("qwe");
    } else {
      Serial.println("123");
    }
  }
}

```

what i get is ether complete gibberish or nothing at all

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/48d8e27860bc67477cbf250824ce381406a986c3.png)

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2021 09:50 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/2 "2021-04-03T09:50:08Z")

</div>

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](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2021 09:55 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/3 "2021-04-03T09:55:17Z")

</div>

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](https://www.arduino.cc/reference/tr/language/functions/communication/serial/begin/))

---

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 10:03 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/4 "2021-04-03T10:03:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [3 April 2021 12:34 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/5 "2021-04-03T12:34:42Z")

</div>

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

> **[Raspberry Pi Documentation - Configuration](https://www.raspberrypi.com/documentation/computers/configuration.html)**
>
> The official documentation for Raspberry Pi computers and microcontrollers

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](https://www.raspberrypi.org/documentation/configuration/raspi-config.md):
> 
> 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.

 ![raspberry-pi-uart-enabling](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f64082a2284fa7a60a01f322f55ff4263580b94f.png)

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).

---

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 12:52 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/6 "2021-04-03T12:52:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 April 2021 13:10 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/7 "2021-04-03T13:10:23Z")

</div>

> [@francuz152](#):
>
> i ended up on 74880 because the start up sequence on the esp8266 in at that rate

Have you tried switching to a different rate?

---

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 13:10 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/8 "2021-04-03T13:10:43Z")

</div>

tryed them all

---

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 13:14 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/9 "2021-04-03T13:14:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [3 April 2021 13:22 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/10 "2021-04-03T13:22:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 13:34 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/11 "2021-04-03T13:34:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![francuz152](https://avatars.discourse-cdn.com/v4/letter/f/2bfe46/32.png) [@francuz152](https://discourse.nodered.org/u/francuz152)\
**Post date:** [3 April 2021 13:43 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/12 "2021-04-03T13:43:48Z")

</div>

i got i working

i tun off my overclock on the Pi...

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

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [3 April 2021 16:58 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/13 "2021-04-03T16:58:24Z")

</div>

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:  
init\_uart\_clock=14745600

Reboot and see if it works for the high speed.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 April 2021 16:58 UTC](https://discourse.nodered.org/t/serial-communication-issue-with-esp8266/43593/14 "2021-04-17T16:58:40Z")

</div>

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