This is a great weekend project to undertake, to get you in the holiday spirit ! In all, it should be a few hours of 3D printing, and then an hour or so in soldering the circuit together, and uploading the python code to the Pi. As part of the build I am using a Raspberry Pi Zero W as the heart of the project, and a RGB led strip (APA102) to diffuse the LEDs through the 3D printed tree . In addition I am also using an I2S class D mono Amp breakout board by Adafruit based on MAX98357 chip and a small 8 ohms speaker, to play some Holiday songs.
Update #1 - 3D printing
Here is a picture of the 3D printed parts, the base and the electronic holder are printed in Red Hatchbox 1.75 mm PLA, and the tree is printed in Transparent PLA with 15% infill to help with the LED diffusion.
- Raspberry Pi Zero W
- APA102 RGB led strip
- I2S class D mono Amp breakout board by Adafruit based on MAX98357 chip
- 8 ohms speaker
Update 2 - Circuit
As part of the circuit here are connection for the APA102 LED strip to the Raspberry Pi zero.
- Power to pin 2 on the Pi (5V Power)
- GND to pin 6 on the Pi GND
- Data to pin 16
- Clock to pin 18
Connect Adafruit MAX98357 I2S Class-D Mono Amplifier to the following pins on the Pi
- Vin to pin 4 on Pi 5V
- GND to pin 9 Pi GND
- DIN to pin 12
- BCLK to pin 40
- LRCLK to pin 35
Update #3 Software setup
Using your computer flash the latest version of Rasbian-lite img on an SD card (Download link for the img file https://www.raspberrypi.org/downloads/raspbian/). And then add the SD card to the Raspberry Pi and connect your Pi to the your WiFi router and make a note of the IP address, then SSH into your Pi
Start by running the two commands below to update and upgrade the packages on the Pi.
sudo apt-get update sudo apt-get upgrade
Now, install the blinkt package written by the awesome folks at Pimoroni. And then get rainbow.py example from blinkt github repo using wget.
sudo apt-get install python-blinkt sudo wget https://raw.githubusercontent.com/pimoroni/blinkt/master/examples/rainbow.py
And then run the python program with the command below, and you should see your LED strip cycle through colors as shown in the third picture above.
sudo python rainbow.py
Now to setup and test the Adafruit’s MAX98357 I2S Class-D Mono Amp, follow the guide on the Adafruit Learning system at - https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp/pinouts?view=all. Basically as part of the setup there is an easy setup and a difficult setup, if you plan to run the easy route just download and run the following shell script
curl -sS https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2samp.sh | bash
To check if the shell script ran successfully, and you are able to hear sound from the speaker run
speaker-test -c2 --test=wav -w /usr/share/sounds/alsa/Front_Center.wav
And to adjust the volume use alsamixer command
Update #4 Setting up Mopidy to play your favorite tunes
Now to play you favorite tunes we are going to setup Mopidy and a web client for mopidy, so that you can play your song from your mobile/table. Mopidy plays music from local disk, Spotify, SoundCloud, Google Play Music, and more. You edit the playlist from any phone, tablet, or computer using a range of MPD and web clients. In my case for the holiday season the idea is to play my favorite Holiday songs/Christmas carols , and once the holiday season is over I plan to install youtube-dl to download podcast from youtube in a mp3 format and then listen to it when I find time.
Now lets install Mopidy run the following command
sudo apt-get install mopidy
for more info check out the documentation at - Installation — Mopidy 2.0.1 documentation
Modify the mopidy.conf to enable the HTTP,MPD and Files sections, here is my mopidy.conf, and my local directory to store musing is /home/pi/Music , so if you plan on using the .conf file below create a “Music” directory in the home folder
sudo nano /etc/mopidy/mopidy.conf
Here is a copy of my mopidy.conf file
# For further information about options in this file see: # http://docs.mopidy.com/ # # The initial commented out values reflect the defaults as of: # Mopidy 2.2.1 # Mopidy-File 2.2.1 # Mopidy-HTTP 2.2.1 # Mopidy-Local 2.2.1 # Mopidy-M3U 2.2.1 # Mopidy-MPD 2.2.1 # Mopidy-SoftwareMixer 2.2.1 # Mopidy-Stream 2.2.1 # # Available options and defaults might have changed since then, # run `mopidy config` to see the current effective config and # `mopidy --version` to check the current version. [core] cache_dir = $XDG_CACHE_DIR/mopidy config_dir = $XDG_CONFIG_DIR/mopidy data_dir = $XDG_DATA_DIR/mopidy max_tracklist_length = 10000 restore_state = false [logging] #color = true #console_format = %(levelname)-8s %(message)s #debug_format = %(levelname)-8s %(asctime)s [%(process)d:%(threadName)s] %(name)s\n %(message)s #debug_file = mopidy.log #config_file = [audio] #mixer = software #mixer_volume = #output = autoaudiosink #buffer_time = [proxy] #scheme = #hostname = #port = #username = #password = [mpd] enabled = true hostname = 0.0.0.0 port = 6600 password = max_connections = 20 connection_timeout = 60 zeroconf = Mopidy MPD server on $hostname command_blacklist = listall listallinfo default_playlist_scheme = m3u [http] enabled = true hostname = 0.0.0.0 port = 6680 static_dir = zeroconf = Mopidy HTTP server on $hostname allowed_origins = csrf_protection = true [stream] #enabled = true #protocols = # http # https # mms # rtmp # rtmps # rtsp #metadata_blacklist = #timeout = 5000 [m3u] enabled = true base_dir = default_encoding = latin-1 default_extension = .m3u8 playlists_dir = [softwaremixer] #enabled = true [file] enabled = true media_dirs =/home/pi/Music # $XDG_MUSIC_DIR|Music # ~/|Home excluded_file_extensions = .jpg .jpeg show_dotfiles = false follow_symlinks = false metadata_timeout = 1000 [local] enabled = true library = json media_dir = /home/pi/Music scan_timeout = 1000 scan_flush_threshold = 100 scan_follow_symlinks = false excluded_file_extensions = .directory .html .jpeg .jpg .log .nfo .png .txt
If you plan on using a web app on the phone/tablet, you will need an http web client, I like the Mopidy-Mobile..
sudo pip install Mopidy-Mobile
To run mopidy on boot run, and restart you pi
sudo systemctl enable mopidy sudo reboot
Also, if you plan to load more mp3/.wav files into the Music folder in the future, you will have to run a scan command, so that songs show up in the Mopidy-Mobile client using
sudo mopidyctl local scan
And then use the mobile client open url in your browser on your mobile/computer -- http://IpAddressOfPi:6680/ and play your favorite tunes and songs, in my case I have download some creative commons music from the youtube audio library for the video demo, which you see in the screenshot below..
Update #5 3D print a Post Card/ Photograph holder
Soo the Holiday season is over !! this means you can replace the top 3D printed tree with a post card holder, as you see in the picture below..
And here is a video demo ..