Difference between revisions of "ESP8266"
(first layout of the 'big' ESPage) |
(added program methods) |
||
Line 11: | Line 11: | ||
=== hardware: using the [[ESP^2]] === | === hardware: using the [[ESP^2]] === | ||
− | + | :NOTE: the used serial connection is 5v (but has some resistors), which is officially not supported | |
+ | :NOTE2: currently, there is only an 8-pin header for the ESP-01 | ||
+ | * before connecting the ESP^2, plug in the ESP-01 (note the markings) | ||
+ | * flip the switch to program mode | ||
+ | * plug in the USB cable | ||
+ | * restore the switch | ||
+ | * upload using your favorite software method | ||
=== hardware: using an FTDI cable === | === hardware: using an FTDI cable === | ||
− | + | NOTE: some people state that you can connect GPIO0 to DTR and REST to RTS, but the current settings in Arduino don't support this properly (might be a configuration thing) This would enable automatic program mode for the ESP | |
+ | |||
+ | Make sure your FTDI cable can do 3.3V! | ||
+ | |||
+ | * connect CH_PD and VCC to 3.3V (use an external power supply as most FTDI cables are not capable of supplying the required amouunt of current | ||
+ | * connect GPIO0 (program) via a momentary switch to GND | ||
+ | * connect REST (reset), if available via a momentary switch to GND (or do a power cycle if you want to start the bootloader mode | ||
+ | * and GPIO15 (if available) via a 10k resistor all to GND | ||
+ | * press both reset (or cut power) and program | ||
+ | * release reset (or restore power) | ||
+ | * release program | ||
+ | * upload using your favorite software method | ||
=== software: using Arduino 1.6.4 === | === software: using Arduino 1.6.4 === | ||
Line 31: | Line 48: | ||
* You can now upload your sketch | * You can now upload your sketch | ||
− | === software: using esptool.py to upload | + | NOTE: currently, programming the ESP-12E will result in corrupted firmware with all kinds of strange behaviour. This is caused by the esptool that comes with the Arduino ESP8266 package. |
+ | |||
+ | There are two ways to circumvent this: | ||
+ | # Manual upload: In Arduino, click file, preferences and check verbose [ ]upload | ||
+ | :upload without putting the ESP in bootloader mode so you don't waste any (corrupt) write cycles | ||
+ | :note the location of the .bin file and use the [[ESP8266#software: using esptool.py to upload binaries|esptool]] method | ||
+ | # add a better working esptool.py in Arduino (which is what [[User:Xopr|xopr]] did) by changing some files within the ESP8266 package | ||
+ | :download '''[https://raw.githubusercontent.com/themadinventor/esptool/master/esptool.py esptool.py]''' and put it in '''~/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-939-g033463a/tools/''' | ||
+ | :edit '''~/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-939-g033463a/boards.txt''' and after | ||
+ | :''generic.menu.UploadTool.espota.upload.tool=espota'' | ||
+ | :add | ||
+ | :'''generic.menu.UploadTool.esptoolpy=Serial (python)''' | ||
+ | :'''generic.menu.UploadTool.esptoolpy.upload.tool=esptoolpy''' | ||
+ | :edit '''~/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-939-g033463a/platform.txt''' and at the bottom, add | ||
+ | :'''tools.esptoolpy.cmd=python''' | ||
+ | :'''tools.esptoolpy.cmd.windows=python.exe''' | ||
+ | :'''tools.esptoolpy.path={runtime.platform.path}/tools''' | ||
+ | :'''tools.esptoolpy.upload.protocol=esptoolpy''' | ||
+ | :'''tools.esptoolpy.upload.params.verbose=''' | ||
+ | :'''tools.esptoolpy.upload.params.quiet=''' | ||
+ | :'''tools.esptoolpy.upload.pattern="{cmd}" "{path}/esptool.py" --baud {upload.speed} --port "{serial.port}" write_flash 0x00000 "{build.path}/{build.project_name}''' | ||
+ | :Now, in Arduino, you have an extra menu option under 'Tools', 'Upload using', 'Serial (python)' | ||
+ | |||
+ | === software: using esptool.py to upload binaries === | ||
− | + | * Make sure you have a binary (for example, [http://bbs.nodemcu.com/t/nodemcu-firmware-download-build-20150318-new-location/27 download NodeMCU here] or do a search for ''"site:http://bbs.nodemcu.com nodemcu firmware"'' | |
+ | * Download [https://raw.githubusercontent.com/themadinventor/esptool/master/esptool.py esptool.py] (and make sure you have python on your system | ||
+ | * Upload using something that says: | ||
+ | :sudo ./esptool.py --port /dev/ttyUSB0 write_flash 0x00000 ../nodemcu_float_0.9.6-dev_20150704.bin | ||
==== loading scripts from a webserver ==== | ==== loading scripts from a webserver ==== |
Revision as of 22:07, 23 July 2015
programming the ESP8266
hardware: using the ESP^2
- NOTE: the used serial connection is 5v (but has some resistors), which is officially not supported
- NOTE2: currently, there is only an 8-pin header for the ESP-01
- before connecting the ESP^2, plug in the ESP-01 (note the markings)
- flip the switch to program mode
- plug in the USB cable
- restore the switch
- upload using your favorite software method
hardware: using an FTDI cable
NOTE: some people state that you can connect GPIO0 to DTR and REST to RTS, but the current settings in Arduino don't support this properly (might be a configuration thing) This would enable automatic program mode for the ESP
Make sure your FTDI cable can do 3.3V!
- connect CH_PD and VCC to 3.3V (use an external power supply as most FTDI cables are not capable of supplying the required amouunt of current
- connect GPIO0 (program) via a momentary switch to GND
- connect REST (reset), if available via a momentary switch to GND (or do a power cycle if you want to start the bootloader mode
- and GPIO15 (if available) via a 10k resistor all to GND
- press both reset (or cut power) and program
- release reset (or restore power)
- release program
- upload using your favorite software method
software: using Arduino 1.6.4
Taken from https://github.com/esp8266/arduino
- Install Arduino 1.6.4 from the Arduino website.
- Start Arduino and open Perferences window.
- Enter http://arduino.esp8266.com/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
- Open Boards Manager from Tools > Board menu and install ESP8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).
- For the ESP^2, the device name (under Linux) is /dev/ttyACM3
- Change the programmer from AVRISP mkII to ArduinoISP
- poweroff ESP (either unplug the USB or pull the device from the socket
- set the switch to prog
- poweron the ESP
- You can now upload your sketch
NOTE: currently, programming the ESP-12E will result in corrupted firmware with all kinds of strange behaviour. This is caused by the esptool that comes with the Arduino ESP8266 package.
There are two ways to circumvent this:
- Manual upload: In Arduino, click file, preferences and check verbose [ ]upload
- upload without putting the ESP in bootloader mode so you don't waste any (corrupt) write cycles
- note the location of the .bin file and use the esptool method
- add a better working esptool.py in Arduino (which is what xopr did) by changing some files within the ESP8266 package
- download esptool.py and put it in ~/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-939-g033463a/tools/
- edit ~/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-939-g033463a/boards.txt and after
- generic.menu.UploadTool.espota.upload.tool=espota
- add
- generic.menu.UploadTool.esptoolpy=Serial (python)
- generic.menu.UploadTool.esptoolpy.upload.tool=esptoolpy
- edit ~/.arduino15/packages/esp8266/hardware/esp8266/1.6.5-939-g033463a/platform.txt and at the bottom, add
- tools.esptoolpy.cmd=python
- tools.esptoolpy.cmd.windows=python.exe
- tools.esptoolpy.path={runtime.platform.path}/tools
- tools.esptoolpy.upload.protocol=esptoolpy
- tools.esptoolpy.upload.params.verbose=
- tools.esptoolpy.upload.params.quiet=
- tools.esptoolpy.upload.pattern="{cmd}" "{path}/esptool.py" --baud {upload.speed} --port "{serial.port}" write_flash 0x00000 "{build.path}/{build.project_name}
- Now, in Arduino, you have an extra menu option under 'Tools', 'Upload using', 'Serial (python)'
software: using esptool.py to upload binaries
- Make sure you have a binary (for example, download NodeMCU here or do a search for "site:http://bbs.nodemcu.com nodemcu firmware"
- Download esptool.py (and make sure you have python on your system
- Upload using something that says:
- sudo ./esptool.py --port /dev/ttyUSB0 write_flash 0x00000 ../nodemcu_float_0.9.6-dev_20150704.bin
loading scripts from a webserver
I (Da Syntax) got tired from typing the scripts line for line into the lua console of the nodeMCU firmware. I wrote a little function to load the scripts from a webserver running on my laptop. This way I can just save the script on my laptop and load it to my ESP8266 calling 2 functions ( netload() and dofile("netloaded.lua") )
function netload() conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) file.open("netloaded.lua", "w") file.write(payload) file.close() end) conn:connect(8080,"192.168.1.193") conn:send("GET /test.lua HTTP/1.1\r\nHost: www.example.com\r\n" .."Connection: keep-alive\r\nAccept: */*\r\n\r\n") end
Future plans
- Send mac address of the wifi module in get so the web server can return device specific firmwares
- Put the script between specific tags so there won't be any problems with headers that are added by the web server + gives the possibility to add meta data (e.g. version of script or a signature)
- Create a nice php/mysql webapp to easily manage the scripts per module
sample projects
Here are some sample projects
Webserver serving JSON (Arduino)
This arduino sketch provides a webserver-like interface and provides a json file (somewhat compatible with SpaceAPI) There is a version running in the space in a 'hot' zone, and accessible on http://192.168.1.132
You can find the code here
SpaceAPI (Arduino)
The new SpaceAPI is a combination of some PHP, MySQL, and some ESP modules updating the space state and sensor data. The ESP sketch sketch will have several features like space state switch, indicator, Dallas temperature and other sensors, which can be enabled compile-time.
SpaceState (Arduino)
This Arduino sketch is a web client and will update the SpaceState
You can find the code here