Connect the board to USB using an Arduino or Serial-to-USB adapter
On the photo I used an Arduino Nano v3 (Chinese version) as a USB to Serial bridge. If you load something into the Arduino that doesn't use the serial pins (such as the blinky sketch) this should work without problem.
A little warning, since the Arduino has 5v on it's serial pins you will need to supply the ESP-01 with 5v also. This is officially NOT supported. For me this has worked without problems for about a week now, but you're warned. ;) Mixing 3.3v and 5v also does not work. I recommend using the USB-to-serial adapters I mentioned in the previous article since you can select the output voltage on it and it can also supply a little bit more power then an Arduino can. With the Arduino on USB as a power source the lights would flicker a lot and serial input could be very spotty (often corrupt) with WiFi also connected. With disconnected WiFi it is manageable though certainly not perfect.
With the adapter it's easy. You just need to connect the right pins together with some dupont cables (See previous post).
Firmware flash mode
To get the ESP-01 in firmware flash mode we will need to connect it in a special way.
![]() |
Schematic overview of the ESP-01. Mind the orientation of the board, this is viewed from the top side |
Normal running mode
The default pins to connect are:
ESP-01 VCC - 3.3v Serial Adapter
ESP-01 GND - Ground or Minus Serial Adapter
ESP-01 RX - Connect to TX on Serial Adapter
ESP-01 TX - Connect to RX on Serial Adapter
ESP-01 CH_PD - 3.3v Serial Adapter
Since two pins need to be connected to 3.3v it's easiest to either use a breadboard with some dupont cables or a screw connector block to multiply the connection.
Since two pins need to be connected to 3.3v it's easiest to either use a breadboard with some dupont cables or a screw connector block to multiply the connection.
This will set the ESP-01 in normal operating mode.
Flash mode
To get into firmware flash mode you need to make two additional connections, easiest is to use a screw connector block or breadboard for this.
ESP-01 GPIO0 - Pull low by connecting to ground / minus
ESP-01 GPIO2 - Pull high by connecting to 3.3v
When you reboot the module it should be in firmware flash mode!
Downloading the software
The next step is to get the software. I am using the NodeMCU firmware with the LUA language to make it all work. There are three sources for this, there is http://www.esp8266.com/ and there is the NodeMCU website http://www.nodemcu.com/.
The third source is directly from Github, this should always contain the most recent version of the firmware and programs. I recommend using this way and I will describe it here.
Go to https://github.com/nodemcu and go to the nodemcu-firmware part. There you click the "Download Zip" button on the right of your screen.
You should end up with a zip file with all the files in it. Extract it. The files we are looking for are located in the \nodemcu-firmware-master\pre_build\0.9.4\512k-flash directory and the file we are going to flash is nodemcu_512k_latest.bin
You should end up with a zip file with all the files in it. Extract it. The files we are looking for are located in the \nodemcu-firmware-master\pre_build\0.9.4\512k-flash directory and the file we are going to flash is nodemcu_512k_latest.bin
Then go back to https://github.com/nodemcu and select nodemcu-flasher and do the same (Download zip). Extract it into a directory and run the program located in the Win64/Release directory.
It should show you window like this:
Next go into the second tab "Config" and use the machine cogwheel button and select the nodemcu_512k_latest.bin
If your ESP-01 is connected correctly and in firmware flash mode it should automatically fill in the MAC addresses when you click flash. The following should take place:
When flashing is successful we can continue.
Sadly, this isn't as easy as it was written here, it should be, but the 3 modules I flashed needed toying and trying again and again for about an hour each to actually get it to go into flash mode. Once it did there was no problem and it flashed just fine, but still it was a bit hard to get it do so sometimes. I still don't know yet why it doesn't always work the first time, it might be because I was using a 5v Arduino.
Sadly, this isn't as easy as it was written here, it should be, but the 3 modules I flashed needed toying and trying again and again for about an hour each to actually get it to go into flash mode. Once it did there was no problem and it flashed just fine, but still it was a bit hard to get it do so sometimes. I still don't know yet why it doesn't always work the first time, it might be because I was using a 5v Arduino.
Once you have managed to get the firmware flashed, disconnect the firmware flashing pins:
ESP-01 GPIO0 - Pull low by connecting to ground
ESP-01 GPIO2 - Pull high by connecting to 3.3v
Installing the QuinLED program on the ESP-01
For sending the programming to the ESP-01 I recommend downloading a tool called ESPlorer, you can download it here. It's a JAVA based tool so you need to install the latest Java version to run it. Sadly Java also has some downsides, when coding for a while inside of ESPlorer it can slow down quite a lot especially when sending the code over serial to the ESP-01. Restarting the program quickly fixes the problem, but it kind of sucks. Hopefully the author of the program is able to fix this!
Having started the program you will be presented with the main interface:
On the top in the right you can select your COM port (check in device manager) and select 9600 as the baud rate. Hit connect and you are connected to the now LUA running ESP-01 over serial.
Here you can issue commands to the ESP-01.
Some useful commands to remember:
- node.restart(); - Restarting the ESP8266
- wifi.setmode(wifi.STATION) - Setting it to WiFi client mode
- wifi.sta.config("SSID","PASSSSS") - Connecting to your WiFi network
- print(wifi.sta.getip()) - Get the IP of the ESP8266
- wifi.sta.connect() - Connect to the set SSID
- wifi.sta.disconnect() - Disconnect wireless
- print("Hello World!") - Print some text
You can paste these commands in the little white box next to send and then execute and select them quickly when you need them.
To install the QuinLED dimming program you need to paste the following in the code window:
This is version 0.4 of my code, it will probably get updated at some point. I also need to add some documentation in the code at some point. :P
pwm.setup(3, 1000, 005)
pwm.setup(4, 1000, 005)
pwm.start(3)
pwm.start(4)
LED1_current=005
LED1_target=005
LED2_current=005
LED2_target=005
Fadetime1=5000
Fadetime2=5000
Stepcounter1=0
PosStepcounter1=0
DimTimer1=0
Stepcounter2=0
PosStepcounter2=0
DimTimer2=0
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASSSS")
srv=net.createServer(net.TCP)
srv:listen(43333,function(conn)
conn:on("receive",function(conn,payload)
print("Input:"..payload)
if string.find(payload,"LED1") then
LED1_target=tonumber(string.sub(payload, 13) )
print("Received LED1 Target Value: "..LED1_target)
Stepcounter1=(LED1_target)-(LED1_current)
if (Stepcounter1) < 0 then
PosStepcounter1=(Stepcounter1)*-1
else PosStepcounter1=(Stepcounter1)
end
if (PosStepcounter1) == 0 then
PosStepcounter1=(PosStepcounter1)+1
else PosStepcounter1=(PosStepcounter1)
end
DimTimer1=(Fadetime1)/(PosStepcounter1)
if (DimTimer1) == 0 then
DimTimer1=(DimTimer1)+1
else DimTimer1=(DimTimer1)
end
print (Fadetime1)
print (Stepcounter1)
print (PosStepcounter1)
print (DimTimer1)
print (LED1_current)
print (LED1_target)
tmr.alarm(0, (DimTimer1), 1, function()
if LED1_current < LED1_target then
LED1_current = (LED1_current + 1)
pwm.setduty(3, LED1_current)
elseif LED1_current > LED1_target then
LED1_current = (LED1_current - 1)
pwm.setduty(3, LED1_current)
elseif LED1_current == LED1_target then tmr.stop(0)
end end )
end
if string.find(payload,"LED2") then
print("Received LED2 Target Value")
LED2_target=tonumber(string.sub(payload, 13) )
Stepcounter2=(LED2_target)-(LED2_current)
if (Stepcounter2) < 0 then
PosStepcounter2=(Stepcounter2)*-1
else PosStepcounter2=(Stepcounter2)
end
if (PosStepcounter2) == 0 then
PosStepcounter2=(PosStepcounter2)+1
else PosStepcounter2=(PosStepcounter2)
end
DimTimer2=(Fadetime2)/(PosStepcounter2)
if (DimTimer2) == 0 then
DimTimer2=(DimTimer2)+1
else DimTimer2=(DimTimer2)
end
print (Fadetime2)
print (Stepcounter2)
print (PosStepcounter2)
print (DimTimer2)
print (LED2_current)
print (LED2_target)
tmr.alarm(1, (DimTimer2), 1, function()
if LED2_current < LED2_target then
LED2_current = (LED2_current + 1)
pwm.setduty(4, LED2_current)
elseif LED2_current > LED2_target then
LED2_current = (LED2_current - 1)
pwm.setduty(4, LED2_current)
elseif LED2_current == LED2_target then tmr.stop(1)
end end )
end
end)
end)
print ("Booted to QuinLED_ESP8266_V0.4")
Be sure to change the SSID and Passcode to what you use in your own network.
When you have it pasted in ESplorer press the "Save to ESP" button to transfer it over. It will ask you for a filename and where to store it. The where is only a local place what the file will also be kept, the filename is important and I recommend you name it "init.lua". That way it will automatically run when the ESP-01 boots.
The tool should now be pasting the code to the ESP-01 line per line and checking if it made it across intact. I sometimes have that the code will arrive corrupt and the tool will error. When that happens I recommend you give the ESP-01 a restart and then a WiFi disconnect command. Doing that always makes the ESP-01 much more stable for me and transferring the program shouldn't be a problem.
Once the ESP-01 is programmed it might complain that it can't start a second TCP server (it depends on what you where running or if you had some fail flashes). Just give the unit a reset.
Once it's booted again you can use the above mentioned commands to ask for it's IP. You should be able to ping that IP. Don't be alarmed by it's 'not so great' ping times, this is normal.
When you have it pasted in ESplorer press the "Save to ESP" button to transfer it over. It will ask you for a filename and where to store it. The where is only a local place what the file will also be kept, the filename is important and I recommend you name it "init.lua". That way it will automatically run when the ESP-01 boots.
The tool should now be pasting the code to the ESP-01 line per line and checking if it made it across intact. I sometimes have that the code will arrive corrupt and the tool will error. When that happens I recommend you give the ESP-01 a restart and then a WiFi disconnect command. Doing that always makes the ESP-01 much more stable for me and transferring the program shouldn't be a problem.
Once the ESP-01 is programmed it might complain that it can't start a second TCP server (it depends on what you where running or if you had some fail flashes). Just give the unit a reset.
Once it's booted again you can use the above mentioned commands to ask for it's IP. You should be able to ping that IP. Don't be alarmed by it's 'not so great' ping times, this is normal.
Issuing commands to the ESP-01 running QuinLED
Now that our unit is running the QuinLED program you should be able to send commands to it. If you still have a serial connection open it will post some logging about this too.
For sending the commands to the ESP-01 you can either use a putty session in RAW mode to open the TCP port (43333) and type in or paste your command or use a little tool called "netcat". It is available on most Linux distributions or you can get it in cygwin when running Windows.
To send a command to LED1 you type:
echo LED1_target=1000 | nc ip.ip.ip.ip 43333
That should said GPIO0 to a duty cycle of 1000. A duty cycle can be anything in the range of 0 to 1023. Do not use a number higher then that because right now the program will crash. ;) It's no use anyway because the ESP8266 supports 1024 PWM duty cycle levels so 1023 is fully open.
And that should be it, you can now control both channels of the ESP-01 connected to your LED strip. In my next post I will explain how you can hook this up into Domoticz and give it control over both channels independently.
And that should be it, you can now control both channels of the ESP-01 connected to your LED strip. In my next post I will explain how you can hook this up into Domoticz and give it control over both channels independently.
Congratulations with a very well written blog post, explained in good detail!
ReplyDeleteThere is a small typo just after the Lua code. It should not say "Send to ESP", but "Save to ESP".
Thank You for your great guide !
ReplyDeleteI do have a problem though, instead of a led strip i use as a load a led street lamp that has 40 leds of 1W and is driven with a 30Vcc led driver.
My issue is that the leds never stay full on, they basically blink all the time, which is annoying.
Regardless of the duty cycle, i can see the code dimms the light but the leds are always blinking, coul dit be that the MOSFET can't sustain the gate open and cycles from closed to open ?
Any ideas ?
When I have noticed this it was because the power supply was constant current and not constant voltage. Because of that the power supply keeps trying to adjust constantly in the range it can, but because of the PWM it becomes confused.
DeleteBest is to measure the voltage at full power, get a power supply to match that power supply, add in my board and then use PWM. I'm doing that with several LED lamps too and it works perfectly.
This comment has been removed by the author.
ReplyDeleteThank you for your work! I have everything turned on, tune in, works.
ReplyDeleteGood to hear, enjoy!
DeleteHi,
ReplyDeleteI have problem with upgrading firmware. Nothing fill-in when I press FLASH
Hi I get the following error while trying to send the command : echo LED1_target=1000 | nc ip.ip.ip.ip 43333 to the dimmer :
ReplyDeletestdin:2: '=' expected near 'LED1_target'
I can't figure out why tis is happening, please help me
No clue, are you using esplorer to upload the code to your ESP? Also please use the code and nc line from the newer post.
DeleteI am looking for Arduino IDE equivalent of the code, as for some reason, 2 of my ESP-01 chips refuse to run nodemcu, while running fine Arduino IDE programs.
ReplyDeleteNo clue, I have not had that problem before. I have had ESP's which I re-used a few times and became less stable, but that's a whole different problem.
DeleteThenk you vey much!!! I was stucked flash my ESP01 until you show me that GPIO02 should be VCC.
ReplyDeleteSocat does not hang like nc, I recommend sending the brightness like this:
ReplyDeleteecho LED1_target=500 | socat - TCP:ip.ip.ip.ip:43333
Awesome project! I got my first one up and running today, including learing how to flash LUA on the esp8266.
I'll give that a try, thnx! :D
DeleteI'll give that a try, thnx! :D
DeleteThere are 3 adjacent LEDs on my strip that randomly flash at different brightness levels when I set the brightness to 1023. At 1022 and below they act normal.
ReplyDeleteThat's odd, that would mean this would also happen is no dimmer is attached? Value 1023 is MAX open, no dimming applied.
DeleteThat's odd, that would mean this would also happen is no dimmer is attached? Value 1023 is MAX open, no dimming applied.
Deletehii.. i am getting " waiting answer from ESP - Timout reached. Send aborted "
ReplyDeletewhat should i do ?
Not sure what is going wrong there. Try hooking everything up again and see if it works then?
DeleteNot sure what is going wrong there. Try hooking everything up again and see if it works then?
DeleteI like your theme of choice for web journal however need to recommend you for sharing some more data with respect to your subject so we can comprehend your idea all the more unmistakably. wp plugins
ReplyDeleteWonderful directory ideas that can help to boost our own web site creating, after i creating web site I will recall these points as well as help make some really good creating.ios 7 app design
ReplyDelete