Esp-01 + Mega... Can't get hard serial working / newb esp questions

So I have an esp-01. I HAVE been able to get the standalone Blynk working well on it (after pulling the chip on an old Uno and using the board for comm), but I am at wits end trying to get it to work as a shield for my Mega. I will also admit that there is just an absurd amount of conflicting and old information out there on the topic. So ultimately, I just can’t get it to work:

Here what I see in serial:

[19] Blynk v0.3.1
[520] Connecting to NETGEAR21
[1530] Failed to disable Echo

My newb questions:

  1. Which set of rx/tx ports on the mega do I connect to?/is this where EspSerial Serial1 <<<— comes into play… like Serial1 corresponds to the TX1/RX1 ports?

  2. Baud rate. My esp boards seems to be working well with 9600, but is it okay that console baud rate and esp baud rate are the same? I don’t really get it.

  3. GPIO-0 and RST… Do I ground these pins at some point in the process of loading this code onto my mega?

  4. AT commands… This is sort of a dumb question, but I don’t actually know how to get back to a point where I can just do AT commands with my esp… Is there some kind of basic sketch I can upload? I mostly ask this because I know one of you is going to ask what firmware version is on it…

  5. My last question… is there any way I can accidentally fry everything? :blush:
    d

And, of course, here is the code I’m trying to upload:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>



// Set ESP8266 Serial object
#define EspSerial Serial1


ESP8266 wifi(EspSerial);

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

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(9600);
  delay(10);

  Blynk.begin(auth, wifi, "NETGEAR21", "derp");

}


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

And this is the working standalone code:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

int derp;

void setup()
{
  
  Serial.begin(9600);
  Blynk.begin(auth, "NETGEAR21", "derpy");
  pinMode(BUILTIN_LED, OUTPUT);
}

BLYNK_WRITE(1){
  derp = param.asInt()+0;
}

void derpalicious() {
  if (derp > 0) {
    digitalWrite(BUILTIN_LED, LOW);
  } else {
    digitalWrite(BUILTIN_LED, HIGH);
  }
}

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

@zeeko,

I use Arduino (Uno / Nano) with ESP. In fact I was asking the same questions about 10 days ago, seems much longer, see ESP8266 with Arduino Newbie Problems for details.
Failed to disable echo almost always means your system is not wired up correctly i.e. your Mega is not correctly wired to the ESP.

I do have a Mega here but it is tied up on another project at the moment. The Mega’s have several serial ports, unlike the Uno’s and Nano’s. I am guessing it will be rx0 and tx0 for you.

Stick with 9600 baud until all is working then you can think about 115200.

With the Mega you don’t do anything with GPIO-o and RST on the ESP. Disconnect the ESP and the RX / TX lines whilst uploading the sketch in the normal way to the Mega. Actually I just disconnect the rx line on my Arduino, leaving the tx connected but power off to the ESP.

Once you have uploaded the sketch to the Mega reconnect power to ESP and rx/tx lines. It is actually quite tedious and I fried an Arduino the other day after connecting up the wires for the hundredth time.

You actually need the basic AT commands on the ESP to be able to connect up the Mega. The Mega can’t talk to an ESP that has an Arduino sketch on it. Load up the AT commands from the details on the xess page at http://www.xess.com/blog/esp8266-reflash/

I’m sue you can fry your ESP if your not careful but they are quite tolerant. I believe they will accept 6V for a short period even though they are rated at 3.3V and I suspect I have accidentally fed 5V at some point without any obvious signs of damage.

Just to add rx on Mega goes to tx on ESP and vice versa.

Holy shit @Costas You are the best.

I’m just going to break this down and leave it here for the next newb.


So you’re a super newb like me with a new esp-01 and an Arduino Mega and you’re running Windows 10. First of all, save yourself a world of pain and DON’T upload the standalone esp8266 Blynk sketch…

If you accidentally did this, or you uploaded that nifty-looking simple led blinking sketch from the esp8266 examples in your arduino IDE to your esp board, read step 1 and then go directly to step 2.

  1. Get the connections right

Read up on the connections- I broke the rules and have mine directly connected to my Mega (with a breadboard). Don’t do this at home, but if you do, it’s: GND-GND, CHPD-3.3V, VCC-3.3v, and you’ll have to experiment with rx/tx combinations- my final successful connection with a Mega running the Blynk hard serial sketch is ESP RX >>> MEGA TX1 (note the ONE… not ZERO. I couldn’t get mine to work on RX0/TX0) and vice versa. However, I flashed the updated AT firmware over an uno (with the chip pulled) with RX -->> RX and vice versa.

If you know you have the right, up to date firmware, continue here, otherwise skip to step 2.

1A- If you’re already running the right AT firmware on your esp (it’s possible that your esp is ready for Blynk action right out of the box), just make the right connections and upload the hard serial Blynk example with your personal internet settings / Blynk token in it. I should also note here that you should be using the Blynk MEGA setting in your App project settings, NOT an esp8266. Further note, you upload the Blynk hardserial sketch to your MEGA not to your esp8266. Once that esp has the right firmware on it, you don’t upload anything to it.

1B- this might be a do-not-try-this-at-home thing, but I left everything on my esp connected to the mega and uploaded the sketch to the mega. Note, I do NOT have gpio-0 OR Rst connected at any point in this process and further note, I am using Serial.begin(9600) and EspSerial.begin(115200) in my working code.

You’re DONE!

So you need new (or you need to re-upload) AT firmware:

  1. get AT communication working

