I attended parents’ orientation night for my to-be-grade-seven daughter this Spring, and all was fine until I noticed LOCKERS…… it felt like yesterday that I was helping my little 3 year old put her sun bonnet into her cubby at pre-school, and now she is about to attend a schoold with lockers. Lockers that in my day held no end of contraband, Led Zepplin posters, graffiti, inappropriatenotes, dirty gym clothes……. I almost passed out.
Later that night our Principal shared that a school tradition is that fathers were invited to decorate their kids’ lockers just before school started….. my wheels started turning. How about a locker Jukebox that would play a different playlist on each day whenever the door was opened. It could play holiday music at holidays, spooky sounds around Halloween, awful birthday songs around birthdays, “I have a dream” for MLK day…. Nobody’s done a musical MOTD for lockers that I could google – we would rock that locker and every day that a new playlist would kick off my kid would think “My dad is such a nerd”. Perfect.
The software flow would be boot, look up the date, use the date to look up the desired playlist in a calendar, dip the EEPROM to see what track was last played then plan the next track in the playlist du jour. Bit of multidimensional arrays and reverse engineering Chinglish documentation. Cake.
So – high level design. Arduino doesn’t have the horsepower nor the library to do native MP3 decoding, so I ordered a standalone MP3 player with a serial control interface and grabbed an arduino nano out of my box and a realtime clock:
The gotcha dragons that needed to be slain were:
he MP3 module BARELY supports FAT 16/32…. it doesn’t understand filenames, the ORDER of file entries in the FAT system is what it uses….. practically that means “random file play order” unless you use a FAT sorter program like “FAT Sorter” – “Play file 1” will play the first file loaded onto the media, regardless of name. Really – repeated for emphasis, the MP3 player can only play a file based on which FAT entry number it is.
So – how to bolt it together? The realtime clock (RTC) gets plumbed to IC2 interface, the MP3 player is connected to the serial interface, speaker to the MP3 player and power for all…. done (insert cheezy schematic or napkin diagram). To keep power usage low, I use a normally-open SPST switch (epoxied to a rare earth magnet) to apply power to the system (from a USB emergency power bank $5 brick), whenever the locker door opens. System boots, plays the next song in the current playlist.
Fritzing (neat if perhaps a tad buggy) didn’t have the MP3 module so I used a generic 28 pin doomahickus (right hand side module) to represent it. Note that there are only half a dozen interconnects, plus power – simple and easy. Transmit wired to Receive (visa versa). The battery illustrated is really a USB “emergency backup” battery that I put a microswitch on – when the locker door opens it provides 5V to the USB port of the nano which powers the MP3 module. The microswitch is epoxied to a rare earth magnet that came out of a hard drive.
Construction is REALLY hinky – I just taped two small (free) protoboards together and used jumpers to wire the whole thing up. I wrapped it in racer tape, and called it a day. Yes, etching a board would have been more elegant, this took literally two minutes.
Not shown in the code is the “how to program a 1307 module” I’d programmed mine for an earlier project – use your google-fu to find a sketch you like to program the time into a 1307 and run it first.
The code is pretty straightforward – note that the MP3 player takes a second or two to cold-boot (the main setup delay), the calendar uses 31 days for every month (I couldn’t figure out a more compact way than just wasting 16 or 20 bytes on nonexistent days, sorry), every day lists a playlist, every playlist contains 10 songs, each song is an ordinal “which song number after FAT sorting the micro-sd card” index that is passed to the MP3 player.
In the code below you’ll see thirty odd playlists that are invoked by season, by day, etc.
It took far longer to curate the playlist than to program/wire/enclose the project, so prepare to spend time here.
ARDUINO Code available here.
I left in the debug serial.print stuff because it doesn’t take up much room, and you’ll probably want to mess around a bit with it in place.
What would I add?
The original idea was to also have a tricolor LED strip that would play a related (curated) color sequence per song. I didn’t want to mess with also having a 12V supply, and the buck/buck switcher I ordered got lost en route from China so that led to a “Plan B” involving listening to the MP3 output with an analog input, doing a simple fast fourier-type transform to get freq bin / amplitude info then doing a color organ.
Midway through the code I realized “doing a transform to pseudo-frequency domain representation of an MP3 is really, really, really stupid” so I took yet another detour to look at Cypress who now sell an integrated SOC with a magical on-wafer FPGA capability. The NEXT rev is going to have a SW defined “old school” analog domain color organ (bandpass filter feeding an integrator that will report to the micro) which will drive an algorithm to represent the music based on the color organ input. I’ll ditch the arduino for a Cypress PSOC4, but I need to get smarter about FPGA first.
For the time being though, this will be the “MVP” feature set.
We are open! See our COVID-19 Phase III reopening guidelines.