Day 23: (Wed Nov 20, Week 13) Revision Testing¶
Assignments¶
Please remember to collect ongoing documentation. Please use Project Phase 2 Folder.
Administrative¶
If your prototype will require 3D-printed parts, I can individually show you how to export an STL and submit to the Mosaic printer system using CKS-F24 3D Printer Submissions.
Short term schedule:
Date |
Due |
|---|---|
Mon Nov 18 |
new proof of concept or design revision |
Mon Nov 25 |
dress rehearsal (before Thanksgiving) |
Mon Dec 4 |
revised prototype to test at School |
Agenda¶
General project status check
Revision demo and testing
Individual consultations
References¶
For the motor drive, we can use the MOSFET circuit and sample code from DC Motor Examples - Raspberry Pi Pico.
For the button circuit, we can use the example from Exercise: Digital I/O with the Pico.
For the button inputs, we can use the sample code from Digital Input/Output Examples - Raspberry Pi Pico.
Sample Code¶
The combined sample code for the puppet machine can be found at puppet-show.py. It should be renamed code.py when copied to the Pico.
1# puppet-show.py
2
3# Sample code for operating a mechanical puppet show. Two pushbutton switches
4# and two indicator LEDS are attached as the user interface. A single MOSFET
5# transistor drive circuit switches on all the DC motor.
6
7# Related documentation:
8# https://circuitpython.readthedocs.io/en/latest/shared-bindings/pwmio/index.html#module-pwmio
9
10# Wiring notes:
11
12# GPIO22 - pin 29 - PWM output to MOSFET
13#
14# GPIO12 - pin 16 - input from start switch
15# GPIO13 - pin 17 - input from stop switch
16# GND - pin 18
17# GPIO14 - pin 19 - output to start LED
18# GPIO15 - pin 20 - output to stop LED
19
20# ----------------------------------------------------------------
21# Import standard Python modules.
22import time, math
23
24# Load the CircuitPython hardware definition module for pin definitions.
25import board
26
27# Load the CircuitPython pulse-width-modulation module for driving hardware.
28import pwmio
29
30# Load the CircuitPython digital input/output module for reading and writing pin voltages.
31import digitalio
32
33# ----------------------------------------------------------------
34# Initialize hardware.
35
36# Create a PWMOut object on GP22. This will create a pulsing signal with
37# variable duty cycle. The switching rate of 20kHz is chosen to be
38# supra-audible.
39pwm = pwmio.PWMOut(board.GP22, duty_cycle=0, frequency=20000)
40
41# Utility function to calculate and apply a new duty cycle setting. Converts a
42# unit-range (0.0 to 1.0) pwm_level to a 16-bit integer representing a fraction
43# needed by the PWM driver.
44def set_motor_speed(pwm_device, pwm_level):
45 pwm_device.duty_cycle = min(max(int(pwm_level * 2**16), 0), 2**16-1)
46 print("Applied duty cycle of %d for pwm_level %f" % (pwm_device.duty_cycle, pwm_level))
47
48# ----------------------------------------------------------------
49# Set up digital inputs.
50
51start_switch = digitalio.DigitalInOut(board.GP12)
52start_switch.direction = digitalio.Direction.INPUT
53
54stop_switch = digitalio.DigitalInOut(board.GP13)
55stop_switch.direction = digitalio.Direction.INPUT
56
57# Set up digital inputs.
58
59start_LED = digitalio.DigitalInOut(board.GP14)
60start_LED.direction = digitalio.Direction.OUTPUT
61
62stop_LED = digitalio.DigitalInOut(board.GP15)
63stop_LED.direction = digitalio.Direction.OUTPUT
64
65# ----------------------------------------------------------------
66# Enter the main event loop.
67while True:
68
69 # turn on stop LED
70 stop_LED.value = True
71
72 # wait for start switch; it is wired active-low, so it will become False when pressed
73 while start_switch.value is True:
74 pass
75
76 # turn off stop LED, turn on start LED
77 stop_LED.value = False
78 start_LED.value = True
79
80 # turn the motor on
81 set_motor_speed(pwm, 1.0)
82
83 # wait for stop switch; it is wired active-low, so it will become False when pressed
84 while stop_switch.value is True:
85 pass
86
87 # turn the motor off again
88 set_motor_speed(pwm, 0.0)
89
90 # turn off start LED
91 start_LED.value = False