Reader small image

You're reading from  MicroPython Projects

Product typeBook
Published inApr 2020
Reading LevelExpert
PublisherPackt
ISBN-139781789958034
Edition1st Edition
Languages
Right arrow
Author (1)
Jacob Beningo
Jacob Beningo
author image
Jacob Beningo

Jacob Beningo is an independent consultant who specializes in microcontroller-based embedded systems. He has advised, coached, and developed systems across multiple industries, including the automotive, defense, industrial, medical, and space sectors. Jacob enjoys working with companies to help them develop and improve their processes and skill sets. He publishes a monthly newsletter, Embedded Bytes, and blogs for publications about embedded system design techniques and challenges. Jacob holds bachelor's degrees in electrical engineering, physics, and mathematics from Central Michigan University and a master's degree in space systems engineering from the University of Michigan.
Read more about Jacob Beningo

Right arrow

Preface

Embedded systems developers have traditionally mostly used C when programming, or if they are daring and cutting edge, they've pushed the envelope by using C++. Over the last decade, a lot has changed in the way that we design and build embedded systems and in the way that software is developed in general. Python has become a dominant language in many computer and server applications, with many young and new developers learning Python first over any other language. This makes Python a unique and interesting choice to develop embedded systems.

MicroPython Projects explores how developers can leverage Python to develop applications that use a slimmed-down version Python known as MicroPython. MicroPython came into existence back in 2013 and has been steadily evolving and growing an active and innovative community around it. MicroPython allows developers to work at a higher level of abstraction, focusing on the application early while leaving low-level processor details behind an interface, which makes it easy for even non-software developers to quickly write applications that control and interface with the hardware.

This book will walk you through the background of developing applications using MicroPython and will help developers to get familiar with some design patterns and formulate ideas for their own projects.

Who this book is for

This book is for embedded systems developers or anyone who is interested in building embedded systems using MicroPython.

I expect that the reader has a basic understanding of electronics and Python while some experimentation with MicroPython will be helpful.

I've tried throughout the book to reinforce the software development process, which I often find lacking in developers who are designing their own product or working on open source software. No matter what your current skill level, readers will get an understanding of where and when to use MicroPython, along with techniques and patterns they can directly apply to their own projects and some ideas on how to expand the projects that are in this book.

What this book covers

Chapter 1, Down the Rabbit Hole with MicroPython, takes you through embedded software development and where MicroPython fits in. In this chapter, we look at how to decide what language to use, along with some general best practices.

Chapter 2, Managing Real-Time Tasks, helps you explore the different techniques that developers can use to schedule tasks in their MicroPython-based system.

Chapter 3, Writing a MicroPython Driver for an I/O Expander, explains how to write your own driver for an external device.

Chapter 4, Developing an Application Test Harness, takes you through different methods that can be used to test our MicroPython-based application and presents several different options for developers interested in such activities.

Chapter 5, Customizing the MicroPython Kernel Start Up Code, helps you to get behind the scenes with MicroPython by examining and making changes to the MicroPython kernel. In this chapter, we focus on the startup code that developers looking to produce a production system might need to modify.

Chapter 6, A Custom Debugging Tool to Visualize Sensor Data, helps you explore how you can transport sensor and debugging information from our device to a computer that then visualizes what is happening on our system. This can be critical to monitoring key variables, debug statements, or just creating a sensor dashboard.

Chapter 7, Device Control Using Gestures, helps you learn how we can interface a gesture sensor with a development board and write an application that will detect gestures.

Chapter 8, Automation and Control Using Android, helps you learn how we can use an ESP32 microcontroller to create a sensor node that can transmit sensor data and receive commands from an Android template. This project is easily extensible for Internet-of-Things (IoT) applications and device control.

Chapter 9, Building an Object Detection Application Using Machine Learning, demonstrates the use of an OpenMV camera module powered by MicroPython to build an application that can detect objects in an image.

Chapter 10, The Future of MicroPython, explores the future of MicroPython and where we might expect to see it go in the coming years.

Appendix A, Downloading and Running MicroPython Code, explains the process of getting code onto the board and running it.

To get the most out of this book

This book assumes that the reader has a basic understanding of Python and that they have at least built a few embedded systems projects previously. The material is written so that a beginner will not have any problems and a more experienced embedded software developer will be able to quickly learn how to write MicroPython-based applications. I also assume that you are able to read flowcharts and basic wiring diagrams. The reader should also understand how to use a Git repository and install software on their computer.

Software/hardware covered in the book

OS requirements

PyCharm

Windows, Linux, macOS

PuTTY

Windows, Linux, macOS

Linux Virtual Machine

Windows, Linux, macOS

Python 3.x

Windows, Linux, macOS

Anaconda Terminal

Windows, Linux, macOS

Simple TCP Socket Tester

Windows, Linux, macOS

OpenMV IDE

Windows, Linux, macOS

Pyboard

-

RobotDyn I2C 8-bit PCA8574 I/O expander

-

Adafruit RGB Pushbutton PN: 3423 or equivalent

-

STM32L4 IoT Discovery Node

-

Robotdyn I2C 8-bit PCA8574 I/O expander

-

USB to UART Converter

-

Adafruit ADPS9960 breakout board

-

MicroPython supported development board

-

ESP32 WROVER-B

-

OpenMV Camera Module

-

The projects are not necessarily designed to be done in order. With that in mind, I would recommend that developers read the first two chapters in order before jumping to the project that is most interesting to them. These chapters give the background on MicroPython and how to schedule tasks. After that, it's up to the developer to decide on the order. As strange as this may sound, I would also encourage readers to make sure they read the last chapter as well, which introduces the pyboard-D, which may be the development board they decide to go with for most of their experimentation.

If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/MicroPython-Projects. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Create new modules for each module that will be tested with _tests.py appended to the filename."

A block of code is set as follows:

def system_init():
print("Initializing system ...")
print("Starting application ...")

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

 try:
PushButton = RGB_Button.DeviceIO.Read()
except Exception as e:
sys.print_exception(e)
print("Exiting application ...")
sys.exit(0)

Any command-line input or output is written as follows:

pip install pySerial

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "See the MicroPython documentation | Quick reference for the pyboard | MicroPython tutorial for the pyboard | 3. Getting a MicroPython REPL prompt for details."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
MicroPython Projects
Published in: Apr 2020Publisher: PacktISBN-13: 9781789958034
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Jacob Beningo

Jacob Beningo is an independent consultant who specializes in microcontroller-based embedded systems. He has advised, coached, and developed systems across multiple industries, including the automotive, defense, industrial, medical, and space sectors. Jacob enjoys working with companies to help them develop and improve their processes and skill sets. He publishes a monthly newsletter, Embedded Bytes, and blogs for publications about embedded system design techniques and challenges. Jacob holds bachelor's degrees in electrical engineering, physics, and mathematics from Central Michigan University and a master's degree in space systems engineering from the University of Michigan.
Read more about Jacob Beningo