Wi-fi MicroPython Programming with Thonny

I’ve been taking part in with a couple of MicroPython tasks just lately on a number of other embedded platforms, together with a few ESP32 WiFi modules. There are more than a few techniques to program those modules:

  • Use a serial terminal and (*10*)ampy (maintained via [devxpy] since being dropped via Adafruit in 2021).
  • When you use Pycom forums or WiFy firmware, there are the pymakr plugins for Atom and Visible Studio.
  • When you want the command-line like me, there’s rshell via one of the highest MicroPython participants [Dave Hylands].

For over a yr, I’ve been reasonably pleased with rshell till I got to work on those wi-fi nodes. Being lazy, I need to tinker with my ESP32 modules from the settee, no longer drag my computer into the kitchen or balcony to plug up a USB cable. Can’t I paintings with them wirelessly?

Neatly, you’ll be able to use (*2*)WebREPL. Whilst its useful, it simply didn’t strike my fancy for some explanation why. [Elliot] discussed in (*1*)a up to date podcast that he’s the use of telnet to get right of entry to his wi-fi nodes, however he’s the use of esp-link on an ESP8266, which means that throwing some other chip into the combo.

The Thonny IDE

I had all however given up when unintentionally I noticed this video at the Dronebot Workshop channel about working MicroPython at the new Raspberry Pi Pico forums. Invoice was once the use of Thonny, a Python IDE this is in style within the training group. Thonny was once offered in 2021 via Aivar Annamaa of the College of Tartu in Estonia. Thonny was once designed to deal with not unusual problems noticed all over six years of educating Python programming categories to newcomers. When you learn concerning the mission and its construction, you’ll see that he’s put numerous effort into making Thonny, and it presentations.

Leaning about Thonny were given me curious, and after slightly digging I found out that it has WebREPL improve for MicroPython proper out-of-the-box. Even supposing it is a new function and categorised as experimental, I discovered it fairly strong to make use of and greater than ok for house lab use.

Set up and Connection

Directions are obviously given at the mission’s website online. There’s a downloader hyperlink on the best of the web page for Home windows. For Linux and Mac merely doing sudo apt set up thonny or brew set up thonny was once all I wanted. When you have a Raspberry Pi, you’ll to find Thonny is pre-installed — model 3.3.3 was once discovered on a up to date Pi 4 in my lab. On an older Pi 3 then again, Thonny was once too outdated and easily reinstalling it didn’t paintings for me. Doing a sudo apt replace, sudo apt improve, after which reinstalling Thonny led to the newest model 3.3.6.

For some explanation why, the Thonny discovered within the Ubuntu 20.04 and Debian Buster package deal repositories additionally weren’t contemporary sufficient. Slightly than development from supply, I used the supplied Linux set up script that downloads and installs the newest free up.

With a purpose to hook up with a module, you’ll use the Run -> Choose interpreter... menu. Right here you pick out which form of module to make use of, and which interface (USB or WebREPL). Word that it’s a must to attach on your module over USB first and be sure that WebREPL is enabled in boot.py. That is the standard approach of enabling WebREPL basically — in case your module already has WebREPL setup, you don’t want to alternate anything else. Fill within the WebREPL URL and password — you must attach and be excellent to head.


(*3*)right here). The e method East, and different compass issues like se will also be specified as smartly. For the programs I examined, the configuration dossier will also be discovered within the following puts:

  • Raspi, Ubuntu, Debian
  • Mac
  • Home windows

I had no issues the use of the REPL manually, however I found out a subject while you get started checking out self-starting programs with eternally loops. When you don’t seem to be cautious, your application’s primary loop can save you you from regaining REPL regulate. The answer is to ensure your application sleeps for a number of milliseconds in the primary loop. I examined with 100 ms (see (*6*)right here) and was once all the time in a position to regain regulate. This shouldn’t be a subject in maximum house sensor programs, the place the module would possibly sleep for tens of mins between readings.

Through default, a Thonny set up doesn’t make itself visual for command line execution. At the computer systems I examined, you’ll to find the Thonny executable within the following places:

  • Raspi /usr/bin/thonny
  • Ubuntu, Debian (put in by the use of installer script)
  • Mac
  • Home windows

A couple of Modules and Circumstances

(*4*)Thonny Modules Variety Record

Thonny can improve numerous other modules. However if you wish to hook up with a couple of modules on the identical time, you wish to have to run a number of circumstances of Thonny concurrently. Through default, best one example is authorized. Within the Equipment -> Choices -> Common menu, untick the Permit best unmarried Thonny example checkbox.

I realized one quirk on MacOS, then again. For some explanation why, unchecking that choice doesn’t paintings when launching the app from the GUI. There’s a workaround — you’ll be able to get a couple of circumstances working should you get started them from the command line.

Yet one more annoyance — via default, Thonny will use the former interpreter / connection when beginning up. That is cheap conduct, however reasons a hiccup when speaking to a couple of forums concurrently. Simply forget about the plethora of error messages when Thonny example #2 tries to connect with an already hooked up module, and use the menus to connect with the second one tool. There it seems that isn’t any command line argument for a particular connection, however I’ve an inquiry pending at the GitHub mission web page.

Tip of the Iceberg

I’ve best targeted at the WebREPL connectivity side of Thonny right here, a capability which appears to be unusual in different MicroPython programming workflows. However this best scratches the skin of Thonny. Beneath the hood, it has so much to supply this is hidden while you first open it.

And whilst I’ve been the use of its MicroPython mode of operation, Thonny was once designed to assist scholars who’re finding out to put in writing and debug “customary” Python systems working on desktop computer systems. When you incessantly paintings in Python, I might inspire you to take a look at those sides of this system — an object inspector, debugger, single-stepping, and an entire slew of different helpful equipment.

Thonny could also be a multi-platform device. Whilst getting ready this newsletter, I examined it on MacOS, Home windows 10, Debian, Ubuntu, and Raspberry Pi computer systems and not using a issues. The mission is open-sourced underneath the MIT License.

On the very least, Thonny is a smart resolution for faraway MicroPython programming of WiFi embedded modules. Test it out and provides it a take a look at run, particularly should you’re lazy like me.