REPL - Workflow
00:00 MicroPython Workflow. If you’re familiar with Arduino or PIC programming, then you might expect to talk first about compilers, development environments, and the toolchain. However, MicroPython is a little different at first glance.
00:15 There are three options that you’re going to take a look at here. Firstly, a direct connection to the MicroPython board and using the REPL. Secondly, using file transfer to put your code onto the board to run it.
00:30 Thirdly, integration with an IDE. The IDE will connect directly to the board, allowing you to run a REPL on it in many cases, and also allowing you to access the file storage which the board offers.
00:43 REPL. With MicroPython, the language may have come pre-installed on your hardware, and you may have the option of working with it interactively. This harks back to the golden era of home computers, such as the Commodore Vic 20 and 64, Sinclair’s ZX81 and Spectrum, and the BBC Micro, where the initial access to the computer is via a language.
01:04 That would have been BASIC in the case of these 1980s machines, and the MicroPython REPL for the boards we will look at here. Accessing the REPL will typically be performed using a serial connection over USB.
01:17 How this is achieved in practice depends on the operating system, so you’re going to see how to do it on macOS, on Linux, and also on Windows. Firstly, using macOS. Once the board is connected, finding the device’s serial port is necessary.
This is done in a terminal using the following command, and while there are two possible candidates, the one that’s wanted is the one on the right. Next, using the
screen command to connect to the board is as simple as issuing this command seen here.
02:11 So here, you can see the macOS desktop and at the top right, the Pyboard’s flash drive has been mounted. We want to connect to it via serial, so the first step is to find out which serial port the Pyboard has presented itself as. Opening up a new terminal… and listing the possible devices…
04:01 Accessing the REPL via USB serial in Windows is slightly different, but we still have to find the device serial port, and that is done in Device Manager. Here, you can see the USB Serial Device is presenting as COM4 to the system.
04:17 Secondly, connecting to the REPL is done using third-party software, such as PuTTY. Here, the PuTTY settings have been specified to suit the COM port which we previously saw, and now you’re going to see that in action on Windows.
04:33 Here we are on the Windows desktop, and the first task is to find the serial port. On Windows, you can do that by holding down the Windows key and tapping X, and then selecting Device Manager. Once Device Manager appears, you can then go down to Ports and expand that, and if you’ve installed the driver, you should see a USB Serial Port. If not, you’ll need to install the driver before going any further.
As you can see, here on this machine we’re on COM6, so that’s the information we need. And now we’re going to run PuTTY. And to get PuTTY to connect, it’s as easy as picking Serial, changing to the appropriate COM port, and then entering the Speed. In this case,
115200, and clicking Open.
Now we can spend a bit of time looking at some of the features which the M5Stick gives us. First things first, from
m5stack we’re going to import the
lcd module. This gives access to the LCD screen, which we can clear using the
Next, it’s our duty to print
"Hello World!", so let’s start out using the
lcd.print() command with the string
"Hello", followed by two coordinates which set the top left of the text on the screen.
06:21 The foreground color can be set with the following command. It takes a 24-bit hexadecimal number in the format red, green, and blue, with two digits for each. Here, we will set maximum red, and no green or blue.
And now repeating the
"World!" line, we’ll reprint that text with a new foreground and background color. There’s plenty more to explore with the M5Stick, but that’s a quick example of how to use it via the REPL from Windows.
Become a Member to join the conversation.