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?
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)
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.
Juraj:
is the board in flashing mode? what USB adapter do you use?
Thanks for your help on this problem!
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.
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)
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:
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);
}
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