Quickly learn to program for microcontrollers and IoT devices without a lot of study and expense. MicroPython and controllers that support it eliminate the need for programming in a C-like language, making the creation of IoT applications and devices easier and more accessible than ever.
MicroPython for the Internet of Things is ideal for readers new to electronics and the world of IoT. Specific examples are provided covering a range of supported devices, sensors, and MicroPython boards such as Pycom's WiPy modules and MicroPython's pyboard. Never has programming for microcontrollers been easier.
The book takes a practical and hands-on approach without a lot of detours into the depths of theory. The book:
Shows a faster and easier way to program microcontrollers and IoT devices
Teaches MicroPython, a variant of one of the most widely used scripting languages
Is friendly and accessible to those new to electronics, with fun example projects
What You'll Learn
Program in MicroPython
Understand sensors and basic electronics
Develop your own IoT projects
Build applications for popular boards such as WiPy and pyboard
Load MicroPython on the ESP8266 and similar boards
Interface with hardware breakout boards
Connect hardware to software through MicroPython
Explore the easy-to-use Adafruit IO connecting your microcontroller to the cloud
Who This Book Is For
Anyone interested in building IoT solutions without the heavy burden of programming in C++ or C. The book also appeals to those wanting an easier way to work with hardware than is provided by the Arduino and the Raspberry Pi platforms.
Author(s): Charles Bell
Publisher: Apress
Year: 2017
Language: English
Pages: 445
Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Chapter 1: What Is the Internet of Things?
The Internet of Things and You
IOT Is More Than Just Connected to the Internet
IOT Services
A Brief Look at IOT Solutions
Sensor Networks
Medical Applications
Automotive IOT Solutions
Fleet Management
IOT and Security
Security Begins at Home
Secure Your Devices
Use Encryption
Security Doesn’t End at the Cloud
Python and the IOT
Origins
Online Python Simulator
Summary
Chapter 2: Introducing MicroPython
Getting Started
Origins
MicroPython Features
MicroPython Limitations
What Does MicroPython Run On?
Experimenting with Python on Your PC
Installing Python 3 on Windows 10
Installing Python 3 on macOS
Installing Python 3 on Linux
Running the Python Console
Running Python Programs with the Interpreter
How MicroPython Works
The Run, Evaluate, Print Loop (REPL Console)
Connect the Board
Starting the REPL Console (Windows)
Starting the REPL Console (macOS and Linux)
Off and Running with MicroPython
Additional Hardware
Basic Electronics Kit
Breadboard and Jumper Wires
Example 1:
Example 2:
Example 3:
Summary
Chapter 3: MicroPython Hardware
Getting Started with MicroPython Boards
Firmware Updates
Networking Issues
One Step at a Time!
Programming Tools
Some Assembly Required
GPIO Pins
Other Tips
Visit the Community Forums
Handle with Care!
PC Doesn’t Recognize the SD Drive
Loose or Missing Jumpers
MicroPython-Ready Boards
Pyboard
Overview
More About the Hardware
Getting Started with Pyboard
Loading the Firmware
Networking with the Pyboard
Where to Buy
WiPy
Overview
More About the Hardware
Getting Started with WiPy
Connecting to Your WiFi Network
Using the SD Drive
Loading the Firmware
Special Applications
Where to Buy
MicroPython-Compatible Boards
BBC micro:bit
Up and Running with MicroPython
Where to Buy
Circuit Playground Express (Developer Edition)
Up and Running with CircuitPython
Where to Buy
Adafruit Feather Huzzah
Up and Running with MicroPython
Where to Buy
Other Boards
Breakout Boards and Add-Ons
Breakout Boards
Board-Specific Shields/Skins
Pyboard
WiPy and Related
Board-Specific Accessories
Pyboard
WiPy and Related Boards
BBC micro:bit
Which Board Should I Buy?
Summary
Chapter 4: How to Program in MicroPython
Basic Concepts
Code Blocks
Comments
Arithmetic
Output to Screen
Variables
Types
Basic Data Structures
Lists
Tuples
Dictionaries
Statements
Conditional Statements
Loops
Modularization; Modules, Functions, and Classes
Including Modules
Functions
Classes and Objects
Learning Python by Example
Example 1: Using Loops
Write the Code
Execute the Code
Your Challenge
Example 2: Using Complex Data and Files
Write the Code
Execute the Code
Your Challenge
Example 3: Using Functions
Write the Code
Execute the Code
Your Challenge
Example 4: Using Classes
Write the Code
Execute the Code
Your Challenge
For More Information
Summary
Chapter 5: MicroPython Libraries
Built-In and Standard Libraries
Overview
Common Standard Libraries
sys
uio
ujson
uos
utime
Built-In Functions and Classes
Exceptions
MicroPython Libraries
Overview
Common MicroPython Libraries
machine
network
Custom Libraries
Summary
Chapter 6: Low-Level Hardware Support
Board-Specific Libraries
Pyboard
pyb
lcd160cr
WiPy
pycom
AES
Low-Level Examples
Drivers and Libraries to the Rescue!
Real-Time Clock (RTC)
Callbacks
Using Breakout Boards
Inter-Integrated Circuit (I2C)
Serial Peripheral Interface (SPI)
Summary
Chapter 7: Electronics for Beginners
The Basics
Tools
Multimeter
Soldering Iron
Wire Strippers
Helping Hands
Using a Multimeter
Testing Continuity
Measuring Voltage
Measuring Current
Measuring Resistance
Powering Your Electronics
Electronic Components
Button
Capacitor
Diode
Fuse
Light Emitting Diode (LED)
Relay
Resistor
Switch
Transistor
Voltage Regulator
Breakout Boards and Circuits
Using a Breadboard to Build Circuits
What Are Sensors?
How Sensors Measure
Analog Sensors
Digital Sensors
Examples of Sensors
Accelerometers
Audio Sensors
Barcode Readers
Biometric Sensors
Capacitive Sensors
Coin Sensors
Current Sensors
Flex/Force Sensors
Gas Sensors
Light Sensors
Liquid-Flow Sensors
Liquid-Level Sensors
Location Sensors
Magnetic-Stripe Readers
Magnetometers
Moisture Sensors
Proximity Sensors
Radiation Sensors
RFID Sensors
Speed Sensors
Switches and Pushbuttons
Tilt Switches
Touch Sensors
Video Sensors
Weather Sensors
Summary
Chapter 8: Project 1: Hello, World! MicroPython Style
Overview
Required Components
Set Up the Hardware
WiPy
Pyboard
Write the Code
Design
Libraries Needed
Changes to ssd1306.py for the WiPy
Changes to uRTC.py for the Pyboard
Changes to ssd1306.py for the Pyboard
Planning the Code
Imports
Set Up
Initialize
New Function
Test the Parts of the Code
Test the RTC Breakout Board
Test the OLED Breakout Board
Completed Code
Execute!
Taking It Further
Summary
Chapter 9: Project 2: Stoplight Simulator
Overview
Required Components
Set Up the Hardware
WiPy
Pyboard
Write the Code
Part 1: Stoplight Simulator – Using a Pushbutton
Imports
Setup
Functions
Test and Debug the Code
Part 2: Stoplight Simulator – Remote Control with HTML
Imports
Setup
Functions
Completed Code
Execute!
Taking it Further
Summary
Chapter 10: Project 3: Plant Monitoring
Overview
Required Components
Set Up the Hardware
WiPy
Pyboard
Write the Code
Calibrating the Sensor
Part 1: Sensor Code Module
High-Level Design
Setup and Initialization
Constructor
Public Functions
Private Functions
Complete Code
Changes for the Pyboard
Part 2: Main Code
HTML Code (Files)
Imports
Imports
Network Time Protocol
The run() Function
Complete Code
Changes for the Pyboard
Execute!
Taking it Further
Summary
Chapter 11: Project 4: Using Weather Sensors
Overview
Message Queue Telemetry Transport
How It Works
Clients
Brokers
Getting Started with Adafruit IO
Required Components
Set Up the Hardware
Configure Adafruit IO
Set Up Feeds
Set Up a Dashboard
Get Your Credentials
Write the Code
MQTT Driver
BME280 Library
Weather Class
Design
Imports
Constructor
Read Data Function
Message Callback Function
Run Function
Completed Code
Main Code
Imports
Global Definitions
Connect Function
Run Function
Completed Code
Execute!
Taking it Further
Summary
Chapter 12: Where to Go from Here
More Projects to Explore
MicroPython Project Samples
Forums
Documentation
Repositories
Community Project Sites: Hackster.io
Knowledge Repositories: learn.adafruit.io
Join the Community
Why Contribute?
Which License, Where?
How We Share
Keep Your Designs Original
Check the License
Keep It Appropriate
Annotate Your Work
Be a Good Citizen
Suggested Communities
Become a Maker
What’s a Maker?
Share Your Ideas
Attend an Event
Summary
Appendix
Required Components
Optional Components
Recommended Tools
Index