Here are resources for more information about the IDEs discussed:
IDE - Workflow
00:13 The precise definition of IDE will vary from person to person, so here we will look across the spectrum of available options from an online browser-based solution through to heavyweight dedicated IDEs.
00:26 The most important element of IDE use with MicroPython is integration of the board into the IDE. What is desirable is a seamless integration of the board into the workflow—allowing creation, saving, and running of the code to be as easy as your normal Python operations.
00:44 In some cases, this provides a plug-and-play experience. In others, this will involve more setup. The exact set of features is dependent on what is available in the IDE, as you’ll see next. Micro:Bit Online.
The online Micro:Bit Python editor provides useful functions for the Micro:Bit. In addition to the Python editor, it also provides the ability to download the code as a
.hex file, which can be dragged to the Micro:Bit for ingestion by it, and running on subsequent boots of the system. When used with a Chrome-based browser, it also offers the ability to connect to a REPL via WebUSB and flash code directly to the Micro:Bit, as you will see next.
01:30 As you can see, we’re at the Micro:Bit editor online. It’s possible to connect to the Micro:Bit just by clicking the Connect button. We pick the device—in this case, there’s only one option—and click Connect, and now we’re ready to either disconnect or—more importantly—flash the code.
02:04 And as you can see, straight away, it’s already running on the Micro:Bit, and that text is scrolling. Clicking Open Serial will allow us to open a REPL just by clicking in the window and sending Control + C. As you can see, the code has stopped executing on the Micro:Bit, and we now have a REPL, as we’ve seen previously.
02:53 There’s also useful code snippets, which can be really helpful if you’re finding some of the syntax just escapes your memory at the moment. So, there’s some boilerplate for creating classes, including—usefully—a reminder to create a docstring for any class that you create—something you should be doing anyway, but we all forget now and again.
03:15 Mu. Nicholas Tollervey’s Mu editor is presented as a beginner-friendly Python editor, but that belies the growing support that it has for hardware-based devices, such as Micro:Bit, ESP, and as you’ll see here, CircuitPython.
03:32 So here you can see Mu running in Linux, but it will look very much the same whether you’re running it on Windows, Linux, or macOS. And currently, as you can see at the bottom right of the screen, it is in Python mode, but that is soon changed easily. If you insert a new device which it supports, it will often also detect it.
03:52 As you can see here, it’s detected that a CircuitPython device has been inserted and asked if we want to change mode, so we will. However, if that doesn’t happen, you can click on Mode and then pick the appropriate mode from this screen here.
As you’ll see onscreen, the device is a CircuitPlayground Express, and it’s running some demo code which takes the NeoPixels through a variety of different colors in different modes. CircuitPython devices run
code.py, which we can load easily in Mu.
The device is presented as a flash drive, and loading up
code.py shows us the code that’s running. This particular code has four different modes, and if we change them to not be played, and then save, the device resets and reloads the code, so now it’s showing us just the
One quick and easy way to get this to run is to copy it from this tab into
code.py. Paste it in, and then save it to get that running. As you can see, the NeoPixels are now off, and if we open up the Serial window, we’ll see that the CircuitPlayground Express is reporting the temperature and light readings to us as a printed-out tuple.
06:34 Being able to quickly plot data without having to implement an API can make application development much quicker. In this case, it’s easy to see a spike in the light data, which probably has something to do with the frequency of the mains lighting that I’m using. Spikes like these can typically be removed by averaging the values over a few samples.
06:58 Thonny. As with Mu, Thonny is described as a Python IDE for beginners, and once again, this belies its usefulness with MicroPython. It has the ability to select the interpreter that’s being used with Micro:Bit, ESP, generic MicroPython, and CircuitPython all being available.
07:17 Let’s take a look at it running on macOS with an ESP32-based board. Here, you can see Thonny running on the desktop, and if you want to know more details about the editor, Real Python has a full course available. For MicroPython, we need to go to the Run menu and then pick Select Interpreter… Now, it’s the case of picking the appropriate interpreter type—in this case, ESP32—and then picking the port if necessary. Here, M5Stack has already been selected.
07:51 Any other suitable ports will be available. Once you do this, you can hit OK, and hopefully, you should drop into a REPL. If you don’t, try pressing Control + C a couple of times, and generally, the REPL will appear.
We can now see that we’re running on the ESP32 from the information given in the REPL, and hitting
help() gives us useful information, including sample code for a basic WiFi configuration and also Control commands.
08:22 The Files area gives us access to the files which are stored on the MicroPython device, and in the case of this M5Stick, there are apps which appear in the device’s menu. Opening the file up allows us to edit it, change things such as—let’s say—the color here,
09:26 Thonny’s IDE approach with built-in file management gives you a complete solution for developing on MicroPython devices that it supports. VS Code. Microsoft’s Visual Studio Code has become extremely popular in the last few years, and there’s a wide range of plugins available for it, including several for MicroPython.
09:49 Each will be different in their implementation, but next, you’ll see how to install one and get up and running in the shortest time. Here you can see we are in VS Code, and the first thing to do is to install the MicroPython extension.
10:03 So, extensions are summoned with Control or Command + Shift + X and then you can search for the extension you want. Here, searching for “micropython” leads us to see quite a few which are available.
10:43 The first one is to create a new MicroPython project, and the second one is to connect to the device. So, first things first, let’s create a MicroPython project, and let’s create a new one. Let’s make it blank.
11:45 Now that the code’s complete, we can save it. And now we need to pick our MicroPython device, which is done by clicking the little plug icon. And you’ll be familiar with this, having seen this previously, so we pick the usbmodem and we can see we have a connection to our device. Close that window.
12:21 And there you can see our LED flash program is running, we see the printed feedback from it, and we can use this workflow to continue developing throughout the program’s lifecycle. We can stop the code running by clicking stop,
Become a Member to join the conversation.