Skip to content

www.rolfje.com

Make the ESP8266 talk 9600 baud

Posted on 2017-01-022025-10-17 By rolfje 3 Comments on Make the ESP8266 talk 9600 baud

Surprise videoThe default serial speed on the ESP8266 WiFi chip is 115200 baud. If you connect this chip to an Arduino and want to use SoftSerial to talk to it, it will not work. The SoftSerial library is limited to 9600 baud because of hardware limitations of the Arduino. If you want to talk to the ESP8266 with an Arduino at lower speeds, you need to tell the ESP8266 to slow down.

Remco.org noted that sending 115200 baud with SoftSerial works just well enough to throw a command to the ESP8266. So below is a sketch that will do just that for you.

  1. Load or copy/paste the sketch in your Arduino IDE.
  2. Connect the ESP8266 board to the Arduino as follows:
    – ESP TX pin to Arduino softRX pin 4
    – ESP RX pin to Arduino softTx pin 5
  3. Open the Serial Monitor of the Arduino IDE and set it to 9600 bps and CR/LF.
  4. Compile and upload this sketch to the  Arduino.
  5. Wait for the Serial monitor to show:
    AT
    OK
    — Sketch stopped.

You can now use your ESP8266 at 9600 baud. The setting is stored in non-volatile memory, so you only need to do this once.

Here’s the sketch:

/*
 * This sketch switches the ESP8266 from its
 * factory-default setting of 115200 bps to
 * 9600 bps so that we can use SoftSerial to
 * communicate with it.
 * 
 * 1. Connect the ESP8266:
 *    - ESP TX pin to Arduino softRX pin 4
 *    - ESP RX pin to Arduino softTx pin 5
 * 2. Open the Serial Monitor of the 
 *    Arduino IDE and set it to 9600 bps and
 *    CR/LF.
 * 3. Compile and upload this sketch to the   
 *    Arduino.
 * 4. Sit back and watch the magic.
 * 5. If you see "AT OK", it worked.
 * 
 * Settings are stored in Flash memory, you
 * only need to execute this sketch once.
 * 
 * Please note: Although softserial is used
 * to transmit at 115200 bps, you'll notice
 * we never wait for an answer. That is
 * because SoftSerial is not built to receive
 * at speeds above 9600 bps.
 * You have been warned.
 */
#include <SoftwareSerial.h>;

const long sourcebaudrate = 115200;
const long targetbaudrate = 9600;

const int softRX = 4;
const int softTX = 5;

SoftwareSerial softSerial(softRX, softTX);

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

  Serial.println("Tell the ESP8266 to switch from "
                  + String(sourcebaudrate) + " to " 
                  + String(targetbaudrate) + " bps.");

  softSerial.begin(sourcebaudrate);
  softSerial.print("AT+IPR=" 
                  + String(targetbaudrate)
                  + "\r\n");

  delay(500);

  Serial.println("Talk to the ESP8266 at "
                  + String(targetbaudrate) + " bps.");
  softSerial.begin(targetbaudrate);
  softSerial.print("AT\r\n");

  delay(500);

  Serial.println("Reply from the ESP8266:");
  while(softSerial.available() > 0 ) {
    char a = softSerial.read();
    if(a == '\0') continue;
    if(a != '\r' && a != '\n' && (a < 32)) continue;
    Serial.print(a);
  }

  Serial.println("-- Sketch stopped.");
}

void loop() {
}
Hardware, Software Tags:Arduino, hacking, programming, Utilities

Post navigation

Previous Post: Seeed ESP8266 WiFi Breakout Board Pinout
Next Post: Installing GPG keys for Debian Backports

Comments (3) on “Make the ESP8266 talk 9600 baud”

  1. Abdullah El-Nahrawy says:
    2018-05-01 at 11:05

    Please, how can I return esp to work at 115600?

    Reply
    1. rolfje says:
      2018-05-01 at 11:41

      If you take a look at the Arduino source, there is a “sourceBaudRate” and “targetBaudRate”. You should be able to change those to get back at 115200 (please note: you typed 115600, that’s 400 bps too high, maybe that’s the problem.

      Reply
  2. George rothbart says:
    2021-09-07 at 00:17

    This method worked for me, after hours of experimentation, level shifting, search the forums, etc. This little sketch really works. Made my day.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

           

Recent Comments

  • rolfje on Methode Buijs uitgelegd
  • LinkedIn is at Peak Enshittifaction – Will Chatham's Blog on Linked-In not really Opt-in?
  • Hans j on 1N4148 diode as RF switch
  • Roaming Rhonda on DLNA on OSX, done right
  • Frans on How to fix a Krups XN2001 Nespresso machine

Tags

Anonimatron Apple backup design DIY DRM eclipse environment Fun gmail google hacking hamradio Hardware helicopter iphone ipod iTunes Java Keynote maven modelling motorcycle music news opinion oracle osx photo photography programming repair review security Software Steve Jobs T-Mobile technology Time Machine Ubuntu usability Utilities vacation windows Workshop

Categories

  • Apple (105)
  • Divorce (1)
  • Electronics (3)
  • Fun (57)
  • Games (7)
  • Hardware (72)
  • Microsoft (18)
  • Racing (14)
  • Software (134)
  • Uncategorized (65)
  • Workshop (20)

Archives

Copyright © 2025 www.rolfje.com.

Powered by PressBook WordPress theme