Category Archives: Uncategorized

Introduction to Python Workshop

The CircuitPython Circuit Playground Express Sound and Light Project

On 2/23/19 I taught my first “Introduction to Python” workshop at Ocean State Maker Mill.
What a great experience getting a chance to interact with everyone that attended. The class slides and code are available on GitHub.

Class Description:

Introduction to Python using: Adafruit CircuitPython & Circuit Playground Express

This workshop is designed to be a fun introduction to the Python language and micro-controllers.

This is a hands on interactive workshop!

Over 3 hours we will explore programming concepts with Python while we implement a project to translate sound into a colorful light display. This is a beginner class, no prior programming experience is needed.

We will cover:

- How to install CircuitPython on the Circuit Playground Express
- Installing the Mu Python editor
- Basic Python concepts, syntax, data types, operators, and expressions
- How to use Python to interact with the Circuit Playground Express

At the completion of the class you will have your own Circuit Playground Express to take home, programmed in Python to create a colorful light display in response to sound. You will be on your way to creating your own interactive projects!

IoT on the Cheap: ESP MicroPython Tools: Simple IDE uPyCraft

I just discovered a new (to me) MicroPython IDE, uPyCraft by DFRobot. It’s a great little IDE modeled along the lines of the Arduino IDE. It has cross platform support: Windows, Linux, and Mac. It supports multiple ESP versions. I tested with a WEMOS D1 Mini Lite with no issues. However, I did not try to flash the firmware.

I had one minor issue with the uPyCraft installation on Windows. uPyCraft requires the SourceCodePro font and has trouble locating the version I had installed.

If you click “OK” you can install the font. If you click “Cancel” the font file is copied to your desktop. You can right click the font file to install it. Once the font is installed uPyCraft ran without issues.

To connect to your ESP board click on the ESP serial port, Tools->Serial-><COMx> . You can also click on the Connect/Disconnect icon, the chain icon, on the right tool bar.

DFRobot includes a nice set of examples with uPyCraft. The REPL window supports editing keys and command recall. The files on your ESP are listed on the left under “Device”.  Right clicking on a file gives you a list of options, including editing in place, running, deleting.
Very nice, clean, easy to use design. In my limited testing uPyCraft was reliable with no issues.

You can download uPyCraft from GitHub: https://github.com/DFRobot/uPyCraft

DFRobot also provides a nice tutorial here: http://docs.dfrobot.com/upycraft/

Source code is available here: https://github.com/DFRobot/uPyCraft_src

IoT on the Cheap: ESP MicroPython Tools: IDE and Command Line

To complete our ESP on the cheap development  environment we need some additional tools to turbocharge our productivity. I did a survey of available tools and found two that meet the criteria for Windows, Mac, and Linux cross platform support and have multiple ESP board vendor support. The first tool is a command line utility that makes it a breeze to perform file operations and run MicroPython programs on the ESP:  Adafruit’s ampy. The second tool is the Pycharm IDE with the MicroPython plugin.

First, let’s take a look at “ampy”.  “ampy” provides simple, but vital, ESP file system functionality, reliably. The usage information below spells it out clearly.

ampy - Adafruit MicroPython Tool

Ampy is a tool to control MicroPython boards over a serial connection.Using ampy you can manipulate files on the board's internal filesystem and even run scripts.

Options:
-p, --port PORT Name of serial port for connected board. Can optionally
specify with AMPY_PORT environment variable. [required]
-b, --baud BAUD Baud rate for the serial connection (default 115200).
Can optionally specify with AMPY_BAUD environment
variable.
-d, --delay DELAY Delay in seconds before entering RAW MODE (default 0).
Can optionally specify with AMPY_DELAY environment
variable.
--version Show the version and exit.
--help Show this message and exit.

Commands:
get           Retrieve a file from the board.
ls              List contents of a directory on the board.
mkdir     Create a directory on the board.
put          Put a file or folder and its contents on the...
reset       Perform soft reset/reboot of the board.
rm           Remove a file from the board.
rmdir     Forcefully remove a folder and all its...
run         Run a script and print its output

Installing ampy is also straightforward:

pip install adafruit-ampy

To upgrade to the latest version:

pip install adafruit-ampy --upgrade

The source and documentation for ampy is available in github:
https://github.com/adafruit/

“ampy”, it simply works. Nice.

At the opposite end of the power and complexity spectrum we have PyCharm. PyCharm is a full featured, professional, powerful, integrated development environment (IDE) for Python. The community edition is FREE. There is great documentation available for PyCharm so I am not going to discuss all its features and installation instructions here. I am just going to focus on the MicroPython plugin. The plugin is available on github: https://github.com/vlasovskikh/intellij-micropython

However, you can install and configure the Micropython plugin from within PyCharm. That’s what we are going to do.

Go to File->Settings->Plugins->Install JetBrains Plugins, search for MicroPython and install the plugin.

Next, go to File->Settings->Languages & Frameworks->MicroPython

On Windows the plugin did not detect my WEMOS D1 MINI ESP8285. I had to enter the COM port manually. In my case COM4. Select your device type, the ESP8285 is equivalent to an ESP8266. Enable MicroPython support.

Plug in your ESP board if you haven’t already. We will bring up the ESP REPL to verify that our installation is working. Select Tools->MicroPython->MicroPython REPL.

