/ microcontroller monday

Microcontroller Monday - Wemos W600 Pico

< Film trailer voice >From the team that brought you the Wemos D1 comes the W600 Pico...< / Film trailer voice >

Before we get too deep into this blog post I would like to thank Volodymyr Shymanskyy for his help in solving a few issues with this board. So please go and check out his projects!

A new tiny board that connects to the Internet!

Main

Another one?

Yeah! The Wemos W600 Pico is a rather fun piece of kit, especially when we factor in the cost, around $3 for the board!
w600vsD1Mini-Side
Measuring only 33mm x 20mm this board is just smaller than the venerable Wemos D1 Mini (which has powered a few of my projects!)
w600vsD1Mini

What do we get for the money?

  • Arm Cortex M3 running at 80MHz
  • WIFI (2.4GHz)
  • 1MB Flash
  • 15x IO
  • 1x I2C
  • 1x SPI
  • 1x UART
  • RTC (Real Time Clock)
  • Hardware Cryptography
  • CH340 USB to TTL (Serial) connector
  • MicroPython

Where can I buy one?

Screenshot-from-2020-01-30-14-25-18
I picked up a couple from Aliexpress for $2.10 each and they took around 2 weeks to reach me. At the time of writing, the seller is out of stock. This is likely due to it being Chinese New Year and the awful virus outbreak means that whole areas are isolated from each other, preventing them from working and being with loved ones so that everyone can be safe.

Pinout

