Introduction: Blink for ESP8266 Native, Like Arduino Using Windows
When I bougth the ESP8266, my first thought was to use ESP8266 as a Wifi shield for Arduino. I found out that the ESP8266 is a powerfull device by it self. And I asked myself. Why not use this device without using an arduino. This cheap (3 US$) device is more powerfull than an Arduino UNO, got more memory (4000Kb versus 32Kb), higher clock speed (80Mhz versus vs 16Mhz) and 9 GPIO pins in version ESP-12
This instructables is for everyone that is using an Arduino and would like to go for the next level by using the ESP8266 native, without an Arduino. We are going to develop direct on te ESP8266.
So let's give its a try.
Shopping list
1) ESP8266 ( I have bought a the version ESP-12, there are several versions,
Any will do ESP-01 is the most common)) for example on aliexpress
2) USB to TTL with 3.3 volt output. (or you can use your Arduino UNO) for example on aliexpress
3) a led
4) a resistor 1K
Disclaimer
Be aware that developing for ESP8266 isn't as easy as developing for Arduino. The ESP8266 is since autumn 2014 on the market. The SDK has not achieved the 1.00 version. (at writing, the latest version is. v0.9.5). This device is using the powersource of 3.3Volt and can be damaged quite easily. Having this said, a lot of sites talks about this but on my on experience I have not seen any smoke yet. Most of the examples found on the web are created by guru's using Linux (ubuntu). I assume most of the Arduino users uses Windows, like I do.
My personal goal for this Instructable is to share all my pitfalls so that you would not have the same issues.
I will go from unboxing until the end. You may skip some steps.
Step 1 Hardware setup
Step 2 Upload the latest firmware.
Step 3 Install development environment (this is the hard part)
Step 4 Compile blink
Step 5 Upload blink
Step 6 Wiring the led
Step 7 Pitfalls & httpd
Step 1: Hardware Setup & Serial Communication
If you made already a terminal connection than you can skip this step.
USB TTL <--> ESP8266 ESP-01
VCC -- VCC
GND -- GND
TX -- RX
RX -- TX
VCC -- CH_PD
This is wiring in normal (operational) mode.
When you connect your USB cable to the computer, a new com port will be available in a terminal emulator.
I prefer to use the serial monitor in the Arduino environment.
Open the arduino environment and select the com port from your USB TTL, In my case this is COM10
Open the serial monitor from the tools menu and set the communication to 115200 baud. Don't forget to set the key emulation to "Both NL & CR".
Try to send the following command: AT+RST
It will reset your ESP8266 and send some info back to serial monitor.
If this doen't work, do not go to the next step.
If you have seen any response, but unreadable. This can be correct. After a reset, the ESP6288 sends information with a strange baudrate, ignore that. If it doesn't react the command AT+RST it could be that you have to switch to baudrate 9600 or check the cables.
Don't forget that your TX should be connected to RX and RX should be connected to TX.
Step 2: Upload Latest Firmware & SDK
The ESP6288 is new on the market since autumn 2014 with a couple of new versions of the firmware.
Actually the latest version is still a sort of beta version version (0.9.5.). But don't worry it is stable.
The latest esp_iot_sdk_v0.9.5_15_01_23 can be downloaded from bbs.espressif.com
If you have this version already on your ESP8266, just skip this step. Extract the zipfile (for example to c:\projects\ESP8266\)
First I struggled with uploading software to ESP8288. All the examples are using command examples using phyton. fortunately I found a good alternative. There is an easy solution available for Windows OS named ESPflasher from NodeMCU. The goal for those guys is to upload NodeMCU as an alternative firmware. But it works also very good for uploading standard firmware and our blink 'sketch'.
Just download it from here https://github.com/nodemcu/nodemcu-flasher . Github will download everything to one zip file. I use only ESP8266Flasher.exe from it. Nothing else.
run ESP8266Flasher.exe and select the second tab "Config"
Select from the esp_iot_sdk_v0.9.5 directory 4 files, and change the offset
c:\projects\ESP8266\esp_iot_sdk_v0.9.5\bin\boot_v1.2.bin 0x00000
c:\projects\ESP8266\esp_iot_sdk_v0.9.5\bin\at\user1.512.new.bin 0x01000
c:\projects\ESP8266\esp_iot_sdk_v0.9.5\bin\blank.bin 0x3e000
c:\projects\ESP8266\esp_iot_sdk_v0.9.5\bin\blank.bin 0x7e000
Yes you are right! The blank.bin will be uploaded twice.
Select in the Operation tab the your COM port, (In my example it is COM10).
Do not press flash yet!
Connect GPIO_0 to GND with a wire (or even better, with a resistor).
Reset the device. The device is now in flash mode.
Press the button flash in ESPFlasher and wait until its ready.
Remove the wire from GPIO_0 to GND. And reset the device.
That's it for firmware, let's check!
We are on version 0.9.5. Now, so for sure we should set the baudrate to 115200
Open again the serial monitor (in Arduino) and reset the device.
You will see on the first line some crazy tekst. Don't worry, this is normal. As long as it end with the text "ready".
Send the command AT+GMR and you will have the response:
AT+GMR
AT version:0.21.0.0
SDK version:0.9.5
OK
As you can see, we are on version 0.9.5
Step 3: Setup Toolchain in Windows (the Hardpart)
Let's hope the previous steps were considered as easy.
This will be the hard part.
In Arduino we just press the button "Verify" and the compiler does his work.
Sorry for that. This is not the case for ESP8266. And certainly not for a computer running on windows.
First we have to download the compiler.
The compiler is named xtensa-lx106-elf-141114.7z and can be downloaded from https://drive.google.com/folderview?id=0BzWyTGWIwcYQendHbWlsNUZpX0E&usp=drive_web#list here. It is from a guy named mobyfab. 7z is a zipped file. I used WinZip to extract. Extract this to the directory xtensa-lx106-elf. I use c:\projects\ESP8266\xtensa-lx106-elf for this. (it is compiled for a 64 bit computer, I assume you are running a 64 bit)
Each example has several steps, like building and compiling. Each program has its own script for that. this is called a Makefile. You will find the makefiles in almost every directory Under Linux it is standard peace of software. For Windows we have to install make.exe first.
Download the installer from here https://www.cygwin.com
I have installed, the installer in c:\cygwin\
Run setup-x86.exe and select "make"
Press next until you see the screen select packages. fill in the field "Search" the word "make". (see screenshot)
Expand Devel and select the second last called "Make: The GNU version of the 'make' utility".
It is possible to switch between different versions. (Use the version 4.0-2 the version 4.1-1 could result in a dll error.)
Press next until you are finished.
In other toolchain examples they pointed out to have python. I think it is not needed.
Download esptool.exe, you may find a copy here: https://github.com/JeroenBeemster/ESP8266-Blink
copy this file to c:\cygwin\bin (or the place where you have installed cygwin). A path to this directory has been made by installing cygwin. So we (mis)use this :)
Step 4: Make Blink (compile the Example)
Download the example from github
https://github.com/JeroenBeemster/ESP8266-Blink
Open the file Makefile. (I use Notepad++ for this)
Change the following lines:
XTENSA_TOOLS_ROOT ?= C:/projects/esp8266/xtensa-lx106-elf/bin
SDK_BASE ?= C:/Projects/ESP8266/esp_iot_sdk_v0.9.5
Change these two lines to the place where you have saved the elf-compiler and the SDK in step 3 and 2.
Be aware that the forwardslash (/) must be a forward slash. A a backslash (\) will not work.
Run ESPMake.bat
This batch run's Make.exe that will execute the commands in the Makefile.
Two new directories will be created. These directories are "build" and "firmware".
You may remove these directories, For example, if you would like to re-compile the solution again.
If the following 2 files are created, we have achieved this step.
firmware\0x00000.bin
firmware\0x40000.bin
This is a milestone. If we are here, the next step are easy.
Step 5: Upload the Program to ESP8266
Select the files in the sub-directory \firmware
run ESP8266Flasher.exe and select the second tab "Config"
Select from the firmware directory 2 files, and change the offset
firmware\0x00000.bin
firmware\0x40000.bin
Select in the Operation tab the your COM port, (In my example it is COM10).
Do not press flash yet!
Connect GPIO_0 to GND with a wire (or even better, with a resistor).
Reset the device. The device is now in flash mode.
Press the button flash in ESPFlasher and wait until its ready.
Remove the wire from GPIO_0 to GND. And reset the device.
As you can see these are the same steps as uploading the firmware.
BTW it is not possible to send AT commands to your ESP8266. If you would like to restore to factory settings. Just redo step-2
Step 6: Wiring the Led
Connect the led to GPIO-2 with a resistor (I used 1K resistor).
Connect the resistor to ground.
Connect ESP8266 to a powersource. I use the TTL as the powersource.
There are a lot of information on the internet that warns you to use a powersource that can not deliver enough power. Until now I have not found any problems with this. May be I am just lucky.
Let's hope you are also.
Your led should blink now. We have achieved the goal.
Step 7: Pitfalls / Httpd
1) makefile
Only use forwardslash, never use backslach in makefiles
c:\projects\esp8266 doesn't work
c:/project/esp8266 does.
2) when there is a "find" command in makefile, be aware there is also a windows command named find.
solution is quite simple, add the full path:
change: find
into: c:\cygwin\bin\find
3) I have used cygwin86.exe. It seems that some computers only run on cygwinx86.exe
This file has to be in the bin directory.
4) Example httpd
When you download httpd from github got a library in a subdirectory httpd\lib\heatshrink\ that seems to be empty. Go back to github and download this separate.
5) Example httpd
Trying to compile mkespfsimage c:\cygwin has to be added with the following cgg compiler.
57 Comments
6 years ago
Thanks for this tutorial! I have a question. Why this first example (blink) is creating an access point in ESP8266? Is it expected?
7 years ago
Can I use the ESP8266 SDK API on TI TM4C123G LaunchPad, and using it to communicate with esp8266 over UART?
7 years ago
Hi, Running this command
C:\projects\ESP8266\Blink>make.exe
AR build/blink_app.a
LD build/blink.out
C:/projects/ESP8266/esp_iot_sdk_v0.9.5/lib\libmain
dt_init':
(.irom0.text+0x3a8): undefined reference to `user_
C:/projects/ESP8266/esp_iot_sdk_v0.9.5/lib\libmain
dt_init':
(.irom0.text+0x527): undefined reference to `user_
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:114: build/blink.out] Error 1.
Besides that error why i'm not getting CC user/user_main.c.
Could you please clarify.
7 years ago
Hi, Running this command
C:\projects\ESP8266\Blink>make.exe
AR build/blink_app.a
LD build/blink.out
C:/projects/ESP8266/esp_iot_sdk_v0.9.5/lib\libmain
dt_init':
(.irom0.text+0x3a8): undefined reference to `user_
C:/projects/ESP8266/esp_iot_sdk_v0.9.5/lib\libmain
dt_init':
(.irom0.text+0x527): undefined reference to `user_
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:114: build/blink.out] Error 1.
Besides that error why i'm not getting CC user/user_main.c.
Could you please clarify.
7 years ago
So far everything has worked very good but when I run makefile.bat this is what I get.
When I downloaded gcc make the only choice was 4.1.1 or 4.2.0. I chose 4.2.0. I am
using win 10 with the latest updates. I hope there is something you can tell me to fix
this. I am as far as I know hot to go. Thanks Dave
C:\projects\ESP8266\ESP8266-Blink-master\ESP8266-Blink-master>make.exe
3 [main] make 8424 child_info_fork::abort: C:\cygwin\bin\cygcrypt-0.dll: Loaded to different address: parent(0x67700000) != child(0x190000)
make: fork: Resource temporarily unavailable
C:\projects\ESP8266\ESP8266-Blink-master\ESP8266-Blink-master>pause
Press any key to continue . . .
7 years ago
Hi
i am beginner to programming. Encounter an issue while following the steps.
i done flashing the firmware(step 2) and the log said that everything is successful but i could not send command to it anymore.
When i send AT+RST or anything, no reply. it works before i upload the firmware.
it still allow me to reupload the firmware but that is no changes.
i tried upload with resistor and without. still no changes.
7 years ago
I am using Windows 8.1. In the step 4, It is failing to create the .bin files at the end. I tried executing the ESPtool.exe. It is giving incompatiability error.
Any idea if we have a 64 bit version of this ESPtool.exe somewhere ?
7 years ago
Hi
Could u please help how to interface esp8266 and arduino codes
Programming tool ::arduino
Os:::windows 8
Reply 7 years ago
If you planing on use Arduino IDE to program your ESP8266, you should give esp8266/Arduino a look
for native development on windows I recommend Unofficial Development Kit for Espressif ESP8266
8 years ago
Hi,
Thank you for your tutorial.
I followed every step discussed above however I get the following error:
C:\projects\Example File\ESP8266-Blink-master>make.exe
CC user/user_main.c
C:/projects/ESP8266/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc:
66/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc: cannot execute bi
Makefile:142: recipe for target 'build/user/user_main.o' failed
make: *** [build/user/user_main.o] Error 126
C:\projects\Example File\ESP8266-Blink-master>pause
Press any key to continue . . .
8 years ago
Hi ,
Good steps and helpfull to discover about ESP8266,One thing i need to clarify after i installing the software and runs the command prompt,the command prompt says,
C:\Projects\esp8266\ESP8266-Blink-master>make.exe
'make.exe' is not recognized as an internal or external command,
operable program or batch file.
Thank you...
8 years ago
Hi Thanks for awesome tutorial,
I came along all the way till compiling step,
the batch file can not find make.exe
'make.exe' is not recognized as an internal or external command,
operable program or batch file.
How can I solve this issue?
Reply 8 years ago
Just add c:\cygwin\bin to PATH, from Advanced System Settings -> Environment Variables.
Reply 8 years ago
AmeenN thanks for reply now I have another problem running batch file
c:\ESP8266\ESP8266-Blink-master>make.exe
CC user/user_main.c
AR build/blink_app.a
LD build/blink.out
FW firmware/0x00000.bin
Makefile:105: recipe for target 'firmware/0x00000.bin' failed
make: *** [firmware/0x00000.bin] Error 127
please help
Reply 8 years ago
I expect that you have installed 64bit version of cygwin, if that's the case just remove it and install 32 bit version even if your Windows version is 64.
8 years ago
Thanks for this demo. Is there a way to view the debugging messages in the source code (i.e. the calls to os_printf)? Which GPIO pin would these be transmitted on?
I'll reiterate what has been said below - you MUST use the 32-bit version of Cygwin (setup-x86.exe). The x64 version causes a compilation error - "Makefile:105: recipe for target 'firmware/0x00000.bin' failed".
Reply 8 years ago
Never mind - I just realised these messages are being transmitted on the normal TX pin. For some reason I thought debugging had to happen on a different pin than flashing!
8 years ago on Introduction
Great tutorial. Two points to make - the NodeMCU flasher tool isn't very clear about what it will download - on the Config screen, there's a TINY little check-box on each line that needs to be checked for each firmware file. That's why folks are having 'Fatal Exception' problems, because by default only the first line is checked (0x00000). There's also a hint in the status area at the bottom of the screen - it shows the address and size of the currently loading file, which should match the size of the firmware file on disk.
Also, I found that I had to disconnect the LED to reboot the ESP8266 - and then connect it once the chip was up and running (garbage in the serial monitor and no flashing LED). Checking the datasheet, I noticed that the max drive current for a GPIO pin is 12mA. Normally these MCUs can sink more current than they can source, so I suggest changing the LED to active low - in other words, connect the LED/resistor combination between VCC and the GPIO pin, not between GPIO and GND. Now it works perfectly.
Fyi I'm using a red LED with a 330-ohm resistor.
8 years ago on Introduction
i followed the tutorial and got through all the steps with minimum dificulty. The problem is that when im done with flashing the blink example [step5] the led does not blink. Any idea why?
8 years ago on Introduction
I followed the tutorial step by step and it all seems ok, build ends with no error. But when I remove flash mode jumper and reset my device I get this on serial port (at 74600) :
Fatal exception (0):
epc1=0x4024058c, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x0
Any idea ?