BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need help with ESP-01s and Arduino Nano

I would appreciate help from you.

I have ESP-01S (black board)
adapter like this :


and arduino Nano.

Everything is connected right.
I turned it on and i could detect ESP-01s on mylist of wifi networks “AI THINKER…”
ESP01S TX to Arduino Nano D2 (software RX)
ESP01S RX to Arduino Nano D3 (software DX)

i use following code on arduino and ESP-01S responded AT=OK…
and so on… Everything seems ok…

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
 
void setup() 
{
    Serial.begin(9600);     // communication with the host computer
  //Serial.begin(115200);  
  //while (!Serial)   { ; }
 
    // Start the software serial for communication with the ESP8266
    //ESPserial.begin(9600);  
    ESPserial.begin(115200);
 
 
    Serial.println("");
    Serial.println("Remember to to set Both NL & CR in the serial monitor.");
    Serial.println("Ready");
    Serial.println("");    
}
 
void loop() 
{
    // listen for communication from the ESP8266 and then write it to the serial monitor
    if ( ESPserial.available() )   {  Serial.write( ESPserial.read() );  }
 
    // listen for user input and send it to the ESP8266
    if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }
}

It’s never going to work with a loop() like that, where did you dream that up from?

Further more i create new project on blynk app on my phone,
Put button on it, select output D8, make mode Switch.
Atach led on Arduino Nano D8 and compile and run following code on arduino Nano.

  #define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "my auth";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "my name of my wifi network";
char pass[] = "my wifi network password";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
//SoftwareSerial ESPserial(2, 3); // RX | TX
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  
  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}

On serial monitor i get message that is connected to internet.
but in blynk app i get message: “device is offline”

So what am I doing wrong?

And one more thing after, compiling and running this blynk code on my Arduino Nano
I can not see anymore ESP-01S in my wifi network list…but ESP-01S still responds to AT comands
using first program…This happened to two different ESP-01S boards with 2 different adapters.

Whats going on,please help, i am confused and frustrated…:slight_smile:

You will be, using a Nano and an ESP-01, nightmare connection method. Could have saved yourself a lot of hassle and money too with a plug and play ESP board like the “WeMos”.

An ESP8266 can have at least two WiFi modes… wherein it either broadcasts as an AP that you connect to, or connects as a client to a router. Some tend to start in AP mode so you can connect and setup your routers credentials, then reboot as a standalone dev board.

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-standalone

Or, as is most common for the the ESP-01, you reflash it with AT firmware and then in AT mode it acts as a simple WiFi to Serial adapter for use on the Arduinos, and only connects to the router (thus no broadcast).

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/esp8266-with-at-firmware

Costas thank you for your very Helpful answer, can you offer some concrete answer how to get things running?
Yes i know i can use plentifull ESP8266 stand alone boards,but the thing is that i invest money and time to develop project - shield,where Arduino Nano is main CPU and controlling lots of electronic.

So i want to add wifi controlling feauture over the mobile phone, so Blynk solution seems like natural one… ofcourse if i use standalone ESP8266 boards i need to reconstruct shield pcb, and reconstruct lots of code from Nano to work on ESP8266 standalone board.

So now you understand why i chose ESP01…

So Gunner if I understood you, you suggest to flash ESP01s and see what happens?

Do you know where i can find latest working AT firmware for ESP-01S?
And is it the same for ESP-01 and ESP-01S?

No not really, sorry. Wouldn’t it be great to remotely update your project as you add new features with ESP OTA?

Don’t go flashing your ESP as the AT firmware that’s already on most of them should be tried first for the shield connection method. Just watch the default baud speeds though, set as 9600 crawler speed.

As already stated, sounds like you already have it in AT mode… so click on that 2nd link provided and follow along.

Hi,

I use some ESP-01 with NANO, to speak with ESP over ARDUINO, i use this sketch :

/*Sketch to communicate With ESP-01*/
/*Pensez a changer @IP du Module dans le Sketch*/

//LIBRARIES
#include <SoftwareSerial.h> //WARNING : Support is not garuanted over 9600Bps

//DEFINE PIN
#define ESPSerialTx 5
#define ESPSerialRx 6
  
//OBJECTS
SoftwareSerial ESPSerial(ESPSerialTx, ESPSerialRx); // RX, TX of ARDUINO

