MicroPython : Embedded Programming Made Easy

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

MicroPython is a lightweight implementation of the Python 3 programming language that has been optimized for microcontrollers and other embedded systems. It provides a powerful and intuitive platform for developing a wide range of Internet of Things (IoT) applications, from simple data collection and processing tasks to complex automation and control systems. In this book, you'll learn the basics of programming with MicroPython and explore its many features and capabilities. You'll discover how to connect and control various hardware devices and sensors using the built-in I/O pins, and how to communicate with other devices over various protocols such as Wi-Fi, Bluetooth, and LoRa. The book covers the most essential topics in MicroPython, including variables and data types, conditionals and loops, functions, modules, memory management, and file system operations. You'll also learn about more advanced topics such as interrupt handling, sleep modes, and PWM control. Throughout the book, you'll work on practical examples and projects that will help you build a solid understanding of MicroPython and its applications. By the end of the book, you'll have the skills and knowledge to create your own IoT projects and applications using MicroPython. Whether you're a seasoned developer or a beginner, this book will provide you with a comprehensive guide to using MicroPython for embedded programming. With its clear explanations and practical examples, it's the ideal resource for anyone looking to get started with this powerful language.

Author(s): Caroline Davis
Publisher: Independently published
Year: 2023

Language: English
Pages: 225

Cover Page
Title Page
Copyright Page
Introduction
Use MicroPython
Access the MicroPython environment
Enter MicroPython code
Direct entry
Exit MicroPython
Display tools
Recover an XBee device
MicroPython syntax
Colons
After conditional statements and loop statements
Indentations
FOR loop with one statement indented
FOR loop with two statements indented
Functions
Function with arguments
Errors and exceptions
Name error
Referencing a name that was not created
Referencing a name from one function that was created in a different function
OSError
Socket errors
ENOTCONN: Time out error
ENFILE: No sockets are available
ENXIO: No such device or address
Keyboard shortcuts
Select a previously typed statement
Differences between MicroPython and other programming languages
Memory management
Variable types
Curly braces and indentation
Semicolons
Increment operator
Logical operators
Develop applications on an XBee device
Space allocated to MicroPython
Code storage
Built-in modules embedded in XBee firmware (device flash)
Parsed and compiled code in .mpy files (file system)
Executable code on MicroPython heap (device RAM)
Compiled modules relocated from file system to device flash
How to organize your code
Monitor memory usage
The gc module
The micropython module
Efficient coding
One-liners in the REPL
Flash upload mode
Modules stored as .py files
Compiled modules stored as .mpy files
Compiled modules via Flash upload mode
Compiled modules embedded in device flash
Digi modified slicing for bytes and strings operations
Power management
Prevent sleep from MicroPython
Initiate sleep from MicroPython
Sleeping with AT commands
Idle a device from MicroPython
Enter and exit the idle state
Poll for data while the device is idle
Access the primary UART
How to use the primary UART
sys.stdin limitations
Example: read bytes from the UART in MicroPython
Example: read the first 15 bytes from the UART in MicroPython
REPL (Read-Evaluate-Print Loop) examples
Print the banner
Print the banner and verify that the memory was not wiped
Paste one line of code
Load code to flash memory
Erase the code stored in flash memory
Flash memory and automatic code execution
Run stored code at start-up to flash LEDs
Disable code from running at start up
Perform a soft-reset or reboot
Access file system
Modify file system contents
uos.chdir(dir)
uos.getcwd()
uos.ilistdir([dir])
uos.listdir([dir])
uos.mkdir(dir)
uos.remove(file)
uos.rmdir(dir)
uos.rename(old_path, new_path)
uos.replace(old_path, new_path)
uos.sync()
uos.compile(source_file, mpy_file=None)
uos.format()
uos.hash([secure_file])
Access data in files
File object methods
read(size=-1)
readinto(b)
readline(size=-1)
readlines()
write(b)
seek(offset, whence=0)
tell()
flush()
close()
Import modules from file system
Reload a module
Compiled MicroPython files
Send and receive User Data Relay frames
Interfaces (always defined)
Limits
relay.callback(my_callback)
Machine module
Reset-cause
Constants
Random numbers
Unique identifier
Class PWM (pulse width modulation)
Constructors
Standard bus operations methods
Memory operations methods
Class Pin
Class UART
Test the UART interface
Use the UART class
Class WDT: watchdog timer
Access the XBee device's I/O pins
Use the Pin() constructor
Use mode() to configure a pin
Pin.DISABLED
Pin.IN
Pin.OUT
Pin.ALT
Pin.ANALOG