Halloween Butler with Raspberry Pico

Let’s make a Halloween Butler with Raspberry Pico and CircuitPython. In CircuitPython, there is the MP3 library for playing audio clips, directly from the Pico’s flash memory. So it will be easy to add a speaker and play some Halloween tunes, while also controlling LED-lights and servo motors.

To connect the devices into the Raspberry Pico we need to draw a circuit drawing and select the used pins. Then we can try to use those in pins the code. But sometimes when working with the code, we need to try with code and change later some pins, because of the how the Pico device operates with PWM signals. If changing the pin in the later code, we also need to remember to change the circuit drawings.

To start coding first we need to install the Thonny code editor

(Previous blog post here: https://koodinkutoja.com/raspberry-pico-testing-with-ultrasonic-sensor-and-led-light-strip-thonny-code-editor/)

Then we need to install the CircuitPython to the Raspberry Pico device

https://learn.adafruit.com/welcome-to-circuitpython/what-is-circuitpython

https://downloads.circuitpython.org/bin/raspberry_pi_pico/en_US/adafruit-circuitpython-raspberry_pi_pico-en_US-9.2.0.uf2

We need to press the button on Pico, while connecting the USB-cable. After that we can copy the .uf2 file to the Pico device:

After copy finishes, Pico will reboot automatically and new window opens:

Now we have the CircuitPython installed to the Pico device and we can start programming.

Let’s configure the Thonny code editor to use CircuitPython and select the correct COMX-port:

Now we can add the MP3 library and start writing the Halloween theme functionality to the code.

(Previous instructions how to add the library: https://koodinkutoja.com/tehdaan-hirvittava-soittorasia/ )

Let’s save the new code to the Raspberry Pico flash memory (CircuitPython device).

We can write the file code.py over. By default there is just a “Hello World” line.

When we write the main .py file as code.py, it should automatically start, when powering up the Raspberry Pico device.

Then we of course need to copy and save the .mp3 file to the Pico flash memory:

Now we can try to press the “Play button” at the Thonny code editor to start the python program.

We should start to hear the .mp3 file play out at the speaker and after the play finishes “Thonny Shell terminal” should also have a new message, “Playing Audio”.

Modify the MP3 file with Audacity to adjust volume up

( More information here: https://koodinkutoja.com/playing-audio-clips-with-arduino/ )

Let’s add LED stripe control to the code

We can also add the NeoPixel LED-strip control to our code.

https://learn.adafruit.com/circuitpython-essentials/circuitpython-neopixel

Copy the adafruit neopixel lib to the Pico /lib/ folder:

Then let’s modify the code.py

Adding the servo to move the Skull position

Pico can also control servo motor positions, with control pulses. More information can be found from the Adfruit website; https://learn.adafruit.com/circuitpython-essentials/circuitpython-servo https://www.adafruit.com/product/169

Also if searching from Youtube, video tutorials are available;

To be able to use the Adafruit Circuit python libraries

We need to download the .zip file and then extract and copy the library to the /lib folder of the Pico device.

https://github.com/adafruit/Adafruit_CircuitPython_Bundle

Check if you are using version 8 or 9 of the CircuitPython on your Raspberry Pico device.

https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/download/20241103/adafruit-circuitpython-bundle-9.x-mpy-20241103.zip

Copy the needed libraries into the Raspberry Pico device flash memory /lib folder.

Then add the servo control to the code..

Now we can also add the Ultra sonic distance sensor for detecting human motion

It would be nice to be able to detect if some person is coming nearby the Butler, and trigger the sound and movement. So let’s try to add a ultrasonic distance sensor to the Butler.

(Previous instructions how to add the Ultra Sonic sensor can be found from here: https://koodinkutoja.com/raspberry-pico-testing-with-ultrasonic-sensor-and-led-light-strip-thonny-code-editor/ )

Then we need to change the code again, to add the person detection. We can use the Adafruit CircuitPython HCSR04 library. https://github.com/adafruit/Adafruit_CircuitPython_HCSR04

Then modify the code and add measuring the distance. And add some logic if the distance is small, then trigger the MP3 play out to the speaker.

And when adding into the project:

https://github.com/hennahoo/Raspberry-Pico-Halloween-Butler