A couple of months ago a new development board based on the popular esp8266 was created.

It seems like a compact version of the popular nodemcu board that includes an RGB led and an LDR. It is called esp8266 witty ( you’ll find them for just a couple of dollars on ebay or aliexpress) and the idea was to split the UART interface into a dedicated board that can be attached to the esp8266 whenever you need to program it or access the serial interface to read data (clever design guys).

The board comes with a custom firmware flashed which I honestly didn’t try to explore because I’m used to nodemcu firmware. Connection was established using the ESPlorer at 115200bps. After connecting this is what we can see:

Welcome screen ESPlorer esp8266 witty version

Flashing the nodemcu firmware is straightforward just like any with any nodemcu dev board… keep the flash button pressed while pressing reset and use the esp tool to flash the firmware:

esptool flashing esp8266

And there you go, nodemcu firmware is now running:

nodemcu firmware flashed by esptool.py

On a side note, the baud rate changed from 115200 to 74880. This is an unusual value for it, but if it doesn’t work for you, just play with the values until you find what works for you.

I couldn’t find a lot of documentation regarding this module and how to access the LDR and the RGB led. Fortunately it was very easy to find out.

The esp8266 modules have a single pin with analog reading capabilities ( pin 0 ) and that was it. For the digital pins controlling the led channels all I had to do was a simple for loop to iterate over all the digital pins and find out which ones were triggering the blue, read and green channels. It ended up being pin 6, 7 and 8.

The following lua snippet will output green under good light conditions and red under low light:

-- Output pins:
-- 6: Green
-- 7: Blue
-- 8: Red
 
-- Input pins:
-- 0: LDR
 
 
function clearOutput()
  for i=6,8 do
    gpio.mode(i, gpio.OUTPUT)
    gpio.write(i, gpio.LOW)
  end
end
 
 
tmr.alarm(1, 1000, 1, function()
  -- Output LOW on all channels
  ldr_value = adc.read(0)
  print(string.format("Current LDR value: %d", ldr_value))
 
   clearOutput()
   if ldr_value > 600 then
     gpio.write(6, gpio.HIGH)
     gpio.write(8, gpio.LOW)
   else
     gpio.write(6, gpio.LOW)
     gpio.write(8, gpio.HIGH)
   end
 
end )

Have fun! 🙂

Useful links:
esptool.py – https://github.com/themadinventor/esptool
nodemcu firmware binaries – https://github.com/nodemcu/nodemcu-firmware/releases
ESPlorer – http://esp8266.ru/esplorer/