2020-05-17

Installing CircuitPython on Arduino MKR WIFI

Part I: Installing CircuitPython

In this part, we will be flashing two bootloaders sequentially onto MKR.

1. Download and install the latest Arduino IDE https://www.arduino.cc/en/Main/Software
2. Open the IDE. Go to Tools -> Boards -> Boards Manager. In Boards Manager, search "Arduino SAMD Boards (32-bits AMR Cortex-M0+)" and then click Install. After installation, select Tools -> Boards -> MKR WIFI 1010
3. Plug-in MKR WIFI into the computer via a USB cable, and select Tools -> Port -> MKR WIFI or the only USB device when MKR is plugged in.
4. Download latest INO for MKR Zero's bootloader from https://github.com/adafruit/uf2-samdx1/releases to your computer, e.g., https://github.com/adafruit/uf2-samdx1/releases/download/v3.9.0/update-bootloader-mkrzero-v3.9.0.ino
5. Open the INO file just downloaded and upload it to MKR. You should see something like this on your Arduino IDE:

Sketch uses 21112 bytes (8%) of program storage space. Maximum is 262144 bytes.
Global variables use 3464 bytes of dynamic memory.
Atmel SMART device 0x10010005 found
Device : ATSAMD21G18A
Chip ID : 10010005
Version : v2.0 [Arduino:XYZ] Mar 19 2018 09:45:14
Address : 8192
Pages : 3968
Page Size : 64 bytes
Total Size : 248KB
Planes : 1
Lock Regions : 16
Locked : none
Security : false
Boot Flash : true
BOD : true
BOR : true
Arduino : FAST_CHIP_ERASE
Arduino : FAST_MULTI_PAGE_WRITE
Arduino : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
done in 0.823 seconds

Write 21112 bytes to flash (330 pages)

[===== ] 19% (64/330 pages)
[=========== ] 38% (128/330 pages)
[================= ] 58% (192/330 pages)
[======================= ] 77% (256/330 pages)
[============================= ] 96% (320/330 pages)
[==============================] 100% (330/330 pages)
done in 0.128 seconds

Verify 21112 bytes of flash with checksum.
Verify successful
done in 0.018 seconds
CPU reset.


6. MKR will restart. If not, press the reset button. A USB storage device called MKRZEROBOOT shall pop-up on your computer now. If a file called
CURRENT.UF2
is there, then you are good.

7. Download the CircuitPython image for MKR from https://circuitpython.org/board/arduino_mkrzero/, the UF2 file. Then copy it to the MKRZEROBOOT device. Then the MKR will restart and the new USB storage device's name will become CIRCUITPY. If it doesn't restart automatically, press the reset button.


Part II: Play around with CircuitPython

1. Download and install Mu editor. For Windows and Mac, go to https://codewith.mu/en/download . For Linux, or Python on other platforms, you can simply use pip: pip3 install mu-editor --user Then start the Mu editor.

2. Upon initial start, select "Adafruit CircuitPython". Then you see an blank editor. Now, click the "Serial" button at the top of the window. And you shall see the "Adafruit CircuitPython REPL" box. Click in it, and press any key to activate the Python console. Then, you can enjoy the Python shell.

3. To run a script, in the Mu editor, paste the code below and save it as a file on your CIRCUITPY storage device and make sure it is the only file there. After saving, the MKR will restart on its own -- if not, press the reset button. And you shall see the orange LED blinking.

import board
import digitalio
import time

led = digitalio.DigitalInOut(board.D6)
led.direction = digitalio.Direction.OUTPUT

while True:
print("Hello, CircuitPython!")
led.value = True
time.sleep(1)
led.value = False
time.sleep(1)


Note that the interactive mode Python shell and the scripting mode (i.e., running code from a script file) cannot coexist.

No comments: