Christmas fun for makers
Music Off
Microcontrollers struggle to play music, and the Pi Zero isn't exactly famous as one of the best devices for multimedia applications. The Zero comes without a headphone output, and the Bluetooth adapter is not very useful for sound playback. Pairing takes time, and small Bluetooth loudspeakers tend to switch off autonomously at the most unfavorable moment to save power.
A small and cheap MP3 player is a good alternative. These devices have a small mono amplifier and a microSD card slot directly on the board. The players are available in two versions: "bare board," with just some solder joints for the pins, and functionally complete, with a few small buttons (Figure 4). Dealers on Amazon often deliver the components domestically. But they are often significantly cheaper if imported directly from China on EBay.
The bare-board version offers a little more flexibility in terms of control. Preassembled mini-loudspeakers with soldered-on socket connectors are also available for a low price. In terms of sound quality, these simple speakers are not totally convincing, but the sound pretty much matches output from small players and definitely beats the jingling of mechanical music boxes hands down. For a retro feel, though, you could record the sound of an old music box and play the recordings back on the MP3 player. I couldn't find anything suitable on the web that could be downloaded easily.
The preconfigured version of the player has a few useful features. As soon as power is applied, the device plays all the songs; it even remembers the last song playing when it was switched off. However, the layout makes it a bit difficult to integrate into projects: The buttons need to be accessible, but all the other elements are just a nuisance. You would definitely want to hide the connection terminals for the speaker. Power consumption in operation is also higher than for the plain version (150-350mA compared with 100-200mA).
In my project, I went for the plain vanilla version. The data sheet [4] helped with the wiring. Two buttons on pins IO_1 and IO_2 (Figure 5) can be used to control the volume and to toggle back and forth between songs. To get the music playing immediately after powering on, the Trinket M0 briefly switches pin IO_2 to ground (Listing 3) during initiation. The complete implementation, including the required wiring, is on GitHub [5].
Listing 3
DFPlayer Mini Control
01 from digitalio import DigitalInOut, Direction, Pull 02 03 NEXTKEY_PIN = board.D1 04 05 nextkey = DigitalInOut(NEXTKEY_PIN) 06 nextkey.direction = Direction.OUTPUT 07 nextkey.value = 0 08 time.sleep(0.2) 09 nextkey.value = 1
Tinkering Time
I deliberately kept the electronic part of the project minimal. The whole thing relies on an external micro-USB power supply. If you are ahead of the game, you will probably want to use a lithium polymer battery with a charging circuit and various switches to control the lighting effects, movement, and music. Because the I/O pins on the Trinket M0 are capacitive, the buttons can even be hidden away inside the music box. However, the five pins of the Trinket M0 can prove restrictive, so you might need a larger microcontroller.
The rest of the project is old fashioned pre-Christmas handicraft: Choose a material that suits you or that you already have. Christmas cookie tins, for example, provide a base that suits the time of year, and figurines are available from the Christmas sections of many stores. If you own a 3D printer, you can even manufacture the moving parts yourself. Figure 6 shows a prototype. The packaging from a recent writable CD purchase was upcycled for the base. Also, be sure you don't underestimate the space you need for the board, cables, speakers, and motor.
Infos
- Trinket M0: https://www.adafruit.com/product/3500
- NeoPixel Überguide: https://learn.adafruit.com/adafruit-neopixel-uberguide/the-magic-of-neopixels
- Fitec FS90R continuous servo: https://www.addicore.com/FS90R-Servo-p/ad314.htm
- DFPlayer Mini data sheet: https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299
- Example code for the project: https://github.com/bablokb/xmas-music-box
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.