a. Before you plug anything in, if you’re using a mega, just upload a blank sketch.
b. pull up serial, set it to Both NL+ CR and play with the baud- until you can type in AT+GMR (tells you your at firmware version) and get a response.

2C. If you find your version is old (below version 1?), download a new AT firmware (it will be a .bin file) here:

Follow the instructions on the BELOW website, and simple windows uploader discussed, but use the .bin file you downloaded earlier (and make sure to remove all hyphens and periods besides the .bin from the file name before you upload). Repeat. Do not use the firmware update in the below link, use the one you downloaded. We are only using the following link for instructions and for the firmware uploader exe.

***Note on connections. The below website uses buttons on a breadboard to reset the board/put it in flash mode. You don’t NEED buttons (though they’re nice). To get the board into prime flashing state (and you have to do this if you want to get that firmware uploaded), you plug in gpio-0 to ground, and then connect your esp RST to ground and then pull the rst out (you may also need to pull the gpio-0 out as well… try it both ways :slight_smile: )

I will also note that I checked which port my esp was being detected in on the arduino IDE before I uploaded the firmware. It was COM3… Different from the port in the instructions:
http://www.xess.com/blog/esp8266-reflash/

2D If you followed the above instructions, you should be at the prime spot. Go back to step 1A. Crush it.

This is how you make the esp8266-01 work for YOU.

LASTLY:

This is a simple Mega+ESP sketch that allows you to turn on the built in Arduino LED on pin 13 using a BLYNK button (switch) set to virtualpin 1 in the App. Upload this sketch to your MEGA (and you can do it with your esp connected)

#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>

// Set ESP8266 Serial object
#define EspSerial Serial1

ESP8266 wifi(EspSerial);

int derp;

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

void setup()
{
  // Set console baud rate
  Serial.begin(9600);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  Blynk.begin(auth, wifi, "your router name", "your password");
  pinMode(13, OUTPUT);

}

BLYNK_WRITE(1){
  derp = param.asInt()+0;
}

void derpalicious() {
  if (derp > 0) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
}

void loop()
{
  Blynk.run();
  derpalicious();
}
1 Like

@zeeko I’m glad you got up and running, I half wish I had used my real name when I joined the Blynk Community now :grinning:

Nice write up and I have just flashed the bin you referred to (SDK 1.0.0). Anything good in this version of the AT firmware over the other one?

I might add a few Uno / Nano bits later to this thread as we only have the one serial port whereas you Mega guys have 3.

You can always use SoftSerial for debug output. I’d imagine the ESP can use more bps than is needed for a little debug output.

With esp8266 you must pay attention to bit rate set on esp, and one stupid thing, you have try to invert TX and rx? Maybe is just this

[quote=“zeeko, post:4, topic:3783”]2C. If you find your version is old (below version 1?), download a new AT firmware (it will be a .bin file) here:http://esp8266.ru/download/esp8266-firmware/AT22SDK100-2015-03-20-boot1.2.bin
[/quote]

i am trying SO hard, but cant flash the firmware you linked to

i get:
connecting ....Erasing flash... Writing at 0x00000000... (0 %) Writing at 0x00000400... (0 %) Writing at 0x00000800... (0 %) Invalid head of packet

i am SURE i need to reflash my ESP as it was previously loaded with NODEMCU firmware, and i get failed to disable echo whenever i connect to the Mega…

what firmware should i flash!?!

@Dave1829 How are you powering this ESP (and which esp are you using)?

Did you make sure that the arduino has a blank sketch loaded on?

no, have not tried that, just a fully blank sketch? on the arduino? how will i know if it is working?

i was stuck at uploading AT firmware… what other firmware could i try?

i have tried a few, but some work, some say Invalid head of packet about 20% in

i will try a few more now…

esp-01, powered using 5V @ 1A PSU dropped to 3.3v with a AMS1117 and extra 1000uf & 0.1uf caps

is that enough so that i can upload the firmware you suggested?

OK, i just checked, i cant flash the NodeMCU firmware anymore, maybe my ESP is damaged from a bad flash? can that happen?

Yes, a fully blank sketch. How are you currently seeing the process of the flash?

im using FTDI 232RL to flash the ESP01

in the NODEMCU flash window i see:

Note:Program flash success.
Note:Program flash success.
Note:Program flash success.
Note:Program flash success.
Note:Program flash success.
Note:Program flash success.
Error:Write flash timeout.

I connected my esp directly to my uno and it works great. If you have an uno I suggest using it to flash the esp

i dont have an Uno, i have a Mega, but i think the ESP is damaged, :frowning:

i got this in the Arduino IDE:

warning: espcomm_send_command: didn't receive command response
warning: espcomm_send_command(FLASH_DOWNLOAD_DATA) failed
warning: espcomm_send_command: wrong direction/command: 0x01 0x03, expected 0x01 0x04

i’ll solder up a new one… and start afresh from zeeko’s guide above…

OK, i have a new one soldered up, a ESP-12E

this is the firmware:

OK
AT+GMR
AT version:0.25.0.0(Jun  5 2015 16:27:16)
SDK version:1.1.1
Ai-Thinker Technology Co. Ltd.
Jun  5 2015 23:07:20

OK

this is OK to use? yeah? i dont need to change this do i??

BTW - first time PuTTY usage for me - i am learning so much trying to get this going…

I don’t think that firmware will work. Try this one: http://esp8266.ru/download/esp8266-firmware/AT22SDK100-2015-03-20-boot1.2.bin