I’m not going to go too deeply into the specific hardware I used for my own project, but instead just give a couple of tips on using the Yellow board as a base for your own creations. First of all there’s that row of red LEDs. While they make for a neat “running light” display, there aren’t that many projects (ESP-based VU meter, anyone?) where they’d be truly useful. In addition to sucking the life out of your battery, they can also interfere with some peripheral connections by providing a pull-up path on the GPIO pins (the single RGB LED is a common-cathode device, by the way, so those GPIOs are pulled down). Sometimes the red LEDs are beneficial; for instance, I2C requires pull-ups and the LEDs also handily show activity on the bus, which can be an aid to troubleshooting. However, in general, we don’t want them there, especially on a battery-powered projects. I usually disable the red LEDs by removing the 470Ω current limiting resistors with a hot iron (why the resistors? …because I don’t have to try and figure out the correct polarity when replacing them, if I want to re-enable any of the LEDs).
If you’re mounting the Yellow board in an enclosure of some sort, you may want to desolder the RGB LED and mount in the lid,so it can be seen externally. Be warned, because of the four leads (with the one which is the common cathode soldered to ground), this is a bit of a beast to remove, but it can be done with a big enough iron and some patience. If you are mounting the LED to the lid, it makes sense to add a momentary switch across the boot/program select jumper (GPIO0) and mount it in the lid, too. That will give you access to all of the Sonoff switch functionality built into TASMOTA.
Whichever way you’re powering the Yellow board, from batteries or a mains adapter of some sort, it never hurts to add a nice chunky electrolytic capacitor on the 3v3 supply line (I generally use a 470µF). The existing SMD capacitor close to the edge of the board by the boot/program select jumper has the pads oriented just right to allow the leads of the electrolytic to be soldered on, with the body of the capacitor hanging over the edge of the PCB. A 5v supply from something like a phone charger works well with the Holtek regulator on the Yellow board (which has rather a low maximum input voltage rating, compared with some of the more commonly available 3v3 regulators).
Using the configuration information from the previous article as a guide, you can now connect up the Yellow board GPIOs to the devices you need for your project. The important ones for TASMOTA compatibility are:-
- GPIO0 – Button1
- GPIO12 – Relay1
- GPIO13 – LED1 (the Sonoff basic uses “LED1i”)
In my particular application, GPIO13 (LED1) is connected to the green anode of the RGB LED and I also have three additional connections:-
- GPIO5 – DS18x20 (two DS18B20 temperature sensors)
- GPIO14 – PWM1 (the blue anode of the RGB LED)
- GPIO15 – PWM2 (the red anode of the RGB LED)
With the current version of TASMOTA (5.11.1), the one-wire bus for DS18x20 sensors is limited to a single GPIO. You can have multiple sensors on that GPIO, but you can’t have (for instance) one DS18B20 on GPIO4 and another on GPIO5; only one of them will show up. If you want to have more than one sensor on your one-wire bus, you should use Theo’s specially crafted sonoff-ds18x20 binary (or define USE_DS18x20 in the user_config.h file when building your own).
The “PWM” designations for GPIO14 and GPIO15 allow us to control the brightness of the LEDs attached to those pins. We could just as easily have assigned them as “LED2” and “LED3” to use simple on/off switching, instead.
Now, to test the operation of our newly updated ESP8266, we have basically three options:-
- The serial port on the ESP itself.
- The web server provided by TASMOTA
- MQTT
DO NOT use the serial port method with a mains-powered project unless you remove external power and use the serial adapter to provide DC to the ESP. I’d recommend that you program the ESP with the serial adapter before fitting it to any mains-powered project and from that point onwards limit yourself to OTA upgrades and using the Web and MQTT methods for configuration and testing. Note that using a serial adapter generally doesn’t supply enough current to reliably drive multiple LEDs and a relay, so I wouldn’t recommend this method, anyway.
For either of the remaining methods, the essential reference guide is the “Commands” page of the Sonoff-TASMOTA wiki. You should keep that guide open in your browser while you experiment.
The “console” option of the web interface provides a very versatile method of monitoring output, as well as enabling input and, together with the previously discussed configuration menus, is pretty much all you need to get your ESP project up and running. You can input commands by selecting “Console” from the main TASMOTA menu and typing them into the input box displayed at the bottom of the screen. The results will be displayed in the main console window.
In the above example (click image for full-size version), you can see that the console was displaying occasional status messages until (at 23:56) I entered the commands:-
- ledpower
- ledpower on
- ledpower off
- ledpower
…to check the current status of the green LED (LED1), then turn the green LED on, turn it off again and finally check the status to verify that it was off (note that the final “ledpower” command was entirely spurious, as the device had already echoed an “MQT” status message in the main console window to indicate that the LED was “OFF”).
The commands to control the relay are similar. We simply replace the “ledpower” with just “power”. Typing in “power” on its own will return the current status, while “power on” and “power off” do exactly what you’d expect and also return a confirmation message, just as the “ledpower” command did.
Controlling the PWM drive to the red and blue LEDs is only very slightly more complicated. Entering “pwm” gives us the status (of both PWM1 and PWM2), while entering “pwm1” or “pwm2” followed by a numeric value between 0 and 1023 will produce an output brightness in proportion to the value entered (and, as before, the console will show a message confirming that the action has been completed).
00:24:15 CMD: pwm
00:24:15 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":0,"PWM2":0}}
00:24:21 CMD: pwm1 350
00:24:21 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":350,"PWM2":0}}
00:24:35 CMD: pwm2 799
00:24:35 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":350,"PWM2":799}}
00:24:38 CMD: pwm
00:24:38 MQT: stat/Plug1/RESULT = {"PWM":{"PWM1":350,"PWM2":799}
Reading the one-wire sensors is even easier still. As long as there are no hardware or configuration issues, the temperature(s) will always be displayed at the very top of the TASMOTA main menu.
Using the console command line is slightly more obtuse, though. The temperature readouts are a part of the TASMOTA status group, so you could type in the command “status 0” to get a full display of all possible status items. However, if you do that, you will see an extremely verbose listing of 10 separate lines of status, with the temperature data being displayed as status line “STATUS10…StatusSNS…”. Luckily that line hints at the command we need to use to get just the temperatures and nothing else. The magic incantation is “status 10” and typing that into the console input box will return just that single “StatusSNS” line with our sensor data, including the sensor’s unique serial number and an indication of whether it is reporting in Fahrenheit or Celsius, as well as the temperature value itself.
00:55:11 CMD: status 10
00:55:11 MQT: stat/Plug1/STATUS10 = {"StatusSNS":{"Time":"2018-02-01T00:55:11","DS18B20-1":{"Id":"011590E534FF","Temperature":2.87},"DS18B20-2":{"Id":"031590A618FF","Temperature":1.87},"TempUnit":"C"}}
There are a number of “setoption” commands in the TASMOTA toolbox and, for those who might need it, the command “setoption8” will change the temperature display units.
setoption8 0
– sets the units to Celsius
setoption8 1
– sets the units to Fahrenheit
That’s it for the console commands for now. Next time we’ll look at doing the same thing again, but utilizing MQTT from a remote machine, instead.