Skip to content

Instantly share code, notes, and snippets.

@sjoerdvan
Last active May 8, 2020 16:31
Show Gist options
  • Save sjoerdvan/65f82b08e8cc358136a2081927578c46 to your computer and use it in GitHub Desktop.
Save sjoerdvan/65f82b08e8cc358136a2081927578c46 to your computer and use it in GitHub Desktop.
Wemos D1 mini pro start guide on OS X with micropython

Basic setup

Install usb serial driver

Download the latest esp8266 micropython binary.

After driver installation do: '''bash sudo kextload /Library/Extensions/SiLabsUSBDriver.kext ''' Then in security settings on your mac, click allow for the kext (kernel extension) to be activated. I needed this for OS X High Sierra

Optional: Erase the flash of the Wemos D1 with esptool

esptool.py -p /dev/tty.SLAB_USBtoUART erase_flash

Run to install micropython on the Wemos D1 with esptool(install this with pip install esptool):

esptool.py -p /dev/tty.SLAB_USBtoUART write_flash -fm dio -fs 4MB 0 ~/Downloads/esp8266-20171101-v1.9.3.bin

Notice, use 4MB even though the D1 mini pro has more space. I tried 16MB and it failed.

Connect to the device

To connect use screen or picocom (when still connected to usb, restart probably required after driver install)

picocom /dev/tty.SLAB_USBtoUART -b115200

Configure remote access via Webrepl (useful for file transfer f/e)

Connect to the device (see above) and run

import webrepl_setup

Follow the steps (enable and set a password) and you're done. You can now connect to it via a webinterface (details or use the online (but local browser running) webrepl)

Configure wifi:

https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/network_basics.html

import network
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)
sta_if.active()
False
ap_if.active()
True
ap_if.ifconfig()
('192.168.4.1', '255.255.255.0', '192.168.4.1', '8.8.8.8')

Configure your own netwerk:

sta_if.active(True)
sta_if.connect('<your ESSID>', '<your password>')
sta_if.isconnected()
sta_if.ifconfig()

Or put the following in your boot.py(or main.py) so it connects on boot

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('<your essid>', '<your password>')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())


connect()

Startup files

There are two files that are treated specially by the ESP8266 when it starts up: boot.py and main.py. The boot.py script is executed first (if it exists) and then once it completes the main.py script is executed. You can create these files yourself and populate them with the code that you want to run when the device starts up.

Connect via a webinterface which can also send and retrieve files

Activate Webrepl on the device, instructions

Download the webrepl client and open webrepl.html

About time stuff on Micropython

So....micropython doesn't use the epoch as it should, but utime.time() shows the seconds since 1-1-2000.

Also the clock seems to drift, so using it every 7,5 hours or using settime is a must. Details

Updating the Wemos D1 mini pro to 16mb flash (128M bit)

I used the instructions (and files) from here Make sure you have esptool later than 2.3.1 (I used 2.5.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment