Difference between revisions of "Basics: Connecting and flashing the ESP8266"
(Basics about connecting and flashing ESP's) |
|||
Line 18: | Line 18: | ||
the "Sonoff basic" switch, or a ESP8266 on a | the "Sonoff basic" switch, or a ESP8266 on a | ||
breadboard. | breadboard. | ||
+ | |||
You may also use a nodeMCU or a WeMOS D1 mini. | You may also use a nodeMCU or a WeMOS D1 mini. | ||
The nodeMCU and the WeMOS D1 mini are recommended for newcomers. They are the most easily to handle version of ESP8266 | The nodeMCU and the WeMOS D1 mini are recommended for newcomers. They are the most easily to handle version of ESP8266 | ||
− | If you have a nodeMCU or a WeMOS, you just need | + | If you have a nodeMCU or a WeMOS, you just need an USB cable, that's all |
For other devices you need a power supply with 3,3V | For other devices you need a power supply with 3,3V | ||
Line 34: | Line 35: | ||
Again: Do NOT use 5V devices! | Again: Do NOT use 5V devices! | ||
− | Last but not least you need some cables with plugs("DuPont cables"). | + | Last but not least you need some cables with plugs ("DuPont cables"). |
Depending on your ESP you may need different cables such as | Depending on your ESP you may need different cables such as | ||
male/male, male/female or female/female. | male/male, male/female or female/female. | ||
− | It's recommended to get | + | It's recommended to get an assorted bunch of such cables as |
you may need them to connect sensors, actuators and such | you may need them to connect sensors, actuators and such | ||
for testing. Buy cables with many different colours. It helps.... | for testing. Buy cables with many different colours. It helps.... | ||
Line 56: | Line 57: | ||
Use a high quality power supply like MeanWell or similiar. | Use a high quality power supply like MeanWell or similiar. | ||
+ | It should have at least a current of 1 ampere. | ||
Do not use the 3,3V supplied by the UART board. | Do not use the 3,3V supplied by the UART board. | ||
Line 66: | Line 68: | ||
Recommended types are those with a CH340G or a CP2xxx chip. | Recommended types are those with a CH340G or a CP2xxx chip. | ||
+ | |||
+ | If you get an UART with settable 5V/3,3V set it to 3,3V. | ||
+ | With some UART cables a wire has to be soldered accordingly. | ||
Do not use cheap converters with a FTDI232 chip! | Do not use cheap converters with a FTDI232 chip! | ||
Line 91: | Line 96: | ||
On testing it's usefull to see what the ESP is doing. | On testing it's usefull to see what the ESP is doing. | ||
− | ESPEasy ist programmed to give informations via the | + | ESPEasy ist programmed to give informations via the |
serial port, the same port you use for flashing. | serial port, the same port you use for flashing. | ||
− | For monitoring you may use the Arduino IDE, a simple | + | |
− | terminal software like putty or a specialized program | + | For monitoring you may use the Arduino IDE, a simple |
+ | terminal software like putty or a specialized program | ||
like ESPlorer (www.esplorer.ru). | like ESPlorer (www.esplorer.ru). | ||
These programs support a lot of devices so you have to | These programs support a lot of devices so you have to | ||
set some parameters: | set some parameters: | ||
− | |||
− | |||
− | |||
− | + | ESPEasy uses a transfer speed of 115200 bit/s. | |
− | + | You have to set this speed in the program, otherwise you get "letter garbage" on the screen. | |
− | + | ||
+ | |||
+ | NOTE: | ||
+ | A usual mistake: Do not start the flashing program with the serial monitor running! | ||
+ | The program started first will grab the COM-port! If your monitor programm is | ||
+ | running the flash program will not find the COM port and will give an error. | ||
Line 156: | Line 164: | ||
It's an "enable" pin you may use to switch off the whole ESP-Chip. | It's an "enable" pin you may use to switch off the whole ESP-Chip. | ||
Put a 10KOhm resistor between CH_PG and Vcc to keep the ESP running at all. | Put a 10KOhm resistor between CH_PG and Vcc to keep the ESP running at all. | ||
+ | |||
+ | Devices with an embedded ESP-Chip (Sonoff basic or 4ch for example) will have | ||
+ | these resistors on board. Just GPIO0 has to be set to ground with a jumper | ||
+ | bridge or via a pushbutton. | ||
+ | |||
'''4. Connecting to the computer for flashing''' | '''4. Connecting to the computer for flashing''' | ||
Line 161: | Line 174: | ||
'''4.1 Get your computer ready''' | '''4.1 Get your computer ready''' | ||
− | + | Install the serial monitoring program of your choice. | |
− | UART (USB->TTL) converter. | + | Install the drivers for your UART (USB->TTL) converter. |
Plug in the UART and open the device manager. Under the | Plug in the UART and open the device manager. Under the | ||
Line 195: | Line 208: | ||
Now connect the UART: | Now connect the UART: | ||
− | UART ESP | + | UART ESP |
− | Rx Tx | + | Rx Tx |
− | Tx Rx | + | Tx Rx |
− | Gnd Gnd | + | Gnd Gnd |
Do not switch on the power supply yet! | Do not switch on the power supply yet! | ||
Connect the power supply to Vcc (3,3V) and Gnd. | Connect the power supply to Vcc (3,3V) and Gnd. | ||
− | + | If using higher voltage power supplies, use a voltage regulator! | |
Watch out not to swap the leads accidentally - it will kill the ESP. | Watch out not to swap the leads accidentally - it will kill the ESP. | ||
Line 238: | Line 251: | ||
and go back to the monitoring program. | and go back to the monitoring program. | ||
− | On a fresh ESP it starts | + | On a fresh ESP it starts clearing some areas of the flash. |
Wait until it is done. | Wait until it is done. | ||
Line 271: | Line 284: | ||
and go back to the monitoring program. | and go back to the monitoring program. | ||
− | On a fresh ESP it starts | + | On a fresh ESP it starts clearing some areas of the flash. |
Wait until it is done. | Wait until it is done. | ||
Line 326: | Line 339: | ||
[To do: | [To do: | ||
Links, pictures, schematics. | Links, pictures, schematics. | ||
− | Troubleshooting should be expanded] | + | Troubleshooting should be expanded. |
+ | Some formatting...] |
Revision as of 20:01, 14 June 2017
You may hear some construction noise in the background...
Basics: How to connect and flash the ESP8266
************* WARNING ************** Some devices as the "Sonoff basic" have their own power supply on board. DO NOT USE THIS POWER SUPPLY FOR FLASHING! Mains Voltage is dangerous for you and your computer! Always use a separate power supply. ************************************
1. What hardware do i need?
You obviously need a device with ESP8266. This can be a device with built-in ESP like the "Sonoff basic" switch, or a ESP8266 on a breadboard.
You may also use a nodeMCU or a WeMOS D1 mini.
The nodeMCU and the WeMOS D1 mini are recommended for newcomers. They are the most easily to handle version of ESP8266
If you have a nodeMCU or a WeMOS, you just need an USB cable, that's all
For other devices you need a power supply with 3,3V or a power supply with higher voltage and a voltage regulator down to 3,3V.
DO NOT USE MORE THEN 3,3V AT THE ESP! It will kill the chip
Further you need a USB to TTL converter (UART) that supports 3,3V.
Again: Do NOT use 5V devices!
Last but not least you need some cables with plugs ("DuPont cables").
Depending on your ESP you may need different cables such as male/male, male/female or female/female.
It's recommended to get an assorted bunch of such cables as you may need them to connect sensors, actuators and such for testing. Buy cables with many different colours. It helps....
1.1. A word about power supplies
Do yourself a big favour: Avoid cheap power supplies!
We have seen some strange behaviour from cheap power supplies. If you put a voltmeter on these it shows the correct voltage. Everything looks nice.
If you use an oscilloscope you may get some nasty surprises. Oscillating voltage, ripples.....
Use a high quality power supply like MeanWell or similiar. It should have at least a current of 1 ampere.
Do not use the 3,3V supplied by the UART board.
The voltage regulators on these boards usually are far too limited to feed the ESP.
1.2 Recommended UART (USB to TTL converter)
Recommended types are those with a CH340G or a CP2xxx chip.
If you get an UART with settable 5V/3,3V set it to 3,3V. With some UART cables a wire has to be soldered accordingly.
Do not use cheap converters with a FTDI232 chip!
The FTDI232 might be one of the most faked chips at all. The genuine manufacturer took measurements against these fakes.
They will not work correctly at least with Windows. Everything looks fine, apparently flashing worked well.
But the code you flashed into the ESP is corrupted!
A genuine FTDI232 UART will cost around 15€ and up! Avoid these cheap 2€ FTDI's you may find on eBay or AliExpress!
Always remember to first install the drivers for the UART before plugging it to your computer!
2. Software
You can use several different softwares for flashing the ESP. It's recommended to use the flasher that is delivered with the ESPEasy software. It needs no settings and works just out of the box.
On testing it's usefull to see what the ESP is doing.
ESPEasy ist programmed to give informations via the serial port, the same port you use for flashing.
For monitoring you may use the Arduino IDE, a simple terminal software like putty or a specialized program like ESPlorer (www.esplorer.ru).
These programs support a lot of devices so you have to set some parameters:
ESPEasy uses a transfer speed of 115200 bit/s. You have to set this speed in the program, otherwise you get "letter garbage" on the screen.
NOTE: A usual mistake: Do not start the flashing program with the serial monitor running! The program started first will grab the COM-port! If your monitor programm is running the flash program will not find the COM port and will give an error.
2.1. Firmware
Of course you need the ESPEasy firmware. You will have to download the .zip file from github. Unpack the .zip to a folder of your choice.
Those who want to compile their own version of ESPEasy should take a look at the wiki to find HowTo's.
Now you're prepared to connect your ESP8266.
3. Some basics about flashing
Those using the nodeMCU or WeMOS D1 mini may skip this paragraph. Everything is ready to use on these boards.
The ESP usually starts up from the internal flash that contains the firmware. This is called "run mode", it's the all days mode for using ESPEasy and the ESP chip.
For flashing the ESP it must be set into "flash mode". Said simply this starts another program, reading the serial port and writing the data into flash memory.
The ESP has four inputs that manage the startup behaviour.
These setting are necessary to flash the chip!
The GPIO15 pin should always be set to "low". Use a 10KOhm resistor between GPIO15 and ground.
GPIO2 should be pulled to "high". Use a 10KOhm resistor between GPIO2 and 3,3V (Vcc).
The GPIO0 setting now decides between run mode and flash mode. Connect a 10 KOhm resistor between 3,3V (Vcc) and GPIO0. This sets the ESP8266 into run mode.
Now you may connect the GPIO0 directly to ground for flashing.
The fourth is the "reset" pin. It should be on "high", so put a 10 KOhm resistor between Vcc and reset pin.
For all ESP's besides nodeMCU and WeMOS there is a "CH-PG" pin. It's an "enable" pin you may use to switch off the whole ESP-Chip. Put a 10KOhm resistor between CH_PG and Vcc to keep the ESP running at all.
Devices with an embedded ESP-Chip (Sonoff basic or 4ch for example) will have these resistors on board. Just GPIO0 has to be set to ground with a jumper bridge or via a pushbutton.
4. Connecting to the computer for flashing
4.1 Get your computer ready
Install the serial monitoring program of your choice. Install the drivers for your UART (USB->TTL) converter.
Plug in the UART and open the device manager. Under the "Ports (COM & LPT)" you will notice an additional COM-Port, usually COM3 or higher.
Note the number, you may need it.
The nodeMCU and the WeMOS use same UART chips. Depending on your board you have to install the CH340G drivers or CP2102 drivers. Identify by reading the marking on the chip near to the USB connector.
4.2. Connecting UART to ESP
Again, those using the nodeMCU or WeMOS D1 mini may skip this paragraph.
Remember the settings mentioned under 3. above. Now it depends a lot on what ESP you use.
The small ESP-01 has some connections already on board (GPIO15) You have to connect GPIO2 and Reset to Vcc and GPIO0 to ground as described above.
If you use the bigger ESP's (ESP07, 07s, 12, 12e, 12f) you have to take care of all connections being properly made.
Note: These ESP's are not very handy to use. If you want to use them an adapter board makes things a lot easier and breadboard friendly. They often have the necessary resistors on board too.
Now connect the UART:
UART ESP Rx Tx Tx Rx Gnd Gnd
Do not switch on the power supply yet!
Connect the power supply to Vcc (3,3V) and Gnd. If using higher voltage power supplies, use a voltage regulator!
Watch out not to swap the leads accidentally - it will kill the ESP.
Double check your cabling! All connections made properly? Check against 3. above. Check it again.
Failures often result from cabling faults.
4.3. Flashing the nodeMCU / WeMOS D1 mini
Just connect an USB cable to your board - that's all. The flashing program will do the rest for you.
Start the flash program from the ESPEasy .zip file.
Select the COM-port you have noted above. In most cases it will show the correct port already.
Select the .bin file you want to flash.
Remember, the file has to reside in the same folder as the flash program.
Now click the "Flash" button.
A black windows (a command console) opens and shows what is going on. Shortly rows of points appear point by point.
BE PATIENT! it takes some seconds until flashing finishes.
As soon as the flash program confirms that it is done you may close it and go back to the monitoring program.
On a fresh ESP it starts clearing some areas of the flash. Wait until it is done.
Reset or power off / on your nodeMCU or WeMOS. It should be ready to use now.
4.4. Flashing other ESP devices
You should have done all connections. Do not power up the ESP now!
Start the flash program from the ESPEasy .zip file.
Select the COM-port you have noted above. In most cases it will show the correct port already.
Select the .bin file you want to flash.
Remember, the file has to reside in the same folder as the flash program.
Now click the "Flash" button.
Power up the ESP as short as possible after hitting the "Flash" button. A switchable outlet for the power supply helps.
A black windows (a command console) opens and shows what is going on. Shortly rows of points appear point by point.
BE PATIENT! it takes some seconds until flashing finishes.
As soon as the flash program confirms that it is done you may close it and go back to the monitoring program.
On a fresh ESP it starts clearing some areas of the flash. Wait until it is done.
Disconnect GPIO0 from ground, the resistor to Vcc should remain. Reset or power off / on your nodeMCU or WeMOS.It should be ready to use now.
5. Where to go from here
If everything has gone right you have a useable ESPEasy device now.
As no parameters are set it will go to "AP mode" for configuration.
Use your computer, tablet or smartphone and search a WiFi network named "ESP-0".
Connect to ESP-0 using the password "configesp" (without "").
Open your internet browser and type 192.168.4.1 as internet address into the browser. The WiFi setup of the ESP opens.
You can choose your WiFi network now. Select the SSID and enter your passphrase, click connect.
It will take 20 seconds until a result is shown. If you typed everything correctly it will show a message that it is connected to the network and it shows the IP address.
Note the IP address!
Conenct your computer or whatever back to your usual network. Open a browser and type the ip address into the browser.
You should see the config pages of ESPEasy now.
6. Troubleshooting
Flashing can go wrong by a lot of reasons. In many cases cabling faults are the reason.
If the flashing program says it can't find the ESP, try to swap the Tx and Rx cables at the ESP. Sadly some manufacturers are not too consequent with naming.....
Didn't help?
Check all of your cabling. All GPIO's set accordingly? Are all cables OK? If you got cheap connector cables they might have some contacting problems. A digital multimeter is a helpfull device for such cases. You might consider to get one for future use. Don't chose the cheapest one.
[To do:
Links, pictures, schematics.
Troubleshooting should be expanded.
Some formatting...]