-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Worksheets for Raspberry Pi Pico and micropython #7
Comments
We do plan to do this (and should have by now) but time has not been on our side. Thank you for the prompt and this code. It will encourage us to progress this. |
Thank you. |
That would be extremely useful. Thank you. |
Worksheet TwoCircuitAll components on the breadboard (LEDs, resistors, buzzer, jump wires) are connected exactly as the Worksheet Two (GPIO Zero) describes. The following pins of the Pico are used: Pin 3 (GND) Code# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 2 - LEDs and Buzzer
# Import Python libraries
from machine import Pin
import time
# Set up the LEDs and Buzzer
red = Pin(2, Pin.OUT)
blue = Pin(3, Pin.OUT)
buzzer = Pin(4, Pin.OUT)
print("Lights and sound on")
red.on()
blue.on()
buzzer.on()
# Pause for one second
time.sleep(1)
print("Lights and sound off")
red.off()
blue.off()
buzzer.off() |
Thank you.
…On Sat, 5 Mar 2022, 16:57 Andrii Annenko, ***@***.***> wrote:
Worksheet Two Pinout
All components on the breadboard (LEDs, resistors, buzzer, jump wires) are
connected exactly as the Worksheet Two (GPIO Zero) describes.
The following pins of the Pico are used:
Pin 3 (GND)
Pin 4 (GP2) RED
Pin 5 (GP3) BLUE
Pin 6 (GP4) BUZZ
[image: image]
<https://user-images.githubusercontent.com/4640265/156892226-b156ee9f-4405-4609-860f-c2c634ba28ea.png>
Code
# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)# Worksheet 2 - LEDs and Buzzer
# Import Python librariesfrom machine import Pinimport utime
# Set up the LEDs and Buzzerred = Pin(2, Pin.OUT)blue = Pin(3, Pin.OUT)buzzer = Pin(4, Pin.OUT)
print("Lights and sound on")red.on()blue.on()buzzer.on()
# Pause for one secondutime.sleep(1)
print("Lights and sound off")red.off()blue.off()buzzer.off()
—
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDNQQXRW4YH5G26GWHS2JTU6OG6TANCNFSM5JNGN56Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Worksheet ThreeIn contrast with my initial suggestion, LEDs and Buzzer from the Worksheet Two are still connected CircuitThermal sensor is connected to the bread board in a very similar way to how the Worksheet Three (GPIO Zero) suggests. The only difference is that all connections on the rows with yellow and black wire of the sensor are shifted by two rows to the left. The following pins of the Pico are used: Pin 38 (GND) BLACK CodeRead temperature in a cycle, pause using # CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 3 - Temperature
# Import Libraries
import time
from machine import Pin
from onewire import OneWire
from ds18x20 import DS18X20
# Initialize the temperature sensor.
ds = DS18X20(OneWire(Pin(28)))
roms = ds.scan()
# Print out the temperature until the program is stopped.
while True:
ds.convert_temp()
time.sleep(1)
print(ds.read_temp(roms[0])) Fire the # CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 3 - Temperature
# Import Libraries
from machine import Pin, Timer
from onewire import OneWire
from ds18x20 import DS18X20
# Initialize the temperature sensor.
ds = DS18X20(OneWire(Pin(28)))
roms = ds.scan()
# A function that reads the sensor data.
def print_temp(timer):
ds.convert_temp()
print(ds.read_temp(roms[0]))
# Print out the temperature until the program is stopped.
Timer(period=1000, mode=Timer.PERIODIC, callback=print_temp) |
Worksheet FourTwo different ways of reading an LDR with Pico are described below:
Circuit (RPi.GPIO adaptation)The LDR and the capacitor are connected to the board the same way as described in Worksheet Four (RPi.GPIO and GPIO Zero). The following pins of the Pico are used: Pin 36 (3v3) Positive capacitor leg connected to the Pico's 3v3 via the LDR Code (RPi.GPIO adaptation)# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 4 - Light
# Import Libraries
import time
from machine import Pin
# A variable that lets us control the LDR
ldr = Pin(27, Pin.OUT)
def readldr():
ldrcount = 0 # Sets the count to 0
ldr.init(Pin.OUT)
ldr.off()
time.sleep(0.1) # Drains all charge from the capacitor
ldr.init(Pin.IN) # Sets the pin to be input
# While the input pin reads 'off' or Low, count
while (ldr.value() == 0):
ldrcount += 1 # Add one to the counter
return ldrcount
while True:
print(readldr())
time.sleep(1) # Wait for a second
# Output:
# 312 (lights on)
# 309
# 4508 (off)
# 5330
# 1555 (dim)
# 1512 Circuit (using ADC)The following pins of the Pico are used: Pin 33 (GND) One LDR leg Code (using ADC)# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 4 - Light
# Import Libraries
import time
from machine import ADC
# A variable that lets us control the LDR
ldr = ADC(27)
while True:
print(ldr.read_u16())
time.sleep(1) # Wait for a second
# Output:
# 448 (lights on)
# 448
# 1152 (off)
# 1216
# 976 (dim)
# 992
|
Worksheet FiveCircuitThe infrared sensor is connected to the bread board in a similar way to how the Worksheet Five (GPIO Zero) suggests. The following pins of the Pico are used: Pin 40 (VBUS) Connected to the sensor's VCC pin Code# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 5 - Movement
# Import Python header files
import time
from machine import Pin
print("PIR Module Test (CTRL-C to exit)")
# Set pin as input
pir = Pin(28, Pin.IN)
# Variables to hold the current and last states
currentstate = 0
previousstate = 0
try:
print("Waiting for PIR to settle ...")
# Loop until PIR output is 0
while pir.value() == 1:
currentstate = 0
print(" Ready")
# Loop until user quits with CTRL-C
while True:
# Read PIR state
currentstate = pir.value()
# If the PIR is triggered
if currentstate == 1 and previousstate == 0:
print(" Motion detected!")
# If the PIR has returned to ready state
elif currentstate == 0 and previousstate == 1:
print(" Ready")
# Record previous state
previousstate = currentstate
# Wait for 10 milliseconds
time.sleep(0.01)
except KeyboardInterrupt:
print(" Quit") |
Worksheet SixCircuitThe circuits for LEDs and buzzer have not changed since Worksheet Two. Code# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)
# Worksheet 5 - Movement
# Import Python header files
import time
from machine import Pin
print("PIR Module Test (CTRL-C to exit)")
# Set pins as input/output
pir = Pin(28, Pin.IN)
red = Pin(2, Pin.OUT)
blue = Pin(3, Pin.OUT)
buzzer = Pin(4, Pin.OUT)
# Variables to hold the current and last states
currentstate = 0
previousstate = 0
try:
print("Waiting for PIR to settle ...")
# Loop until PIR output is 0
while pir.value() == 1:
currentstate = 0
print(" Ready")
# Loop until user quits with CTRL-C
while True:
# Read PIR state
currentstate = pir.value()
if currentstate == 1 and previousstate == 0:
# PIR is triggered
print(" Motion detected!")
# Flash lights and sound buzzer three times
for x in range(0, 3):
buzzer.on()
red.on()
time.sleep(0.2)
red.off()
blue.on()
time.sleep(0.2)
blue.off()
buzzer.off()
time.sleep(0.2)
# If the PIR has returned to ready state
elif currentstate == 0 and previousstate == 1:
# PIR has returned to ready state
print(" Ready")
previousstate = currentstate
# Wait for 10 milliseconds
time.sleep(0.01)
except KeyboardInterrupt:
print(" Quit") |
Thank you so much. I plan to work on the 'official' worksheets when I am
next ashore.
…On Sun, 13 Mar 2022, 11:56 Andrii Annenko, ***@***.***> wrote:
Worksheet Six Circuit
Same as in the Worksheet Five
Code
# CamJam EduKit 2 - Sensors (Raspberry Pi Pico)# Worksheet 5 - Movement
# Import Python header filesimport timefrom machine import Pin
print("PIR Module Test (CTRL-C to exit)")
# Set pins as input/outputpir = Pin(28, Pin.IN)red = Pin(2, Pin.OUT)blue = Pin(3, Pin.OUT)buzzer = Pin(4, Pin.OUT)
# Variables to hold the current and last statescurrentstate = 0previousstate = 0
try:
print("Waiting for PIR to settle ...")
# Loop until PIR output is 0
while pir.value() == 1:
currentstate = 0
print(" Ready")
# Loop until users quits with CTRL-C
while True:
# Read PIR state
currentstate = pir.value()
if currentstate == 1 and previousstate == 0:
# PIR is triggered
print(" Motion detected!")
# Flash lights and sound buzzer three times
for x in range(0, 3):
buzzer.on()
red.on()
time.sleep(0.2)
red.off()
blue.on()
time.sleep(0.2)
blue.off()
buzzer.off()
time.sleep(0.2)
# If the PIR has returned to ready state
elif currentstate == 0 and previousstate == 1:
# PIR has returned to ready state
print(" Ready")
previousstate = currentstate
# Wait for 10 milliseconds
time.sleep(0.01)
except KeyboardInterrupt:
print(" Quit")
—
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABDNQQV5SXLZW672ZK5YS6DU7XJWHANCNFSM5JNGN56Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Great! Thanks for the heads up! |
Hi,
I would like to suggest an idea to add worksheets for Raspberry Pi Pico to this repository.
Micropython port for Pico has everything needed to implement all projects from the worksheets. It even has a built-in support for a DS18x20 family of temperature sensors, so the code in the third worksheet could look like this:
or a
Timer
could be used to keep the Pico responsive:Here's a setup:
To implement multiple projects from the worksheets together, jump wires could be connected directly to the pins on the Pico. Although it would not look as clean as with a Raspberry Pi, it would still work.
The text was updated successfully, but these errors were encountered: