Book Image

MicroPython Cookbook

By : Marwan Alsabbagh
Book Image

MicroPython Cookbook

By: Marwan Alsabbagh

Overview of this book

MicroPython is an open source implementation of Python 3 that runs in embedded environments. With MicroPython, you can write clean and simple Python code to control hardware instead of using complex low-level languages such as C and C++. This book guides you through all the major applications of the MicroPython platform to build and program projects that use microcontrollers. This MicroPython book covers recipes that will help you experiment with the programming environment and hardware programmed in MicroPython. You'll find tips and techniques for building a variety of objects and prototypes that can sense and respond to touch, sound, position, heat, and light. This book will take you through the uses of MicroPython with a variety of popular input devices and sensors. You'll learn techniques to handle time delays and sensor readings, and apply advanced coding techniques to create complex projects. As you advance, you'll deal with Internet of Things (IoT) devices and integration with other online web services. In addition to this, you'll use MicroPython to make music with bananas and create portable multiplayer video games that incorporate sound and light animations into the gameplay. By the end of this book, you'll have mastered the tips and tricks to troubleshoot your development problems and take your MicroPython project to the next level.
Table of Contents (17 chapters)

What this book covers

Chapter 1, Getting Started with MicroPython, introduces the Adafruit Circuit Playground Express microcontroller and teaches the core skills for using MicroPython on this hardware.

Chapter 2, Controlling LEDs, covers methods of controlling NeoPixel LEDs, the color of the lights, and how to create animated light shows by controlling the timing of light changes on the board.

Chapter 3, Creating Sound and Music, discusses methods of how to make sounds and playmusic on the Adafruit Circuit Playground Express. Topics such as making the board beep at a certain sound frequency and playing music files using the WAV file format and the board's built-in speakers will be covered.

Chapter 4, Interacting with Buttons, shows methods of interacting with the buttons and touch pads that come on board with the Adafruit Circuit Playground Express. The basics of detecting when a button is pressed or not, as well as advanced topics, such as fine tuning the touch threshold of the capacitive touch pads, will be discussed.

Chapter 5, Reading Sensor Data, introduces methods of reading sensor data from a number of different types of sensors, such as temperature, light, and motion sensors.

Chapter 6, Button Bash Game, guides us to create a two-player game called Button Bash that you can play directly on the Circuit Playground Express using the push buttons, NeoPixels, and built-in speakers.

Chapter 7, Fruity Tunes, explains how to create a musical instrument with the Adafruit Circuit Playground Express and some bananas. Touchpads will be used to interact with the bananas and play different musical sounds each time you touch a different banana.

Chapter 8, Let's Move It, Move It, introduces the Adafruit CRICKIT hardware add-on that will help control motors and servos through our Python scripts; in particular, their speed, rotational direction, and angle will be controlled through these scripts.

Chapter 9, Coding on the micro:bit, covers methods of interacting with the micro:bit platform. How to control its LED grid display and interact with the buttons that come on board will be discussed.

Chapter 10, Controlling the ESP8266, introduces the Adafruit Feather HUZZAH ESP8266 microcontroller, and discusses its features and strengths compared to other microcontrollers. Topics such as connecting to Wi-Fi networks, using the WebREPL, and transferring files over Wi-Fi will be covered.

Chapter 11, Interacting with the Filesystem, discusses a number of topics related to the operating system (OS), such as listing files, removing files, creating directories, and calculating disk usage.

Chapter 12, Networking, discusses how to perform a number of different network operations, such as DNS lookups, implementing an HTTP client, and HTTP servers.

Chapter 13, Interacting with the Adafruit FeatherWing OLED, introduces the Adafruit FeatherWing OLED hardware add-on, which can be attached to the ESP8266 to add a display to an internet-connected microcontroller, to display display text graphics and interact with the user using the included three hardware push buttons.

Chapter 14, Building an IoT Weather Machine, explains how to create an IoT device that will retrieve weather data and show it to the user at the press of a button from the IoT device itself.

Chapter 15, Coding on the Adafruit HalloWing, introduces the Adafruit HalloWing microcontroller, which comes with a 128x128 full-color Thin-Film Transistor (TFT) display built into it, providing the ability to display rich graphical images on the microcontroller.