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.

Figure 4: Small functionally complete (top, with buttons and connectors for speakers) and bare-board (bottom) MP3 players.

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
Figure 5: DFPlayer Mini pinout.

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.

Figure 6: A prototype of the electronic Christmas music box created with a Trinket M0 microcontroller. The capacitive buttons can be operated through the housing.

The Author

Bernhard Bablok works at Allianz Technology SE as an SAP HR developer. When he's not listening to music, cycling or walking, he deals with topics related to Linux, programming, and small computers. He can be reached at mailto:mail@bablokb.de.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Adafruit PyPortal

    Unlike other displays for the Raspberry Pi, Adafruit's PyPortal touchscreen provides an autonomous environment, including a microprocessor, sound output, and a WiFi connection.

  • Light Painting

    In the photographic method of light painting, you expose a subject over an extended period of time while moving the light sources. With a little technical support from a Raspberry Pi Pico, you can achieve sophisticated results.

  • Google Announces Its Own Pixel Phones

    Google finally enters the phone hardware business.

  • Halloween Vending Machine

    A Halloween vending machine frightens visitors, but the braver ones receive a chocolate reward.

  • TUXEDO InfinityBook Gen7 MK1

    The next-generation laptop from TUXEDO is faster and lighter than previous business models.

comments powered by Disqus
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.

Learn More

News