MicroPython Projects

Book description

Explore MicroPython through a series of hands-on projects and learn to design and build your own embedded systems using the MicroPython Pyboard, ESP32, the STM32 IoT Discovery kit, and the OpenMV camera module.

Key Features

  • Delve into MicroPython Kernel and learn to make modifications that will enhance your embedded applications
  • Design and implement drivers to interact with a variety of sensors and devices
  • Build low-cost projects such as DIY automation and object detection with machine learning

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 seven engaging projects, you'll learn how to enable devices to communicate with each other, access and control devices over a TCP/IP socket, and store and retrieve data. The complexity will increase progressively as you work on different projects, covering areas such as driver design, sensor interfacing, and MicroPython kernel customization.

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
  • 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
  • Learn how to customize and deploy the MicroPython kernel
  • Explore the techniques for scheduling application tasks and activities

Who this book is for

If you are an embedded developer or hobbyist looking to build interesting projects using MicroPython, this book is for you. A basic understanding of electronics and Python is required while some MicroPython experience will be helpful.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. MicroPython Projects
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Down the Rabbit Hole with MicroPython
    1. The embedded software language menagerie
    2. The case for MicroPython
      1. Use cases for MicroPython
        1. Use case #1 – DIY projects
        2. Use case #2 – rapid prototyping
        3. Use case #3 – low-volume production products
    3. Evaluating whether MicroPython is right for you
    4. Selecting the right development platform
      1. Surveying the available architectures
      2. Identifying boards of interest
      3. Selecting a development board using a KT matrix
    5. MicroPython development processes and strategies
    6. Useful development resources
    7. Summary
    8. Questions
    9. Further reading
  7. Managing Real-Time Tasks
    1. Technical requirements
    2. The need for real-time scheduling
      1. Real-time system types
    3. MicroPython scheduling techniques
      1. Round-robin scheduling
        1. Building a task manager using round-robin scheduling
      2. Periodic scheduling using timers
        1. Building a task manager using periodic scheduling
      3. MicroPython thread mechanism
        1. Advantages of using threads in MicroPython
        2. Considerations when using threads in MicroPython
        3. Building a task manager using threads
      4. Event-driven scheduling
      5. Cooperative scheduling
    4. Cooperative multitasking using asyncio
      1. Introducing asyncio
        1. A cooperative multitasking blinky LED example
        2. Going further with asyncio
    5. Summary
    6. Questions
    7. Further reading
  8. Writing a MicroPython Driver for an I/O Expander
    1. Technical requirements
    2. The RGB pushbutton I/O expander project requirements
      1. Hardware requirements
      2. Software requirements
    3. The hardware and software architecture design 
      1. The hardware architecture
      2. Detailed hardware design
      3. Selecting a pushbutton
      4. The I/O expander schematic
      5. The software architecture
    4. Project construction
      1. Building the hardware
      2. I/O expander driver construction
      3. RGB driver construction
      4. RGB pushbutton driver construction
    5. Testing and validation
      1. Developing the test cases
      2. Writing the application
    6. Summary
    7. Questions
    8. Further reading
  9. Developing an Application Test Harness
    1. Technical requirements
    2. A brief introduction to test harnesses
    3. Test harness requirements
      1. Hardware requirements
      2. Software requirements
    4. Test harness design
      1. The test harness hardware architecture
      2. The test harness software architecture
    5. Constructing the test harness
      1. Writing the test harness scaffolding
      2. Tests for the PCA8574
    6. Running the test harness
    7. Summary
    8. Questions
    9. Further reading
  10. Customizing the MicroPython Kernel Start Up Code
    1. Technical requirements
    2. An overview of the MicroPython kernel
      1. Downloading the MicroPython kernel
      2. MicroPython kernel organization
      3. Becoming familiar with the STM32L475SE_IOT01A port
        1. mpconfigboard.h
        2. mpconfigboard.mk
        3. pins.csv
        4. stm3214xx_hal_conf.h
    3. Navigating the startup code
      1. Modifying the default GPIO initialization
    4. Adding MicroPython modules to the kernel
      1. The compilation process
    5. Deploying the custom kernel to a board
      1. The compiled output files
      2. Programming the board
      3. Testing the updated kernel
    6. Summary
    7. Questions
    8. Further reading
  11. A Custom Debugging Tool to Visualize Sensor Data
    1. Technical requirements
    2. Debugging and visualizing embedded systems
    3. Visualizer requirements
      1. Hardware requirements
      2. Software requirements
    4. Visualizer design
      1. The visualizer hardware architecture
      2. The visualizer software architecture
    5. Constructing the visualizer
      1. Installing the project libraries
      2. Setting up a serial data stream in MicroPython
      3. Opening a COM port using command-line arguments
      4. Creating a user interface with Matplotlib
      5. Plotting the incoming data stream
    6. Running the visualizer
      1. Going further with visualizer enhancements
    7. Summary
    8. Questions
    9. Further reading
  12. Device Control Using Gestures
    1. Technical requirements
    2. Introducing gesture controllers
    3. Gesture controller requirements
      1. Hardware requirements
      2. Software requirements
    4. Hardware and software design
      1. The gesture hardware architecture
      2. The detailed hardware design
      3. The software architecture
    5. Constructing the gesture controller
      1. The APDS-9960 theory of operation
      2. Analyzing gesture data
      3. The APDS-9960 gesture driver
      4. The APDS-9960 gesture class constructor
      5. The APDS-9960 gesture class detect method
      6. The gesture controller applications
    6. Testing the gesture controller
    7. Summary
    8. Questions
    9. Further reading
  13. Automation and Control Using Android
    1. Technical requirements
    2. The sensor node project requirements
      1. Hardware requirements
      2. Software requirements
    3. Hardware and software design
      1. The hardware architecture
      2. The software architecture
    4. Building a sensor node
      1. Installing MicroPython on the ESP32
      2. Setting up the ESP32 flash utilities
      3. Programming the ESP32 with MicroPython
      4. Testing MicroPython with LEDs
      5. Setting up WebREPL
      6. Simplifying application development with Anaconda
      7. Installing uasyncio
      8. Writing the sensor node application
        1. Imports and supporting objects
        2. LEDs and local control
        3. socket_connect()
        4. socket_receive()
        5. The IotDevice class
        6. Command parsing
        7. The system status task
        8. socket_send()
        9. The main application
    5. Testing the sensor node
      1. The Android socket server
      2. Commanding the sensor node
      3. Testing the commands
    6. Summary
    7. Questions
    8. Further reading
  14. Building an Object Detection Application Using Machine Learning
    1. Technical requirements
    2. Introducing machine learning
      1. The need for intelligent systems
      2. Machine learning from the cloud to the edge
    3. Object detection requirements
      1. Hardware requirements
      2. Software requirements
    4. Object detection design and theory
      1. The CIFAR-10 and CIFAR-100 datasets
      2. Machine learning modeling languages
      3. TFLu
      4. CMSIS-NN
      5. The hardware
    5. Implementing and testing object detection on the OpenMV camera 
      1. Getting familiar with OpenMV IDE
      2. Implementing a pretrained CIFAR-10 network
      3. Person detection with a TensorFlow model
    6. Summary 
    7. Questions 
    8. Further reading
    9. References
  15. The Future of MicroPython
    1. The advancing MicroPython
    2. The pyboard D-series
      1. The pyboard D-series hardware
      2. The pyboard D-series software
        1. Controlling the boot sequence
        2. Recovering from system faults
    3. MicroPython in the real world
      1. Example DIY/maker projects
      2. Example professional projects
    4. The future of MicroPython
    5. Going further
    6. References
  16. Downloading and Running MicroPython Code
  17. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: MicroPython Projects
  • Author(s): Jacob Beningo
  • Release date: April 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781789958034