ESP8266 – Getting Started with MicroPython

For a couple of pounds I purchased a couple of ESP8266 NodeMCU WEMOS development boards to play with. Decided to go with the NodeMCU versions so that they come with a micro USB and 3.3 regulator onboard.

As I’ve been playing with Python for a while I decided to download MicroPython on to the ESP to provide control of real-world devices. Instructions on downloading, formatting and getting started with MicroPython can be found here.

I’ve included my notes here as things were not as plain-sailing as I would have liked.

Connecting the ESP8266 to my Mac – sounds easy but the hardest part is finding a USB cable that has data connections instead of just being wired for 5v-GND. Most charging cables come with only power wired so after trying about 6 cables I found one that worked.

So how did I know I had a good cables as all powered up the ESP? You need to see if your Mac shows the USB device turning up. Before connecting type “ls /dev | grep -I usb” and then connect the device. You should see the device show up if the cable has the right connections.

Now download the esptool for programming the ESP and transmits the firmware to the ESP.

And down a copy of the Micropython Firmware from the above MicroPython site.

If you need to find out ESP board information such as flash size use: -p /dev/ttyUSB_DEVICE flash_id

To program the ESP I used the following command: --port /dev/ttyUSB_DEVICE --baud 460800 write_flash --flash_size=detect 0 FIRMWARE>BIN

      ttyUSB_DEVICE is your device found from the ls /dev command above
      FIRMWARE.BIN is the file you downloaded from the MicroPython site

With luck the firmware would have downloaded and successfully been verified – woohoo!

Now you can connect to the device and get a REPL prompt.

REPL prompt – that sounds easy but it took a few goes to find the right command on the Mac to create a serial connection to the ESP on the USB port and then get it working. The “screen” command is available on the Mac and the speed to connect with is 115200.

screen /dev/cuUSB_DEVICE 115200

                 screen quick reference guide >> link

I found that I sometimes got an error about no Pty device. This turned out to be zombie screen processes locking out the device port. Perform a “ps -ef | grep -i usb” to find the zombie processes and kill them (show no mercy).

 You can not follow the instructions on the MicroPython site to interact with the REPL prompt. If you want to upload/download files then you will need “WebREPL“.

Notes on uploading files to Execute

  • Use the web version of WebREPL or to send or get files from the ESP
  • I found that once a file is uploaded you need to reset before attempting to run the file. A soft reset can be performed by pressing Ctrl-D in the browser or at the REPL command prompt in screen
  • To run the file import it!

Controlling a 5050 WS2812B RGB LED Ring

This was a few pounds on Ebay so tried to connect it to the ESP8266 WEMOS which was pretty simple after I soldered some wires on. I connected the 5v and GND straight to the ESP pins, and the Din (DI) wire to D2 on the WEMOS. This is GPIO04 (pin out found here). 

Power consumption = each led is around 18mA on.

If you want to create an online wiring diagram with drag-n-drop components then use which is pretty cool.

To control the leds you need to run some MicroPython code on the ESP but you can use the example below:

import machine, neopixel
np = neopixel.NeoPixel(machine.Pin(4), 12) #we have 12 leds on GPIO4

np[0] = (128, 0, 0) # Led 0 half bright single color - red I think
np[2] = (0, 128, 0) # Led 2 another colour
np[4] = (0, 0, 128)


You should have some (3) leds now light up, if it all works!


Posted in Electronics | Tagged , , , | Leave a comment

git Quick Reference

Pull Code from a Repository
    git clone http://{server/repository.git

Add Files to Local Repository
    git add *

Status of Local Files
    git status

Commit Changes Locally
    git commit -m "Adding new files"

Commit Change to Remote Main Branch
    git push origin master

Refresh Local Files in Case Other Updates Took Place
    git pull origin master

Creating a development branch
    git checkout -b develop origin

Push new branch back to the server
    git push -u origin develop


An excellent and more detailed quick reference guide is located here and cheatsheets here.

