Cytron Maker Pi Pico Demo¶
The Cytron Maker Pi Pico carrier accepts a standard Raspberry Pi Pico and adds buttons, LEDS, speaker, audio jack, SD card slot, Grove connectors, and a WiFi module socket. It doesn’t include the Pi Pico itself.
Blink All¶
The board includes indicator LEDs on all the available GPIO pins in addition to a single color NeoPixel.
1# blink_all.py
2
3# Demo for the Cytron Maker Pi Pico with Raspberry Pi Pico installed.
4# Blink all the available LEDs.
5
6import board
7import time
8
9# load the CircuitPython GPIO support
10from digitalio import DigitalInOut, Direction, Pull
11
12# load the low-level CircuitPython NeoPixel support
13from neopixel_write import neopixel_write
14
15#---------------------------------------------------------------
16# list of all the blue indicator LED pins in pin order
17indicator_pins = [
18 # left side, top to bottom
19 board.GP0, board.GP1,
20 board.GP2, board.GP3, board.GP4, board.GP5,
21 board.GP6, board.GP7, board.GP8, board.GP9,
22 board.GP10, board.GP11, board.GP12, board.GP13,
23 board.GP14, board.GP15,
24
25 # right side, bottom to top
26 board.GP16, board.GP17,
27 board.GP18, board.GP19, board.GP20, board.GP21,
28 board.GP22,
29 board.GP26, board.GP27,
30 # board.GP28, this indicator LED is shared with the NeoPixel
31 ]
32
33# the NeoPixel in on GP28
34neopixel = DigitalInOut(board.GP28)
35neopixel.direction = Direction.OUTPUT
36
37# the LED on board the Pico is GP25
38Pico_LED_pin = board.LED
39
40#---------------------------------------------------------------
41# Create a list of output devices to flash in order.
42outputs = [DigitalInOut(pin) for pin in indicator_pins]
43outputs.append(DigitalInOut(Pico_LED_pin))
44
45# and set them all to output
46for io in outputs:
47 io.direction = Direction.OUTPUT
48
49#---------------------------------------------------------------
50
51# run forever
52while True:
53 # sequence the LEDs on and off
54 print("strobing LEDs")
55 for io in outputs:
56 io.value = True
57 time.sleep(0.05)
58 io.value = False
59
60 # cycle through colors on the NeoPixel: green, red, blue, off
61 for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 0, 0)):
62 print("neopixel color:", color)
63 neopixel_write(neopixel, bytearray(color))
64 time.sleep(0.25)
Play Tones¶
This demo uses the tones.py module from Music and Rhythm Examples - CircuitPython to
generate musical tones on the buzzer. To try it, please copy the tones.py
file to the top level of the CIRCUITPY drive, then copy the code below into
code.py on CIRCUITPY.
1# play_tones.py
2
3# Demo for the Cytron Maker Pi Pico with Raspberry Pi Pico installed.
4# Play a melody on the buzzer.
5
6# This uses the tones module from the music/ folder of the course sample code.
7# The tones.py file should be copied to the top level of the CIRCUITPY drive.
8
9import board
10import time
11
12# load the speaker driver module
13import tones
14
15#---------------------------------------------------------------
16# create an I/O object for the buzzer on GP18
17speaker = tones.ToneSpeaker(board.GP18)
18
19#---------------------------------------------------------------
20# run forever
21while True:
22 # play a major C scale up and down
23 for note in [60, 62, 64, 65, 67, 69, 71, 72, 71, 69, 67, 65, 64, 62, 60]:
24 speaker.midi_tone(note)
25 time.sleep(0.125)
26
27 speaker.noTone()
28 time.sleep(2.0)