void setup()
{
  Serial.begin(9600);
  while (!Serial); 
  ESPSerial.begin(115200);
  while (!ESPSerial);
  Serial.println("CHANGE BAUDRATE 9600, NO PARITY, NO FLUX CONTROL");
  ESPSerial.println("AT+UART_DEF=9600,8,1,0,0");  // Change the baudrate to 9600, no parity, no flux control
  delay(250);
  ESPSerial.begin(9600);
  while (!ESPSerial);
  /*AUTOCONNECT*/
  //Serial.println("AUTO CONNECT OFF");
  //ESPSerial.println("AT+CWAUTOCONN=0");
  //delay(250);
  /*SET STATION MODE*/
  //Serial.println("SET STATION MODE");
  //ESPSerial.println("AT+CWMODE_DEF=1");
  //delay(250);
  /*DISCONNECT*/
  //Serial.println("IF CONNECTED ----> DISCONNECT");
  //ESPSerial.println("AT+CWQAP");
  //delay(250);
  /*SET IP, GATEWAY and MASK*/
  //Serial.println("SET IP, GATEWAY AND MASK");
  //ESPSerial.println("AT+CIPSTA_DEF=\"000.000.000.000\",\"000.000.000.000\",\"000.000.000.000\"");
  //delay(250);*/
}

void loop()
{
  if(ESPSerial.available())  // If the ESP sent any characters
  {
    // Send any characters the ESP prints to the serial monitor
    Serial.print((char)ESPSerial.read());  
  }
  if(Serial.available())  // If stuff was typed in the serial monitor
  {
    // Send any characters the Serial monitor prints to the ESP
    ESPSerial.print((char)Serial.read());
  }
  // and loop forever and ever!
}

For your Blynk sketch, i think ESPSerial speed is set too high. For SofwareSerial librarie the max without errors is 9600bps

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

//LIBRARIES
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*****************************************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "************";
char pass[] = "**************";

//ESP8266 WiFi OBJECTS
SoftwareSerial ESPSerial (5, 6); //RX, TX 
ESP8266 wifi(&ESPSerial); //Use EspSerial to communicate with ESP8266

void setup() {   
  Serial.begin(9600); // Init Debug console
  while (!Serial);  //Wait for Serial ready
  ESPSerial.begin(9600); // Init Serial with Wifi Shield
  while (!ESPSerial); //Wait for EspSerial ready
  /*BEGIN Blynk*/  
  Blynk.begin(auth, wifi, ssid, pass); //Connect to blynk server
}

/*MAIN LOOP*/
void loop() {
  /*RUN BLYNK*/
  Blynk.run();
}

So i did some experiments…
I change code and i Can definitely confirm that AT commands works.
For AT i got OK
For AT+CWMODE=1 i lose ESP from wifi list
For AT+CWMODE=2 i get ESP on wifi list
For AT+CWMODE? i get righ mode
and so on…
Interesting when i change CWMODE-s ESP remember it after cuting of power and starting again.
I did not change firmware yet.
I set CWMODE=1 and when i start serial monitor i get following:

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.10 on Arduino Nano

