Implementations of the exercises in Get Started with MicroPython on Raspberry Pi Pico
Design goals
- Modular code
- Minimize thinking about pins and other physical minutiae, allow mental focus on behavior
- Support automated unit and functional tests
- Minimize on-device QA
To achieve these goals, the code is broken out into components
, singletons
, models
and scripts
A component is a physical device wired to the Pico using one or more pins. A model is a collection of components that interact.
The primary singleton is the Pico class, which represents the microcontroller configuration i.e., allocation of pins.
Scripts tie different components, models and singletons together into an executable.
Dependencies
- Micropython 1.17 or greater
- UnitTest
- Install with
micropython -m upip install unittest
- Install with
Hardware Used
- Towerpro MG92 Microservo
- LEDs
- PS1240 Piezo Buzzer
- Potentiometer
- TinSharp TC1602A LCD
- PIR Sensor
- AHT20 Humidity/Temperature Sensor
- Adafruit AirLift ESP32 Wifi Board
Functional Testing
To prove correct functioning of components and models, we can write functional tests that
observe the states of IO channels. This is possible by providing mock implementations
of machine
classes for Pin
, PWM
, ADC
, I2C
and SPI
.
Running Tests
micropython run_tests.py
Running Scripts
Within a micropython interactive session exec(open('scripts/the_script.py').read())