It’s an exciting time to get involved with MicroPython, the re-implementation of Python 3 for microcontrollers and embedded systems. This practical guide delivers the knowledge you need to roll up your sleeves and create exceptional embedded projects with this lean and efficient programming language. If you’re familiar with Python as a programmer, educator, or maker, you’re ready to learn—and have fun along the way. Author Nicholas Tollervey takes you on a journey from first steps to advanced projects. You’ll explore the types of devices that run MicroPython, and examine how the language uses and interacts with hardware to process input, connect to the outside world, communicate wirelessly, make sounds and music, and drive robotics projects. Work with MicroPython on four typical devices: PyBoard, the micro:bit, Adafruit’s Circuit Playground Express, and ESP8266/ESP32 boards Explore a framework that helps you generate, evaluate, and evolve embedded projects that solve real problems Dive into practical MicroPython examples: visual feedback, input and sensing, GPIO, networking, sound and music, and robotics Learn how idiomatic MicroPython helps you express a lot with the minimum of resources Take the next step by getting involved with the Python community
Author(s): Nicholas H. Tollervey
Publisher: "O'Reilly Media, Inc."
Year: 2017
Language: English
Pages: 214
Chapter 1. What is MicroPython? MicroPython is a reimplementation of the Python programming language that targets microcontrollers and embedded systems. Microcontrollers are computers shrunk onto a single, very small chip. Embedded systems are computers that function within a larger mechanical or electrical system. Embedded systems often use microcontrollers. This book introduces, explores and explains MicroPython through four typical yet different devices1, all of which have a microcontroller at their core. Such devices are very different to other sorts of computer. Most computers contain lots of parts: memory, storage and processing are physically separate components containing various specialist chips. They may also contain additional parts for sound, graphics and networking capabilities. Such computers are significantly more powerful than the microcontroller based devices used in this book. This raises two important questions: Why use such small underpowered microcontroller based d
Chapter 1. What is MicroPython?
Chapter 2. PyBoard The PyBoard is the original target device for MicroPython. It can be purchased from the MicroPython website. Damien and Viktoriya’s company ship it to anywhere in the world. Figure 2-1. The original PyBoard is about the size of a large postage stamp. The board connects to your PC via a micro USB cable. This connection provides two ways to interact with the device: as a USB flash drive and as a serial-based Python REPL1. Note Perhaps the most common problem for people new to MicroPython is the wrong sort of micro USB cable. There are two sorts, those that provide just power (often for charging devices such mobile phones) and those that supply both power and data. It is this latter type of cable that you should use. If your board powers up (you should see an LED light up) but you don’t see it as a connected USB flash drive or cannot connect to the REPL, then you probably have the wrong type of lead. This caveat applies to all devices discussed in this book. The PyBoard
Chapter 2. PyBoard
Chapter 3. BBC micro:bit The BBC micro:bit is a simple yet powerful computing device for beginner programmers. It is small, cheap and easy to use. The British Broadcasting Corporation (BBC) created the device to promote digital creativity. In other words, the BBC want to foster the skills and confidence needed for anyone to make cool stuff with computers! This isn’t the first time the BBC have created a computing device for beginner programmers. In the 1980s I first learned to program on an 8-bit BBC microcomputer. Every school in the UK was given one and, luckily for me, my father was a head-teacher (school principal). One weekend he came home with various large boxes containing a monitor, the computer, leads and various manuals. His intention was to learn how to use the computer in school. However, it took only half an hour before my brother and I had managed to take over and get our young hands on the device (I was eight years old). Compared to today’s computers it wasn’t particular
Chapter 3. BBC micro:bit
Chapter 4. Adafruit Circuit Playground Express Star Trek is one of my favourite science fiction universes. Upon reflection, a big reason for its appeal is that Star Trek’s fictional technology is generally a force for good. It facilitates progress (technology is used to help others), a humane and open minded outlook (technology allows characters to live, work and communicate with each other despite physical, physiological and cultural differences) and fearless exploration of our universe (they fly around in space ships!). One of my favourite Star Trek technologies is the “tricorder” -- a device used by Mr.Spock, Bones and others to sense the environment, make computations and react to things with flashing lights or strange chirruping noises that obviously make perfect sense to citizens in the 23rd century. I’ve often thought it’d be cool to own such a device. With Adafruit’s Circuit Playground Express my dream has come true. Even better, it’s fun to imagine Mr.Spock programming such a
Chapter 4. Adafruit Circuit Playground Express
Chapter 5. ESP8266 / ESP32 The Internet of Things is a buzzword for embedded devices connected to the internet. Such devices are attached to all sorts of every-day objects making it easy to control or sense the object’s state via the attached embedded device. It means computers are in everything around us -- we are surrounded by computing devices that are uniquely identifiable and interconnected over the internet. Such objects turn the world inside out. In a sense, we no longer have objects that do stuff, we just have computers -- computers that light things, toast bread, water plants, keep time, air-condition buildings, fly in the sky, roll along rails and drive on roads. Such embedded computers allow us to do three things: Sense stuff -- collect and share data about their environment. Control stuff -- affect changes in the environment or device. Compute stuff -- work out what to do with data or signals such that they are autonomously useful. As Bruce Schneier points out1, you can thi
Chapter 5. ESP8266 / ESP32
Chapter 6. Thinking Embedded This chapter helps you think about generating embedded solutions to real-world problems. Why is this important? While microcontroller-based devices have been around for a long time, it is only recently that they have received broad attention due to the hype surrounding the Internet of Things (IoT). Many people have become interested in the opportunities available in this field, especially given some of the bombastic language in the media. Apparently, we are “standing at the precipice of the next transformative development, a world in which innovation becomes more human”, and where “technology will be embedded in hundreds of everyday objects we already use -- our cars, wallets, watches, umbrellas, even our trash cans”1. The antidote to such tiresome hype is reflective, grounded and critical thinking. Such an outlook is essential for identifying and evaluating opportunities to solve important problems with genuinely useful embedded solutions. In the Hitchhike
Chapter 6. Thinking Embedded
Chapter 7. Idiomatic MicroPython Why is Python such a popular language? What motivates so many to contribute to the Python community? Why is Python widely used as a teaching language? In the 1990s Guido van Rossum, the creator of Python and the project’s Benevolent Dictator for Life (BDFL), used Python as the basis for a project called “Computer Programming for Everybody: A Scouting Expedition for the Programmers of Tomorrow”. The opening paragraphs of the project’s proposal provide one clue to Python’s popularity: In the seventies, Xerox PARC asked: “Can we have a computer on every desk?” We now know this is possible, but those computers haven’t necessarily empowered their users. Today’s computers are often inflexible: the average computer user can typically only change a limited set of options configurable via a “wizard” (a lofty word for a canned dialog), and is dependent on expert programmers for everything else. We ask a follow-up question: “What will happen if users can program t
Chapter 7. Idiomatic MicroPython