[605] Connecting to MyNetwork
[13638] AT version:1.2/0.0(Jul  1 3016 20:04:44)
SDK vershon:1.5.4.1(39cC
[23702] Failed to connect WiFi

Then i restart the serial monitor and get this:

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.10 on Arduino Nano

[605] Connecting to MyNetwork
[13638] AT vdrsion:1.2.0/0(Jul  1 2016 20:04:45(
SDK version:1.5.4.1(38cy
[14660] Failed to enable MUX
[15671] Failed to set STA mode

Then i turn off the power and disconnect usb cable and turn on power and usb cable and get this:

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.10 on Arduino Nano

[605] Connecting to MyNetwork
[13638] AT version:1.2/0.0(Jul  1 2016 20:04:45)
SDK version:1.5.4.1(39cV6
[23702] Failed to connect WiFi

And so on … pattern repeats.

here is the code:

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "MyToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MyNetwork";
char pass[] = "MyPassword";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
//SoftwareSerial ESPserial(2, 3); // RX | TX
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  
  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}

Any ideas how to get it working?

Two people have told you that this is too high and that you should be using 9600.
The ESP also needs to be told to receive/send data at 9600, via an AT command. This should only need to be done once, the ESP baud rate change will persist after a reboot.

Pete.

1 Like

Ok. I done following:
1.I change Baud rate to 9600 with AT+UART_DEF=9600,8,1,0,0
2.In code I change software serial baud rate to 9600 and test with AT commands, it worked perfectly and more stable.
3. I change software serial baud rate to 9600 in blynk sketch and test it.

And now i only get followingafter reseting Arduino or power off/on:

[19]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
///_, /////_
/__/ v0.4.10 on Arduino Nano

[605] Connecting to MyNetwork
[3814] AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
OK
[14008] Failed to connect WiFi

----------
[14014] Failed to connect WiFi
[14008] Failed to connect WiFi
[14015] Failed to connect WiFi
[14008] Failed to connect WiFi
[14009] Failed to connect WiFi
[14009] Failed to connect WiFi
[14014] Failed to connect WiFi
[14007] Failed to connect WiFi
[14008] Failed to connect WiFi

[] are those numbers in brackets some kind of error codes?
Any ideas how to get this running?

No, they should be the milliseconds counting up since boot… how you managed to get some out of order is interesting. Mixup with the copy/pasting?

I sometimes find I have to reset my ESP-01/MEGA setup couple of times before finally connecting.

Are you 100% sure that your Wi-Fi SSID and password are correct in your code?
Remember that both SSID and password are case sensitive.

Pete.

Verify your SSID and password, if it’s ok you can :

1-Try to reset your ESP : AT+RESTORE,
2-After fix speed : AT+UART_DEF=9600,8,1,0,0
3-You can fix ESP in station mode : AT+CWMODE_DEF=1
4-And try to fix IP, GATEWAY and MASK : AT+CIPSTA_DEF=“192.168.6.100”,“192.168.6.1”,“255.255.255.0”

you can find list of AT commands here :

Gunner -> those different numbers were different after each reset,i copy/pastethem as they apeared.

Aklain - Thank you, your post is very constructive and helpful…

but i done following:
I set ESP to client mode and disable it’s DHCP
AT+CWDHCP=1,1 - disabled

and i get this:

[19] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.10 on Arduino Nano

[605] Connecting to MyNetwork
[3816] AT version:1.2.0.0(Jul  1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec  2 2016 14:21:16
OK
[9120] +CIFSR:STAIP,"192.168.1.81"
+CIFSR:STAMAC,"dc:4f:22:0a:0b:23"
[9127] Connected to WiFi

:slight_smile: but when i start blynk on my mobile phone i get message “Device is ofline”

And Yes Auth Token is right one and correct.

Any further ideas?

Verify your token.

When your use AT+CIPSTA_DEF you need to enter an IP, GATEWAY and MASK. Verify with “AT+CIPSTA_DEF?” there are all ok. Disable DHCP is not useful when you set an address with AT+CIPSTA_DEF.

This configuration will store in Flash user parameter area.
This configuration interacts with DHCP related AT commands (AT+CWDHCP related):
•If enable static IP, DHCP will be disabled;
•If enable DHCP, static IP will be disabled;
•This will depend on the last configuration.

Any solutions?

I did not realize that i must set all manually.

I set fixed IP,Gateway and Mask with:

AT+CIPSTA_DEF=“192.168.1.100”,“MyGateway”,“255.255.255.0”

and i get this:

[19]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
///_, /////_
/__/ v0.4.10 on Arduino Nano

[605] Connecting to MyNetwork
[3815] AT version:1.2.0.0(Jul 1 2016 20:04:45)
SDK version:1.5.4.1(39cb9a32)
Ai-Thinker Technology Co. Ltd.
Dec 2 2016 14:21:16
OK
[4915] Failed to enable MUX
[8111] +CIFSR:STAIP,“192.168.1.100”
+CIFSR:STAMAC,“dc:4f:22:0a:0b:23”
[8119] Connected to WiFi
[18550] Ready (ping: 38ms).

And example with turning led on/of works…nice

But what this mean “[4915] Failed to enable MUX” ?
Is there any waythat IP,Gateway and Mask can be obtained automatically?

For example i make some project but my “Default Gateway” is not the same every time,
or i want to connect my project to another WiFi network(assuming same nameand password) with another Gateway…

Generally the gateway of your local network should not move. Often this is the IP address used to access the administration of your router, which often acts as a DHCP server. In your case certainly 192.168.1.1 or 192.168.1.254

The error “Failed to enable MUX” can happen at the start.