Long time since last post. Other hobbies get in the way, and in my tiny house my electronics bench gets buried.

I bought a Wemos D1 Mini with MicroPython as part of a toy order from universal-solder.ca. Universal Solder is a Canadian company, which I like to support. They have a pretty good selection of microcontrollers, prototyping stuff and electronic gadgets. Good service so far.

The Wemos D1 Mini uses an Expressif ESP8266EX processor clocked at 80MHz. It has a generous 4MB of Flash memory. The board does WiFi b/g/n, and has 11 GPIO pins. Not bad for $7.50 Canadian.

When I first plugged it in all it would do was scan WiFi over and over, and nothing else, no matter what I tried. It acted like MicroPython wasn't installed. I assume I got the one that someone fubared the software until they gave up and returned it?

So I flashed the latest MicroPython on it, and it still wouldn't work. I would go through the "Basics" tutorial and it would blink LEDs and stuff, but neither filesystem commands nor network stuff would work. Just nothing but errors.

So I reflashed to the second newest version of MicroPython. Now finally I was able to get the filesystem to work, and get WiFi connected to my network.

I recently reflashed the Wemos to the newest MicroPython again and I'm pretty sure that all that confusion and errors were caused my my noobness with the board at the time. Seems to work fine now.

This isn't one of those MicroPython boards that shows up on your computer as a hard drive, where you just edit the files in the board's directory. This doesn't have that. You interact with the Wemos D1 via serial interface (screen, picocom, putty, etc.) in the terminal and with REPL. So I had to find a way to upload my code to the thing.

I set up and ran WebREPL for a while, but found it incredibly clumsy and annoying - constantly disconnecting or locking up.

Gave up on that and installed Adafruit's Ampy. Fought with that for some hours and could not get it to connect. I'm sure that if I had persevered I would have got it working, but I was tired of it.

So I turned to rshell. I noticed that it was written by Dave Hylands, who I have a lot of respect for, so I installed it and gave it a try. It took a bit of fiddling to get it working (my fault - it's not terribly difficult), but once I got things set up right and got comfortable with it it works great! Nice comfy tool to work in. I write my code in Atom, save to main.py, and flip to rshell to upload the program to the Wemos D1. Works pretty well.

Here's the MicroPython code to display the value of the single A/D pin reading a potentiometer (photo above). Just vanilla MicroPython code - nothing fancy.

from machine import Pin, SPI,ADC
import time

adc = ADC(0)
cs = Pin(0, Pin.OUT)
cs(1)

spi = SPI(miso=Pin(12), mosi=Pin(4), sck=Pin(2))

dig1 = dig2 = dig3 = dig4 = 0

#initialize
cs(0)
spi.write(b'\x0a')
spi.write(b'\x0f')
cs(1)
cs(0)
spi.write(b'\x0b')
spi.write(b'\x03')
cs(1)
cs(0)
spi.write(b'\x09')
spi.write(b'\x0f')
cs(1)
cs(0)
spi.write(b'\x0c')
spi.write(b'\x01')
cs(1)

while True:
    d = adc.read()
    d = int(d)

    if(d > 0):
        dig4 = d % 10
        d = d / 10
    cs(0)
    spi.write(bytes([0x01,int(dig4)]))
    cs(1)

    if(d > 0):
        dig3 = int(d % 10)
        d = d / 10
    cs(0)
    spi.write(bytes([0x02,int(dig3)]))
    cs(1)

    if(d > 0):
        dig2 = int(d % 10)
        d = d / 10
    cs(0)
    spi.write(bytes([0x03,int(dig2)]))
    cs(1)

    if(d > 0):
        dig1 = int(d % 10)
    cs(0)
    spi.write(bytes([0x04,int(dig1)]))
    cs(1)

    time.sleep_ms(50)

Next Post Previous Post