Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MicroPython Cookbook

You're reading from   MicroPython Cookbook Over 110 practical recipes for programming embedded systems and microcontrollers with Python

Arrow left icon
Product type Paperback
Published in May 2019
Publisher Packt
ISBN-13 9781838649951
Length 452 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Marwan Alsabbagh Marwan Alsabbagh
Author Profile Icon Marwan Alsabbagh
Marwan Alsabbagh
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Getting started with MicroPython 2. Controlling LEDs FREE CHAPTER 3. Creating Sound and Music 4. Interacting with Buttons 5. Reading Sensor Data 6. Button Bash Game 7. Fruity Tunes 8. Let's Move It, Move It 9. Coding on the micro:bit 10. Controlling the ESP8266 11. Interacting with the Filesystem 12. Networking 13. Interacting with the Adafruit FeatherWing OLED 14. Building an Internet of Things (IoT) Weather Machine 15. Coding on the Adafruit HalloWing Microcontroller 16. Other Books You May Enjoy

Flashing the microcontroller firmware

In this recipe, we will show how to flash the firmware on the Circuit Playground Express with the latest CircuitPython firmware. There are two reasons to this before you start working with this device. First, the device also supports the Microsoft MakeCode programming environment and flashing the device with the CircuitPython firmware prepares it for use with the Python language.

Second, the CircuitPython language is under constant development, with a release every few months, so it is a good idea to update the firmware from time to time to load the latest release of the language onto the board.

Getting ready

This chapter's introduction gives us directions on how to buy the Circuit Playground Express, which will be required for all the recipes in this chapter. A USB micro B cable and a computer running macOS, Windows, or Linux will also be required.

How to do it...

Let's look at the following steps:

  1. Download the latest CircuitPython Circuit Playground Express UF2 file (https://github.com/adafruit/circuitpython/releases/latest). The name of the UF2 file for version 3.1.2 of CircuitPython is adafruit-circuitpython-circuitplayground_express-3.1.2.uf2. For each release of CircuitPython, there are many different uf2 files for different supported microcontrollers. Make sure that you download the file for the Circuit Playground Express device.
We will use the latest stable version of CircuitPython in this recipe, which is currently 3.1.2.
  1. Connect the USB cable to the Circuit Playground Express and the computer.
  2. Double-click the reset button located at the center of the board. If all goes well, you will see all the LEDs turn green; otherwise, there is most likely an issue with the USB cable being used. In some instances, if a double-click doesn't work, try a single click of the reset button.
  1. You will see a new disk appear called CPLAYBOOT:
  1. Copy the UF2 file into this drive.
  2. Once the UF2 file has been fully written to the device, the firmware will be updated and a new drive will appear, called CIRCUITPY:

Now, our Circuit Playground Express can be used.

How it works...

Traditionally, special software has had to be installed and used to handle the delicate process of flashing a microcontroller. Microsoft developed the UF2 method, which greatly simplifies the process by not requiring any special software or command-line execution to flash the microcontroller.

Once the board is placed into the bootloader mode, it will then expect a UF2 file to be saved to it. When the UF2 is copied to the drive, the microcontroller will detect that the file copy has been completed and then automatically proceed to flash the microcontroller and restart the device, at which point the device is reattached and ready to be used.

The UF2 file format can be found athttps://github.com/Microsoft/uf2.

There's more...

The UF2 approach to flashing microcontroller firmware makes the process easier and faster compared to previous approaches. Not all MicroPython boards support the UF2 method and so require the more involved approach of installing special software to do the firmware flashing. The exact process and software required varies between different boards and manufactures.

When you use this flashing software, it will frequently require that you know the exact name of the serial device that the device appears as on your computer. The naming of these devices varies between Windows, Linux, and macOS. This type of software is usually required to be run in the Terminal, so you'll have to have some command-line knowledge to inter with it. For all these reasons, the use of UF2 with supported devices such as the Circuit Playground Express is the preferred way of starting your experimentation with MicroPython.

See also

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime