Introduction
Mu is a simple code editor that works with the Adafruit CircuitPython boards. It is written in Python and works on Windows, MacOS, Linux and Raspberry Pi. The serial console is built right in so you get immediate feedback from your board’s serial output! This post closely follows the Adafruit tutorial Installing the Mu editor.
Install Mu
Download Mu from https://codewith.mu. in MacOS double click the diskimage (.dmg), then drag the app Mu Editor to the Applications folder.
First startup
The first time you start Mu, you will be prompted to select your mode - you can always change your mind later. For now please select CircuitPython.
If you have the disk (Volume) called CIRUITPY mounted, Mu editor will automatically detect it. Otherwise it will ask for a local directory for storing the python modules.
For more details on installeing and starting up Mu editor, please see the Arduino page on Installing the Mu Editor.
How it works
When you plug a board into your computer with CircuitPython already installed, the board shows up on your computer as a USB drive called CIRCUITPY.
Each time the board is powered up (or you save a new file to the disk CIRCUITPY) the python module code.py is executed. Thus you can start by making simple changes to code.py for testing how CircuitPython works. For more details see the Arduino page on The CIRCUITPY Drive.
A first python module
Adafruit Feather nRF52840 Express comes with 4 built-in LED lights. To actually write a python script (or module) that affects the board go to the Arduino tutorial Creating and Editing Code. Copy the following code as suggested on that page:
import board
import digitalio
import time
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
Paste this code, using the Mu editor interface and save it as code.py and save it to the board mounted as CIRCUITPY (you have to overwrite the existing file). When the script file is uploaded, the red LED next to the usb port on the Feather board should start blinking. For details on the imports and functions, please see the Arduino tutorial Creating and Editing Code.
Read-Evaluate-Print-Loop (REPL)
When working more with CircuitPython you will encounter the abbreviation REPL. To access REPL in the Mu editor, click the button to open a REPL window below the code window of the Mu editor. Now you can start and stop the execution of the code.py.
ctrl+C to stop the execution
ctrl+D to restart the execution
For more details on how to use the _REPL, please see the Arduino tutorial The REPL.