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
Note
Students can build using physical components or prototype using this Template Wokwi Project.
- 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 |
Note
Students can build using physical components or prototype using this Template Wokwi Project.
- 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 |
GP7 | Red LED |
GP17 | Flashing Green LED |
GP19 | Flashing Red LED |
GP22 | Button signal |
GP27 | Piezo Buzzer |
GND | Circuit Ground |
3V3 | Button logic voltage |
classDiagram
class Pin {
-__pin: int
+__init__(pin: int)
+value()
+high()
+low()
+toggle()
}
class PWM {
-__pin: int
+__init__(pin: int)
+freq(freq: int)
+duty_u16(duty: int)
}
class Audio_Notification {
-__debug: bool
+__init__(pin: int, debug: bool)
+warning_on()
+warning_off()
+beep(freq: int, duration: int)
}
PWM <|-- Audio_Notification : Inheritance
class Led_Light {
-__debug: bool
-__pin: int
-__flashing: bool
+__init__(pin: int, flashing: bool, debug: bool)
+on()
+off()
+toggle()
+flash(duration: int)
+on_for(duration: int)
+led_light_state: int
}
Pin <|-- Led_Light : Inheritance
class Pedestrian_Button {
-__debug: bool
-__pin: int
-__last_pressed: int
-__pedestrian_waiting: bool
+__init__(pin: int, debug: bool)
+callback(pin: Pin)
+button_state
+reset
}
Pin <|-- Pedestrian_Button : Inheritance
class Controller {
-__object: Led_Light
-__object: Led_Light
-__object: Led_Light
-__object: Led_Light
-__object: Led_Light
-__object: Pedestrian_Button
-__object: Audio_Notification
}
Led_Light --> Controller : Composition
Audio_Notification --> Controller : Composition
Pedestrian_Button --> Controller : Composition
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) for Unit Testing the Microcontroller. |
v02.py | Unit Test for wiring and use basic methods from parent Pin and PWM class. |
v03.py | A blank python script. |
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