A great article on managing versions and releases is here

Posted in Uncategorized | Leave a comment

Installing Gitea (my own GitHub)

To install Gitea on a Synology under Docker you can pretty much follow the instructions found here

I used the custome setup with some minor changes to the USER-UID & USER-GID for the account I want to run under on the Synology. 


version: "2"
    external: false
    image: gitea/gitea:latest
      - USER_UID={enter User ID here}
      - USER_GID={enter Group ID here}
    restart: always
      - gitea
      - ./gitea:/data
      - "3000:3000"
      - "222:22"

The above will use a SQLite database which should be fine. 

When running “sudo docker-compose up -d” an error was generated for failing to mount “gitea” due to permissions. Manually creating the folder and re-running the command fixed the issue.

Checking Docker on the Synology finds that the container is running and connecting with a browser to http://{server}:3000 with bring up the Gitea page – woohoo!


Posted in Code, Docker | Tagged , , , | Leave a comment

SVN Quick Reference

View Repository
    svn ls svn://{server}/projects

Import New Folders in to Repository
   svn import {folder} svn://{server}/projects/{folder} -m "{comment}"

Checkout Folder/Files from Repository
  svn co svn://{server}/projects/{folder}

View Status of Files in Folder
  svn status

Checkin Changed Files to Repository
  svn commit -m "{comment}"

Pull Latest Files from Repository
  svn update

Posted in Code | Tagged , | Leave a comment

Docker Quick Reference

View/Change Container Status
    docker ps                 {list running containers}
    docker ps -a              {list all containers even exited ones}
    docker container pause ID {pause running container}
    docker container stop ID  {stop running container}
    docker container kill ID  {Kill a running container}
    docker logs -f ID         {continually follow output of container}
Access Running Container
   docker ps                               {find ID of running container}
   docker commit ID mysnapshot             {create a snapshot}
   docker run -t -i mysnapshot /bin/bash   {run a bash shell}
                                           {-i interactive, -t terminal}
Building/Running a Container {containing python code}
   docker build -t {name} .
   docker  run -i -t {name} python
Deleting Images
   docker image list      {list images}
   docker rmi image_ID.   {remove image}
   If you are unable to delete due to container in use
      docker ps                   {get container name}
      docker rm container_name    {remove exited container}
      docker rmi image_id         {remove image}
Mounting Local File Systems
This will mount the current directory as /mnt/app for the container to access:
    docker run -it -v ${PWD}:/mnt/app instabot /bin/bash
Docker Documentation
Posted in Code, Docker | Leave a comment

Excel: Expand multi-line rows

How to end up with one row per entry in a spreadsheet when some cells contain multiple entries. This example will expand the data below in to multiple rows using a VB. Noting here for my reference.

The following code with take the above (Sheet1) content and create a new worksheet (Sheet2) with the expanded records. As the code expands both column D & E an error is thrown for row 4 as the same number of entries do not match in both cells.

Public Sub expandData()
    MsgBox "Make sure to have an Empty Sheet2"
    If Not IsEmpty(Worksheets("Sheet2").Range("A1").Value) Then
        MsgBox "Sheet2 looks like it has data?"
        Dim i As Long
        Dim insertrow As Long
        i = 1
        insertrow = 1
        Do While Not IsEmpty(Worksheets("Sheet1").Range("A" + CStr(i)).Value)
            insertrow = expandRow2("A" + CStr(i) + ":C" + CStr(i), "D" + CStr(i), "E" + CStr(i), insertrow)
            i = i + 1
    End If
End Sub

