How to upload sketch to ESP8266-07?

Hi,

I have just bought one of these:

https://www.ebay.com/itm/ESP8266-ESP-07-V1-0-Serial-Wifi-Transceiver-Adapter-Module-board-for-Arduino/173847921481?ssPageName=STRK%3AMEBIDX%3AIT&var=472558266984&_trksid=p2057872.m2749.l2649

Now, I have been able to update the firmware. But I`m stuck when it comes to uploading sketches to the module. I have tried to communicate with basic commands such as AT and AT+GMR which gives me expected responses. But how do I actually upload my own sketches or use it within an Arduino sketch?

Thanks for any help!

install esp8266 boards package in Arduino IDE, select generic esp8266, put the esp8266 into programming mode (switch + reset), upload the sketch, turn off programming mode. but the switch will not work long this way. this adapter is good for AT firmware, not to upload sketches.

you could turn off reset after upload in platform.txt, then the sketch would run after upload without the module going into flashing mode. it would retur to flash mode after on reset.

Thanks for your reply.
Should the RX of the Arduino be connected to the RX pin of the ESP8266-module, and the same for the TX-pin? Or should they be swapped, hence TX->RX and RX->TX?

Nickless:
Thanks for your reply.
Should the RX of the Arduino be connected to the RX pin of the ESP8266-module, and the same for the TX-pin? Or should they be swapped, hence TX->RX and RX->TX?

always receive to transmit but if you use the USB of a dev board then the pins are labeled for the main MCU, not for USB chip (which is connected to RX,TX pins of the main MCU)

I only get error when I try to upload it:

esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM6
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
  File "C:\Users\Nickless\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
  File "C:/Users/Nickless/Documents/ArduinoData/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main
    esp.connect(args.before)
  File "C:/Users/Nickless/Documents/ArduinoData/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 468, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
_
the selected serial port _
 does not exist or your board is not connected

I use the following settings:

I have tried to press the reset button multiple times when uploading without luck.

What could the problem be?

how do you connect it to USB of the computer? The Port selection is disabled in your Tools menu. You can't upload without selecting a Port

Juraj:
how do you connect it to USB of the computer? The Port selection is disabled in your Tools menu. You can't upload without selecting a Port

Sorry, it was disconnected at the time I took the screenshot. Should show COM6.

is the board in flashing mode? what USB adapter do you use?

Juraj:
is the board in flashing mode? what USB adapter do you use?

Thanks for your help on this problem! :slight_smile:

Yes, I have set the switch from UART to PROGRAM.
I only have a regular USB cable that is plugged into the Arduino from the USB-port on my computer, then the module (ESP8266-07) is connected to the Arduino`s TX, RX, GRD and 3.3V.

Hence, cable like this:

the esp8266 adapter requires 5 V Vcc.
and wire the esp8266 to Uno as RX to RX, TX to TX (to be connected to USB chip RX to TX). the ATmega should have a sketch without Serial.begin (Blink for example)

See these instructions: Flashing the ESP8266 with an Arduino UNO

Pieter

Juraj:
the esp8266 adapter requires 5 V Vcc.
and wire the esp8266 to Uno as RX to RX, TX to TX (to be connected to USB chip RX to TX). the ATmega should have a sketch without Serial.begin (Blink for example)

Sweet, now it uploaded the WifiScan example sketch to the ESP8266 module. But it seems that I have problem running it. This is what the serial monitors gives:

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld

SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld

SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020

at 75880 baud. Nothing is printed on 115200 as set in the code below.

The example code:

/*
    This sketch demonstrates how to scan WiFi networks.
    The API is almost the same as with the WiFi Shield library,
    the most obvious difference being the different file you need to include:
*/
#include "ESP8266WiFi.h"

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

  // Set WiFi to station mode and disconnect from an AP if it was previously connected
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);

  Serial.println("Setup done");
}

void loop() {
  Serial.println("scan start");

  // WiFi.scanNetworks will return the number of networks found
  int n = WiFi.scanNetworks();
  Serial.println("scan done");
  if (n == 0) {
    Serial.println("no networks found");
  } else {
    Serial.print(n);
    Serial.println(" networks found");
    for (int i = 0; i < n; ++i) {
      // Print SSID and RSSI for each network found
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*");
      delay(10);
    }
  }
  Serial.println("");

  // Wait a bit before scanning again
  delay(5000);
}

crystal frequency should be 26 MHz
flash size 8 MBit is 521kB 1MByte, you selected 8 MByte

Juraj:
crystal frequency should be 26 MHz
flash size 8 MBit is 521kB, you selected 8 MByte

Thanks, changed the settings and tried another sketch which seems to work.
However, for some reason it seems that the module are running old sketches in addition the one I just uploaded. In the serial monitor I see messages that where added to code that is not present in the current sketch, but was a part of earlier sketches.

EDIT: Used flash download tools and erased the flash memory which fixed the old code problem.
Everything seems to work fine now.

Juraj: Thanks a lot for your help, it has been highly appreciated!

if you want to write a sketch for the esp8266, buy a development board with USB and auto-reset circuit like the Wemos D1 mini or NodeMcu. The esp8266 on an adapter like this is only good if you use it with a firmware which you rarely need to re-flash