Categories
computers suck

MicroPython on the terrible old ESP8266-12 Development Board

… + 1 + 1 + 1 …

I just found my first ESP8266 dev board. This was from way back before Arduino support, and long before MicroPython

esp8266-dev-boards from ESP8266 Support WIKI

It’s not really in a useful form factor, but it’s got some sensors and outputs:

  • an LDR on the ADC channel
  • RGB LED for PWM on pins 15, 12 & 13
  • red LEDs pins 16, 14, 5, 4, 0, 2 with inverted logic: set them low to light them.

My board can’t quite be the earliest of the early, as it has 1 MB of flash. This is enough to install MicroPython, so I wrote a tiny test program for the outputs:

  • run a binary counter every second on the six red LEDs;
  • cycle through a colour wheel on the RGB LED while this is happening.

Here’s the code:

# esp8266 old explorer board
# see https://www.esp8266.com/wiki/lib/exe/detail.php?id=esp8266-dev-boards&media=esp8266-12_mod.png

from time import sleep
from machine import Pin, PWM
# LEDs are 16, 14, 5, 4, 0, 2 - L to R
# inverted logic: 1 = off
leds = [Pin(2, Pin.OUT, value=1), Pin(0, Pin.OUT, value=1), Pin(4, Pin.OUT, value=1), Pin(
    5, Pin.OUT, value=1), Pin(14, Pin.OUT, value=1), Pin(16, Pin.OUT, value=1)]

# RGB for PWM on [15, 12, 13]
rgb = (PWM(Pin(15)), PWM(Pin(12)), PWM(Pin(13)))
# LDR on ADC


def cos_wheel(pos):
    # Input a value 0 to 255 to get a colour value.
    # scruss (Stewart Russell) - 2019-03 - CC-BY-SA
    from math import cos, pi
    if pos < 0:
        return (0, 0, 0)
    pos %= 256
    pos /= 255.0
    return (int(255 * (1 + cos(pos * 2 * pi)) / 2),
            int(255 * (1 + cos((pos - 1 / 3.0) * 2 * pi)) / 2),
            int(255 * (1 + cos((pos - 2 / 3.0) * 2 * pi)) / 2))


i = 1
while True:
    i = i + 1
    i = i % 64
    w = cos_wheel(4 * i)
    for j in range(3):
        rgb[j].duty(4 * w[j])

    for k in range(6):
        if i &amp; (1 << k):
            leds[k].value(0)
        else:
            leds[k].value(1)
    sleep(1)

Leave a Reply

Your email address will not be published. Required fields are marked *