Private Function expandRow2(copyrange As String, expcell As String, expcell2 As String, insertpoint As Long)
    Dim count As Integer
    Dim sa() As String
    Dim sb() As String
    Dim i As Integer
    count = Worksheets("Sheet1").Range(copyrange).Columns.count
    sa() = Split(Worksheets("Sheet1").Range(expcell).Value, vbLf)
    sb() = Split(Worksheets("Sheet1").Range(expcell2).Value, vbLf)
    If UBound(sa) <> UBound(sb) Then
        Worksheets("Sheet1").Range(copyrange).Copy Destination:=Worksheets("Sheet2").Range("A" + CStr(insertpoint))
        Worksheets("Sheet2").Cells(insertpoint, count + 1).Value = "#ERROR"
        insertpoint = insertpoint + 1
        For i = 0 To UBound(sa)
            Worksheets("Sheet1").Range(copyrange).Copy Destination:=Worksheets("Sheet2").Range("A" + CStr(insertpoint))
            Worksheets("Sheet2").Cells(insertpoint, count + 1).Value = sa(i)
            Worksheets("Sheet2").Cells(insertpoint, count + 2).Value = sb(i)
            insertpoint = insertpoint + 1
        Next i
    End If
    expandRow2 = insertpoint
End Function
Posted in Code, Microsoft, Software | Leave a comment

Creating an Alexa Skill to work with your Synology

I found this excellent article on creating a basic Alexa skill. Follow this tutorial to get a basic skill and use the php code below instead of the shell script in the tutorial as the Synology does not like non-PHP scripts.

 header("Content-Type: application/json;charset=utf-8");
{ "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "Got it. Yes, your command was received."} }}

In the Amazon skill testing you can see the JSON data sent to the Synology. After the tutorial you will find that that you are only sending the date and no other command data. To send more data the Amazon skill will need to be further developed.

More to come on linking the broadlink and Alexa skill

Posted in Code, Home Automation | Leave a comment

Broadlink RM IR control via Python

Christmas I received the Broadlink RM device for controlling IR devices with the intention of using it with Amazon Alexa. It turns out that the service is not available in the UK so the only way to control the device is with the phone App.

After ‘googling’ for options it turns out there are ways to bridge the connection using Android devices, which I don’t have. My next option was to look for ways to control the device through Python and create my own skills in Alexa.

Everything is easier said than done but here goes.

Step 1. make sure your broadlink RM device is on your network and you can see it with the phone App. Just follow the instructions in the box for this bit.

Step 2. I found a library on github to provide some basic API features. Download the API from user mjg59 on github. From this point you can follow the instructions on the README 🙂

or mine below…..

Step 3. I found that my install of Python did not have pyaes installed that is used by the API so ….. sudo pip install pyaes

Step 4. Okay, when I download the code from github I placed the contents of broadlink/ in to You will need to do the same if you use the code below to learn one command from your remote and repeat it back out. This will prove you can communicate with the broadlink device and play out a recorded IR code.

import broadlink
import time

devices =


ir = devices[0].check_data()



Running the above will give you 5 seconds to learn an IR code (your broadlink should show an amber light) and 10 seconds later the broadlink will reply the command.

This proves you have control of your broadlink. The next stages will be to learn all your IR commands to build a database that Alexa can use.

Posted in Code, Home Automation | Leave a comment

Synology Certificates and Alexa Skills

If you want to host Alexa skills on your Synology you will need to use Let’s Encrypt certificates as the default one will not authenticate for the skill.

To check if your certificate is okay use SSLChecker to validate the certificate from the Synology. You should get all green ticks. Anything else will cause a failure while testing the skill.

Posted in Code, Home Automation | Leave a comment

Installing Screen on Synology

Home page for screen

To install on synology you need to have ipkg installed. Mine is located in /opt/bin.

sudo /opt/bin/ipkg install screen

If you just run /opt/bin/screen you will get a terminal error as you may not have a termcap entry. For me the fix was:

TERM=xterm-color /opt/bin/screen

Screen commands:

  • Ctrl-a Ctrl-d  = detach from screen
  • screen -r = re-attach to screen
  • Ctrl-a Ctrl-\ = kill session and terminate

Loads more command on the above screen page

Posted in Code, Software | Leave a comment