w600_pico_v1.0.0_3_16x9
Image from [https://docs.wemos.cc/en/latest/w600/w600_pico.html]
The GPIO runs at 3.3V so when using any components at 5V, take all the necessary steps to protect the W600 Pico.

If you like what you read...
BuyMeACoffee_blue@2x-1
Sorry to interrupt! But would you like to buy me a cup of coffee? It helps me to pay for hosting this blog, and to buy stuff to hack from Poundshops / Dollar Stores which are used in free projects on this blog. Thanks!

Getting access to the repl

To access the repl for the w600 Pico, and from there we can test that our board works, we need to plug in the board to our computer and for my Ubuntu machine I opened a terminal and ran the following command to detect which port it was connected to.

udevadm monitor --udev

Which was /dev/ttyUSB0 for me. Windows users can detect the correct port using the Device Manager application, and then checking their COM ports.

Connecting to the repl

Screenshot-from-2020-01-29-15-20-55
I used tio, a recent Tuesday Tooling discovery to create a connection to the W600 Pico via the USB to Serial interface. But you can use tools such as puTTY to make a connection on Windows.

So this is MicroPython?

Yup, the included version (as of January 2020) is MicroPython v1.10-282-g6a9b3cb-dirty on 2019-09-17; WinnerMicro module with W600 and it comes with a standard set of modules for us to use.

What modules come as standard?

_boot             hashlib           select            uos
_onewire          heapq             socket            urandom
_thread           io                struct            ure
array             json              sys               uselect
binascii          machine           time              usocket
builtins          math              ubinascii         ustruct
cmath             micropython       ucollections      utime
collections       network           uctypes           utimeq
ds18x20           ntptime           uerrno            uzlib
easyw600          onewire           uhashlib          w600
errno             os                uheapq            zlib
framebuf          random            uio

Two modules which caught my eye were easyw600 and w600 as these are board specific. But what do they do?

easyw600

>>> import easyw600
>>> easyw600.
__class__       __name__        binascii        connect
disconnect      network         oneshot         scan
utime           w600            createap        closeap
ftpserver

Immediately I can see connect and disconnect which provide a simple means to connect to a know WiFi AP / SSID.
Connect to WiFi

import easyw600
easyw600.connect("NAME OF ACCESS POINT","PASSWORD")

Create a quick FTP Server and upload your files
Screenshot-from-2020-01-29-15-33-45
All I needed to do was first connect the board to the WiFi and then run the ftpserver. It opened port 21, and told me the username/ password.

import easyw600
easyw600.ftpserver()

Screenshot-from-2020-01-25-18-37-03
Then using an FTP client, in my case the file manager in Ubuntu, go to the IP address of the board, like this.

ftp://192.168.0.5

And login as

username: root
password: root

We can then upload files to the board, for example I uploaded a custom boot.py using this method, and now my W600 Pico connects to WiFi on boot. This is far from ideal, but it at least gives me access from any device.

Change the FTP password
In the easyw600.py file, line 55 we see the username and password for the FTP server. These can be changed to suit your requirements.

def ftpserver():
    w600.run_ftpserver(port=21,username="root",password="root")
    print("ftp server port is 21, username is root, password is root")

Create an Access Point
If you need to create an access point from which we can connect locally, we can tell the W600 Pico to broadcast its own Access Point.

import easyw600
easyw600.createap()

Then we can connect via FTP to upload files.

w600

The w600 module looks to be a collection of tools to work with the flash memory of the device. Use with caution!

>>> w600.
__class__       __name__        flash_erase     flash_id
flash_read      flash_size      flash_user_start
flash_write     run_ftpserver   version

The "Hello World" of physical computing! Ok lets do it! I connected the anode (long leg) of an LED to PB6, and the short leg (cathode) was connected to GND via a 220 Ohm resistor.

from machine import Pin
import time
led = Pin(Pin.PB_06, Pin.OUT, Pin.PULL_FLOATING)
while True:
    led.value(1)
    time.sleep(0.2)
    led.value(0)
    time.sleep(0.2)

Why Pin.PULL_FLOATING?
For some reason if we do not include that argument, then the pin will not activate. My best guess is that there is a pull up/down resistor for the pin.

The only issue with doing this test is that the repl will become unresponsive, and we have to reset the board to carry on working.

w600tool

January 31 2020 - Update - Please note that this section has been completely revised so that we only use the original version of this tool, and not the Wemos version which has a few issues with correctly flashing code to the W600.

So what is it?

The original and well maintained tool to upload firmware to a W600 Pico board. Created by Volodymyr Shymanskyy, w600tool is designed for W600 and W601 boards and is a general maintenance tool for uploading firmware and for getting and setting the devices MAC address.

So how do I install it?

Clone the repository from Github.

git clone https://github.com/vshymanskyy/w600tool

You can also download the ZIP file containing the project.

Then install a few dependencies via pip3.

sudo pip3 install pyserial PyPrind xmodem

So how do I use it?

Lets take a typical use case.

Flashing new firmware to the W600 Pico

success
I've got my W600 Pico, and a new firmware is released. So I download it and copy the image file img or fls to the same location as w600tool.py and then I use this command to upload it to the board.

python3 w600tool.py -p /dev/ttyUSB0 -u wm_w600.fls --upload-baud 115200

Lets breakdown that command

I call python3 to run the Python code inside w600tool.py.
The -p switch tells w600tool that I am using port /dev/ttyUSB0 to upload the file.
The -u switch is the name of the firmware file I aam uploading.
Finally --upload-baud 115200 tells w600tool that the baud rate (connection speed) should be 115200bps.

Can I make w600tool.py an executable application?
Sure, to make w600tool.py executable in a terminal, in the same directory as the file type chmod +x w600tool.py and you will not have to call the command with python3 at the start. You can also copy w600tool.py to your /usr/bin/ directory by typing sudo cp w600tool/w600tool.py /usr/bin/w600tool so now all we have to do is type w600tool to use the command.

So why should I use this over the Wemos version?

This is the original version which does not have any issues. The Wemos fork of this project has a few issues with line ending characters and this causes Python3 to error unless we remove these characters using a tool such as dos2unix.

How can I upload my code to the board?

I mentioned earlier that we can set the W600 Pico to run an FTP server, but sometimes we just want to send a file to the board without messing around with servers etc. The ideal tool for this is Adafruit's ampy, which I've written about in a Tuesday Tooling blog post. But here is a condensed version of that post.

To install ampy

Linux

sudo pip3 install adafruit-ampy

Windows

pip.exe install adafruit-ampy

For my project I wanted to upload a custom boot.py file to connect my W600 Pico to my home WiFi on boot. So in a text editor I did just that.

import easyw600
easyw600.connect("EVIL LAIR AP","TRUSTNO1")

Then using ampy I upload the file to the W600 Pico...or so I thought :(

ampy --port /dev/ttyUSB0 put boot.py

Screenshot-from-2020-01-29-13-45-22
I got an error stating that ampy could not enter a raw repl and this caused the application to exit

But luckily Volodymyr Shymanskyy was on hand to help and offered a workaround by replacing a file in the ampy install with a modified version. I've copied the file to my Google Drive, from where you can download it.
I then saved the original pyboard.py file in the ampy directory

 sudo mv /usr/local/lib/python3.6/dist-packages/ampy/pyboard.py  /usr/local/lib/python3.6/dist-packages/ampy/pyboard.py.old

And then copied the new pyboard.py file from my Downloads directory to the ampy directory.

sudo cp /home/les/Downloads/pyboard.py  /usr/local/lib/python3.6/dist-packages/ampy/pyboard.py

Then I ran the ampy command to copy my custom boot.py file to the W600 Pico.

ampy --port /dev/ttyUSB0 put boot.py

Screenshot-from-2020-01-30-13-10-53
The code in my custom boot.py file, and no that is not my WiFi details
Screenshot-from-2020-01-30-13-12-11
Successfully copied a file to the W600 Pico
Screenshot-from-2020-01-30-13-13-00
Proof that it worked

So is ampy at fault?
No!

As Volodymyr says "I believe the problem is in the pre-built uPython image for W600 (it uses different line ending marks for some reason)" and I believe that the issue with line ending marks we encountered and had to mitigate using dos2unix confirms this.

MicroPython Specifics!

MicroPython has two files that are important to us and these are the main files that we will interact with, unless we add our own libraries of MicroPython code.

boot.py

This is the file which contains the code that will run when the W600 Pico is powered up. So in my use case I added two lines of code to automatically connect the board to my WiFi. This can also be used to set any specific requirements for the board, WiFi, FTP server, blinking lights to confirm successful startup.

main.py

In this file is the main application / project that you are using the board for, such as your cool weather station or Neopixel lamp.

Happy Hacking!