Explore MicroPython through a series of hands-on projects and learn to design and build your own embedded systems using the MicroPython Pyboard and STM32 IoT Discovery kit
Key Features
• Learn how to customize and deploy the MicroPython kernel
• Design and implement drivers to interact with a variety of sensors and devices
• Build low-cost projects such as DIY automation and IoT-enabled weather stations
Book Description
With the increasing complexity of embedded systems seen over the past few years, developers are looking for ways to manage them easily by solving problems without spending a lot of time on finding supported peripherals. MicroPython is an efficient and lean implementation of the Python 3 programming language, which is optimized to run on microcontrollers. MicroPython Projects will guide you in building and managing your embedded systems with ease.
This book is a comprehensive project-based guide that will help you build a wide range of projects and give you the confidence to design complex projects spanning new areas of technology such as electronic applications, automation devices, and IoT applications. While building eight engaging projects, you'll learn how to enable devices to communicate with each other, access information over the internet, and store and retrieve data. The complexity will increase progressively as you work on different projects, covering areas such as time management, driver design, and sensor interfacing.
By the end of this MicroPython book, you'll be able to develop industry-standard embedded systems and keep up with the evolution of the Internet of Things.
What you will learn
• Develop embedded systems using MicroPython
• Build a custom debugging tool to visualize sensor data in real time
• Process and parse GPS and National Marine Electronics Association (NMEA) messages in MicroPython
• Detect objects using machine learning and MicroPython
• Discover how to minimize project costs and reduce development time
• Get to grips with gesture operations and parsing gesture data
Who This Book Is For
This book is for embedded systems developers or anyone who is interested in building embedded systems using MicroPython. Basic understanding of electronics and Python along with some MicroPython experience will be helpful.
Author(s): Jacob Beningo
Edition: 1
Publisher: Packt Publishing
Year: 2020
Language: English
Commentary: True PDF
Pages: 236
City: Birmingham, UK
Tags: Debugging; Multithreading; Python; Hardware; Android; MicroPython; Device Drivers; Gesture Recognition; asyncio; Testing; Scheduling; Embedded Systems; STM32; Do-It-Yourself; Object Detection
Cover
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Table of Contents
Chapter 01: Down the Rabbit Hole with MicroPython
The embedded software language menagerie
The case for MicroPython
Use cases for MicroPython
Use case #1 – DIY projects
Use case #2 – rapid prototyping
Use case #3 – low-volume production products
Evaluating whether MicroPython is right for you
Selecting the right development platform
Surveying the available architectures
Identifying boards of interest
Selecting a development board using a KT matrix
MicroPython development processes and strategies
Useful development resources
Summary
Questions
Further reading
Chapter 02: Managing Real-Time Tasks
Technical requirements
The need for real-time scheduling
Real-time system types
MicroPython scheduling techniques
Round-robin scheduling
Building a task manager using round-robin scheduling
Periodic scheduling using timers
Building a task manager using periodic scheduling
MicroPython thread mechanism
Advantages of using threads in MicroPython
Considerations when using threads in MicroPython
Building a task manager using threads
Event-driven scheduling
Cooperative scheduling
Cooperative multitasking using asyncio
Introducing asyncio
A cooperative multitasking blinky LED example
Going further with asyncio
Summary
Questions
Further reading
Chapter 03: Writing a MicroPython Driver for an I/O Expander
Technical requirements
The RGB pushbutton I/O expander project requirements
Hardware requirements
Software requirements
The hardware and software architecture design
The hardware architecture
Detailed hardware design
Selecting a pushbutton
The I/O expander schematic
The software architecture
Project construction
Building the hardware
I/O expander driver construction
RGB driver construction
RGB pushbutton driver construction
Testing and validation
Developing the test cases
Writing the application
Summary
Questions
Further reading
Chapter 04: Developing an Application Test Harness
Technical requirements
A brief introduction to test harnesses
Test harness requirements
Hardware requirements
Software requirements
Test harness design
The test harness hardware architecture
The test harness software architecture
Constructing the test harness
Writing the test harness scaffolding
Tests for the PCA8574
Running the test harness
Summary
Questions
Further reading
Chapter 05: Customizing the MicroPython Kernel Start Up Code
Technical requirements
An overview of the MicroPython kernel
Downloading the MicroPython kernel
MicroPython kernel organization
Becoming familiar with the STM32L475SE_IOT01A port
mpconfigboard.h
mpconfigboard.mk
pins.csv
stm3214xx_hal_conf.h
Navigating the startup code
Modifying the default GPIO initialization
Adding MicroPython modules to the kernel
The compilation process
Deploying the custom kernel to a board
The compiled output files
Programming the board
Testing the updated kernel
Summary
Questions
Further reading
Chapter 06: A Custom Debugging Tool to Visualize Sensor Data
Technical requirements
Debugging and visualizing embedded systems
Visualizer requirements
Hardware requirements
Software requirements
Visualizer design
The visualizer hardware architecture
The visualizer software architecture
Constructing the visualizer
Installing the project libraries
Setting up a serial data stream in MicroPython
Opening a COM port using command-line arguments
Creating a user interface with Matplotlib
Plotting the incoming data stream
Running the visualizer
Going further with visualizer enhancements
Summary
Questions
Further reading
Chapter 07: Device Control Using Gestures
Technical requirements
Introducing gesture controllers
Gesture controller requirements
Hardware requirements
Software requirements
Hardware and software design
The gesture hardware architecture
The detailed hardware design
The software architecture
Constructing the gesture controller
The APDS-9960 theory of operation
Analyzing gesture data
The APDS-9960 gesture driver
The APDS-9960 gesture class constructor
The APDS-9960 gesture class detect method
The gesture controller applications
Testing the gesture controller
Summary
Questions
Further reading
Chapter 08: Automation and Control Using Android
Technical requirements
The sensor node project requirements
Hardware requirements
Software requirements
Hardware and software design
The hardware architecture
The software architecture
Building a sensor node
Installing MicroPython on the ESP32
Setting up the ESP32 flash utilities
Programming the ESP32 with MicroPython
Testing MicroPython with LEDs
Setting up WebREPL
Simplifying application development with Anaconda
Installing uasyncio
Writing the sensor node application
Imports and supporting objects
LEDs and local control
socket_connect()
socket_receive()
The IotDevice class
Command parsing
The system status task
socket_send()
The main application
Testing the sensor node
The Android socket server
Commanding the sensor node
Testing the commands
Summary
Questions
Further reading
Chapter 09: Building an Object Detection Application Using Machine Learning
Technical requirements
Introducing machine learning
The need for intelligent systems
Machine learning from the cloud to the edge
Object detection requirements
Hardware requirements
Software requirements
Object detection design and theory
The CIFAR-10 and CIFAR-100 datasets
Machine learning modeling languages
TFLu
CMSIS-NN
The hardware
Implementing and testing object detection on the OpenMV camera
Getting familiar with OpenMV IDE
Implementing a pretrained CIFAR-10 network
Person detection with a TensorFlow model
Summary
Questions
Further reading
References
Chapter 10: The Future of MicroPython
The advancing MicroPython
The pyboard D-series
The pyboard D-series hardware
The pyboard D-series software
Controlling the boot sequence
Recovering from system faults
MicroPython in the real world
Example DIY/maker projects
Example professional projects
The future of MicroPython
Going further
References
Downloading and Running MicroPython Code
Assessments
Other Books You May Enjoy
Index