This repository is a series of introduction tasks to teach students the basics of Pi Pico and common mechatronic components. Then students will create a mini OOP based project to explicitly teach Object Oriented Paradigm (OOP) programming concepts specifically in the microcontroller context.
Students will be recreating a model of the pedestrian crossing on Unwins Bridge Road out the front of Tempe High School.
- Connect and control a LED
- Connect a digital sensor that controls the LEDs
- Connect a analog sensor that controls the LEDs
- Control the brightness of the LED with Pulse Width Modulation
- Connect and control a servo motor
- Connect and read a ultrasonic sensor use it to control the servo motor
- Connect and control a I2C 16x2 LCD Display
- Breadboard
- Jumper leads
- Pi Pico
- 1x LED
- 1x 130Ω resistors
- 1x Potentiometer or analog sensor
- 1x Momentary switch or digital sensor
- 1x Servo motor
- 1x Ultrasonic sensor
- 1x 2IC 16x2 LCD Display
Pin | |
---|---|
GP0 | SDA |
GP1 | SCL |
GP4 | Keyboard Interrupt |
GP10 | Servo Motor Signal |
GP11 | Ultrasonic Echo Signal |
GP12 | Ultrasonic Trig Signal |
GP13 | Digital Sensor Signal |
GP15 | External LED |
GP25 | Inbuilt LED |
GP26 | Analog Sensor Signal |
AGND | Analog Ground |
GND | Ground |
3V3 | 3V Power |
VBUS | 5V Power |
From the above real world control system we will model:
- Overloading and overriding polymorphism
- Inheritance, multilevel inheritance and multiple class inheritance
- Abstraction
- Decomposition and composition
- Generalisation
- Encapsulation
- Object instantiation, objects as instance variables
- Breadboard
- Jumper leads
- Pi Pico
- 1x Momentary switch
- 5x LED
- 1x Piezo buzzer
- 5x 130Ω resistors
Pin | |
---|---|
GP3 | Red LED |
GP4 | Keyboard Interrupt |
GP5 | Amber LED |
GP6 | Red LED |
GP17 | Flashing Green LED |
GP19 | Flashing Red LED |
GP22 | Button signal |
GP27 | Piezo Buzzer |
GND | Circuit Ground |
3V3 | Button logic voltage |
classDiagram
PIN <|-- Button : Inheritance
PIN <|-- Led_Light : Inheritance
PWM <|-- Buzzer : Inheritance
Led_Light <|-- Flashing_Light : Inheritance
Buzzer <|-- Flashing_Light : Inheritance
Button --* Pedestrian_Crossing : Composition
Led_Light --* Pedestrian_Crossing : Composition
Flashing_Light --* Pedestrian_Crossing : Composition
class PIN{
}
class Led_Light{
obj Servo
get_pos()
set_rot_cw(count)
set_rot_ccw(count)
}
class Flashing_Light{
obj Servo
int start_angle
int min_set_angle
int max_set_angle
get_angle()
set_angle(angle)
}
class Button{
obj Servo
int open_angle
int closed_angle
bool claw_state
set_open()
set_closed()
get_state()
}
class Pedestrian_Crossing{
obj Claw
obj Base
obj Elbow
obj Elbow
pick_cube()
place_cube()
}
Note
Inheritance and association labels are note required in a UML diagram but have been added for understanding.
Version | Notes |
---|---|
v01.py | Basic "Blink" Program (the Hello World of mechatronics). |
v02.py | Test wiring and use basic methods from parent Pin class. |
v03.py | Implement a child class of MicroPython Pin class for the traffic lights, demonstrating Inheritance and Polymorphism. |
v04.py | Move the Led_Light class to a separate file, demonstrating abstraction. |
v05.py | Write a Button class and test it by instantiating it and controlling the red_light instance of the Led_Light class. |
v06.py | Implement a Event Trigger for when the button has been pressed. |
v07.py | Demo code only of Multiple Inheritence. |
MicroPython_OOP_Pi_Pico_Mini_Project_Source
and MicroPython_OOP_Pi_Pico_Mini_Project_Template
by Ben Jones is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International