I had to hit the reset button on my ESP to get it to work the first time. After that I didn’t have any issues.I found that none of the text editing keys worked in the REPL window, backspace, command recall, etc. So keep that in mind if you are planning to do extensive work in REPL. You may want to just open a terminal session (PuTTY on Windows).

To transfer files to the ESP you create a “flash” configuration, by right clicking on the file.

Once created it is a simple matter to run the configuration and copy the file to the ESP.

You can now work directly with your ESP (or other) MicroPython board without having to leave PyCharm!

But wait, there is more! The MicroPython plugin also includes support for context aware completion and documentation (ctrl-Q), syntax checking, and type checking. Go PyCharm!

IoT on the Cheap: ESP WebREPL Access

In this post we will be covering how to connect to the MicroPython interpreter (REPL) over the wireless network. MicroPython includes a web interface to REPL and file transfer. MicroPython supports a web interface that provides REPL (Read Execute Print Loop) access and file transfer capability. Before we can access WebREPL we need to bring up the ESP’s wireless access point.

The ESP family supports both station and access point WiFi operation and a wide variety of encryption algorithms for WiFI security. In this post we are just going to cover bringing up the ESP as an access point to get WebREPL running.

Connect to your ESP REPL via USB and serial terminal. See the previous post if you need to flash and configure your ESP for access via USB.

At the REPL prompt:

>>> import network
>>> ap_if = network.WLAN(network.AP_IF)
>>> ap_if.active(True)
>>> ap_if.ifconfig()
('192.168.4.1', '255.255.255.0', '192.168.4.1', '208.67.222.222')
>>> import webrepl_setup
WebREPL daemon auto-start status: disabled

Would you like to (E)nable or (D)isable it running on boot?
(Empty line to quit)
> E
To enable WebREPL, you must set password for it
New password (4-9 chars): upythoN
Confirm password: upythoN
Changes will be activated after reboot
Would you like to reboot now? (y/n) y

... ( bunch of build dependent output ) ...

WebREPL daemon started on ws://192.168.4.1:8266
Started webrepl in normal mode

ESP32 Notes: As of 7/2018 the stable 5/11/2018 ESP32 build “webrepl_setup” import didn’t work for me. However, the daily ESP32 build did work correctly.
See the previous post if you need to flash your ESP32 with a new build. Another difference between the ESP32 build and ESP8266 build, the ESP32 network came up as an Open network, the ESP8266 as secure. I’m not sure if this behavior will change in a future build, just something to be aware of. This is OK for quick prototyping but in a production environment you would want to configure WiFI security.

D1 Mini Lite AP

You should now see an ESP access point available. Don’t connect to it yet! We need to copy a few files from GitHub before we disconnect from the internet connected WiFi ( assuming you are connected to a WiFi access point).

The MicroPython WebREPL uses a WebSocket to communication so we need to download a web client to access the board. You can download the WebREPL client from GitHub here. Unzip the file and navigate to the directory containing “webrepl.html”

webrepl files

Switch your WiFi connection to the ESP_XXXX access point (AP).

Open “webrepl.html”  in your browser, chrome or firefox is recommended. The ip address is preset to match the MicroPython AP defaults. Click on the connect button. You should now have a working WebREPL session over WiFi to your ESP! You are no longer limited to a tethered connection! Freedom! WebREPL is great for updates, quick changes, and interactive testing. Here are a few useful command to test that your ESP and WebREPL are working correctly:

Webrepl Session

Congratulate yourself! You now have a working MicroPython ESP board with WiFi and wireless access to REPL and file transfer.  We showed some commands to explore the ESP MicroPython environment, checking on the amount for free memory, listing files, and accessing system information.

Resources:

https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/repl.html#webrepl-a-prompt-over-wifi
https://docs.micropython.org/en/latest/esp8266/library/index.html

CNC Fun at Ocean State Maker Mill

I attended an “Intro to CNC” class at the Ocean State Maker Mill on Saturday January 20th.

The class provided an overview of the CNC (Computer Numerical Control) process. The entire workflow: design, CAD, CAM, CNC set up, and finishing.  Many small CNC machines use the Dewalt 611 Router. So if you have experience using a router you are off to a good start. I used a router for some small home projects, but never really gave much thought to router bits other than the shape. There is more to router bits and end mills than I ever imagined: up cut, down cut, compression. Tomes have been written on the subject. Why? Because it turns out to be really important when you want to reliably produce a quality result. If you are yearning to learn more about bits, um, I mean, end mills, you can check out this article in Popular Woodworking.

When you have a robot doing the work for you it can’t always compensate when things go astray the way a human can. Attention to detail is a must: measure the thickness of your material, make sure it is fastened down securely, check clearances, calibrations. Safety first: ear and eye protection, dust mask, NO gloves !

After covering the general principles we got down to the specifics using a small sign as a sample project targeting the Inventables X-Carve CNC. The project was designed in the Inventables Easel free design system.

Matt setting up the project on the CNC:

Time to relax while the CNC does the work:

Almost done:

The final product:

Welcome

Welcome to my technology blog. I’m Robert “Jack” Babb, software engineer, maker, and technology enthusiast. At the moment I am working on a variety of microcontroller projects. On the bench we have: a Beaglebone Black, a Raspberry Pi, a Netduino, and an assortment of Arduinos.