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

Using Mu to access the REPL

Mu is an easy-to-use graphical code editor written in Python that runs on Windows, macOS, Linux, and the Raspberry Pi. In this recipe, we will learn how to install Mu and use it to access the REPL on the Circuit Playground Express.

Getting ready

This recipe requires Python and pip to be installed on the computer. The Mu editor will be installed using the pip command, so this recipe can optionally be run within virtualenv.

How to do it...

Let's have a look at how to do this:

  1. Execute the following pip3 install mu-editor command to install the Mu editor.
  2. Run the mu-editor command to start the editor.
  3. The first time you run the editor, it will ask which mode it should run in. On the following screenshot, select the Adafruit CircuitPython mode:
  1. Click the Serial button on the toolbar to open a REPL session with the device.
  2. On Linux systems, if a Cannot connect to device error appears, then exit the editor and start it again with the sudo /full/path/to/mu-editor command, where the absolute path to the editor is given.
  3. Once a connection is successfully made to the device, you can test the REPL by evaluating the 1+1 expression, which should produce output like the following screenshot:

How it works...

When you click on the Serial button in the Mu editor, it will attempt to open a serial connection to the board. If successful, it captures your input, sends it the device, and displays the output just as a typical Terminal emulator would.

The beauty of this application is that it works on all the major desktop OSes and automatically finds the correct device address without the need to manually specify it, as is required by your typical Terminal emulators. It also has a very simple and approachable layout, making it easy to use for first-time users to connect to microcontrollers.

There's more...

The Mu editor is a great graphical application to begin with when you first start working with MicroPython. Its simple and intuitive design makes it easy to get productive fast and makes it fun to explore its different features. Beyond its REPL features, it also has the main part of the Screen, which can be used to edit and save Python scripts. It has code-editing features such as code completion and will show helpful popups with details on a function's accepted arguments and documentation on what the function does.

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