Skip to content

How to build a music box (not only) for children based on Raspberry Pi and NFC.

Notifications You must be signed in to change notification settings

layereight/nfc-music-box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nfc-music-box

This tutorial shows how to build a music box (not only) for kids based on Raspberry Pi and NFC tags. The software is mainly based on Volumio which is a very nice music player distribution for the Raspberry Pi. Another small piece of software called MFRC522-trigger detects NFC tags with a NFC reader and triggers certain actions in Volumio (e.g. play playlists, stop playback).

If you have the impression that the how-to is unclear in certain parts or you're missing something, feel free to write an issue or simply create a pull request. Helping hands are highly appreciated.

Hardware

Components

Item Picture Price (EUR) Links
Raspberry Pi Zero W Raspberry Pi Zero W 10.35 - 17.49
Multi-pin Connector Multi-pin Connector 0.40
MicroSD Card (min. 8GB) MicroSD Card 4.99 - 7.85
RC522 NFC Reader NFC Reader 3.80 - 4.99
NFC Tags NFC Tags 0.69 - 1.10
Hifiberry MiniAmp Hifiberry 13.90 - 20.90
2x Speakers 3W Speaker 5.24 - 9.32
Speaker Cable Speaker Cable Optional. Simple copper wire might be enough for 3W speakers.
Powerbank (charge-through/pass-through) Powerbank 11.99 - 13.49
2x E Capacitor 4700 µF 6.3V E Capacitor 0.37 - 2.09
Inductor 33 µH 1,5A Inductor 0.41
Micro-USB Power Supply Power Supply 6.99 -
Micro-USB Jack Micro USB Jack 3.10
4x Spacer 10mm Spacer 0.92
8x Screw 5mm Screw 0.32
8x Washer Washer 0.24
Dupont Jump Wire male/female Jump Wire male 2.90
Braided Copper Wire Copper Wire 0.69
Switch Switch 0.55
Push Button Push Button 0.48
1x LED LED 0.10
1x 1K Ohm Resistor Resistor 0.06
Case Case Possibilities are limitless. :-) See MiczFlor/RPi-Jukebox-RFID#5 (beware, very long loading time) for some inspiration.
Figures Figure Optional. In case you wanna have physical objects you can attach your NFC stickers to. Again possibilities are limitless.

Wiring Diagram

Music Box Wiring Diagram

Assemble the Components

Since the Hifiberry Amplifier will take the whole multi-pin connector on the upper side of the Raspberry Pi, we will have to solder all the other connections to the bottom side. So when it comes to pin numbering you will always have to think upside down. TODO: add photos

Multi-Pin Connector

  • solder the multi-pin connector to the Raspberry Pi, it's 40 pins, so a good warm-up ;-)

Speaker Cable

  • cut 2 times the right length of speaker cable (or just standard copper wire) for the speakers
  • dismantle and tin-coat all 8 ends
  • solder the cables to the speakers (if you have speaker cable, the anode + is usually marked in red)

NFC Reader

  • there is a 8-pin connector for the NFC reader board, that we need to solder
  • depending where and how you wanna put the NFC reader in you case later, you have do decide to which side of the board the connector should face
  • solder 8x the male side of jump wire to the Raspberry Pi, also see https://github.com/ondryaso/pi-rc522#connecting
    • pin 17 red (3.3V power)
    • pin 19 orange (GPIO10, SPI MOSI)
    • pin 21 green (GPIO9, SPI MISO)
    • pin 23 yellow (GPIO11, SPI SCKL)
    • pin 18 brown (GPIO24, IRQ)
    • pin 20 black (GND)
    • pin 22 blue (GPIO25, RST)
    • pin 24 white (GPIO8, SPI CE0)
  • connect 8x the female side of the jump wire to the NFC reader
    • SDA white
    • RST blue
    • GND black
    • IRQ brown
    • SCK yellow
    • MISO green
    • MOSI orange
    • 3.3V red
  • note: depending on which range you will have to span in your case, you might either want to buy longer jump wire or simply connect 2 jump wires one after another

Status LED

  • first solder the resistor to the LED, since they are connected in series it doesn't matter which side (anode + or cathode -)
  • cut 2 times the right length of copper wire, the length depends on what ranges you will have to span in your case later
  • dismantle and tin-coat all 4 ends
  • first solder one cable to the open end of the LED, and the other cable to the resistor that is already connected to the led
  • now when soldering the cables to the Raspberry Pi, you will have to consider the polarity of the LED
  • the cathode (-) is the side with the slidely shorter pin that is also flat on the LED's head
  • the anode (+) is simply the other side
  • the cable on the cathode (-) side of the LED goes to pin 14 (GND)
  • the cable on the anode (+) side of the LED goes to pin 8 (GPIO24, UART0 TXD)

Push Buttons

  • cut 6 times the right length of copper wire, the length depends on what ranges you will have to span in your case later
  • dismantle and tin-coat all 12 ends
  • solder one wire to each connector of the push buttons
  • solder the free ends of the shutdown button to the Raspberry Pi
    • pin 7 (GPIO4)
    • pin 9 (GND)
  • solder the free ends of the vol- button to the Raspberry Pi
    • pin 29 (GPIO5)
    • pin 30 (GND)
  • solder the free ends of the vol+ button to the Raspberry Pi
    • pin 33 (GPIO13)
    • pin 34 (GND)
  • polarity doesn't matter, they are just push buttons

Power Supply Buffer

  • note: the buffering capacitors (and the inductor) are just used to cover scenarios where you wanna charge the powerbank while the Raspberry Pi is running (at the same time), when you're charging your powerbank with the Raspberry Pi switched off you may not need them
  • to have our music box portable we've bouhgt a special kind of powerbank as power supply, they are called charge-through or pass-through powerbanks, they have the ability to deliver power and being charged at the same time
  • also they do not need a button on the powerbank being pressed to activate power delivery
  • however, almost all of these powerbanks I've seen cannot be used as uninterruptible power supply (UPS) directly
  • when you unplug the external power supply after charging, they will discontinue to deliver power to the connected device they are charging for a very short moment, for a sensible Raspberry Pi this moment is too long and it will simply shut off and restart
  • this is why we'll need a small buffer to cover those small interruptions
  • TODO: how to wire the capacitors and inductor, this section is still in development

Hifiberry Aplifier

  • simply mount the Hifiberry Miniamp aplifier to the multi-pin connector (that you soldered earlier) on the upper side of the Raspberry Pi
  • the Hifiberry Miniamp uses following pins
    • pin 12 (GPIO18)
    • pin 35 (GPIO19)
    • pin 36 (GPIO16)
    • pin 37 (GPIO26)
    • pin 38 (GPIO20)
    • pin 40 (GPIO21)
  • also see https://www.hifiberry.com/docs/hardware/gpio-usage-of-hifiberry-boards/

MPU6050

  • the MPU-6050 is a digital accelerometer and gyroscope
  • the use of the MPU6050 module can be considered experimental and is totally optional
  • it is used for additional control of the music box by motion gestures
  • also see https://github.com/layereight/MPU6050-trigger

Software

Download, install and configure Volumio

  • download and install volumio: https://volumio.org/get-started/
  • current version of Volumio is 3.x
  • e.g. for linux:
    • unzip the disk image unzip Volumio-3.251-2022-03-31-pi.zip
    • insert the sd-card and find its device lsblk
    • copy the image to sd-card, e.g. sudo dd if=Volumio-3.251-2022-03-31-pi.img of=/dev/mmcblk0 status=progress
  • start, configure volumio, also see https://volumio.org/get-started/
    • on the very first boot of Volumio and on a Raspberry Pi with on-board WiFi, Volumio will enable a Wifi Access Point called Volumio
    • when Volumio boots up you should be able to see the Volumio AP, e.g. from your Laptop
    • connect to the Volumio AP, the default password is "volumio2"
    • open a browser http://volumio.local/ or http://192.168.211.1/
  • do the Volumio setup wizard
    • chose a language
    • (re-)name your box, let's say to music-box
    • configure audio output
      • enable I2S DAC
      • chose "HifiBerry DAC" from the list
    • configure Wifi networking
      • chose your home Wifi from the list and enter your Wifi password
      • after reboot, Volumio will try to connect to your home Wifi
    • skip the "add your music" step for now
    • you're done, Volumio will prompt your to reboot your music box
  • after reboot you should already be able to hear the Volumio startup sound when Volumio has booted up
  • connect your laptop back to your home Wifi
  • your laptop and your Volumio music box will now be in the same network
  • the HifiBerry MiniAmp doesn't have a hardware mixer so you will have to configure a software mixer in order to be able to control the volume
    • open http://music-box.local/ in a browser
    • goto "Playback Options" in the menu
    • go down to "Volume Options"
    • chose "Software" as mixer type and press "Save"
    • the "Volume Options" will update after a short while
    • now also configure a "Default Startup Volume", e.g. 60, press "Save" again
    • in the main "Playback" screen of the Volumio web interface you will now be able to control the volume
    • try play some music, in the main "Browse" screen there is "Web Radio" and then "Volumio Selection", just chose one of the radio stations to play, Volumio should now start to play the web stream of the radio station :-)

Enable volumio ssh access

Install NFC Reader Software on your Volumio

$ git clone https://github.com/layereight/MFRC522-trigger.git
$ cd MFRC522-trigger/ansible
$ vim inventory
  • replace the contents of the file inventory to point to your music box (e.g. music-box.local)
[my_pi]
music-box.local ansible_user=volumio ansible_ssh_pass=volumio ansible_sudo_pass=volumio
  • execute the ansible playbook, it runs for roughly 12 minutes
$ ansible-playbook -i inventory MFRC522-trigger.yml 

PLAY [Install prerequisite software] ************************************************

TASK [Run apt-get update if cache is older than a week] *****************************
ok: [music-box.local]

TASK [Install prerequisite debian packages] *****************************************
changed: [music-box.local]

TASK [Install prerequisite pip packages] ********************************************
changed: [music-box.local]

TASK [Install pi-rc522 python library] **********************************************
changed: [music-box.local]

PLAY [Prepare Raspberry Pi's /boot/config.txt] **************************************

TASK [Alter /boot/config.txt] *******************************************************
changed: [music-box.local]

TASK [Reboot the machine when /boot/config.txt was changed] *************************
changed: [music-box.local]

PLAY [Clone MFRC522-trigger from github] ********************************************

TASK [Create devel directory] *******************************************************
changed: [music-box.local]

TASK [Clone MFRC522-trigger from github] ********************************************
changed: [music-box.local]

TASK [Copy config.json from sample file] ********************************************
changed: [music-box.local]

PLAY [Install MFRC522-trigger as systemd service] ***********************************

TASK [systemd : Copy custom systemd service file] ***********************************
changed: [music-box.local]

TASK [systemd : Enable custom systemd service] **************************************
changed: [music-box.local]

TASK [systemd : Copy custom systemd service file] ***********************************
changed: [music-box.local]

TASK [systemd : Enable custom systemd service] **************************************
changed: [music-box.local]

TASK [systemd : Copy custom systemd service file] ***********************************
skipping: [music-box.local]

TASK [systemd : Enable custom systemd service] **************************************
skipping: [music-box.local]

PLAY RECAP **************************************************************************
music-box.local: ok=12 changed=11 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0

Copy Content to your Music Box

  • on the network Volumio exposes a couple of samba shares (windows shares)
  • e.g. on Windows in the windows explorer (the file manager) enter "\\music-box.local"
  • on Linux (when your file manager has a samba plugin) enter "smb://music-box.local"
  • one of the shares is called "Internal Storage"
  • just copy your music files there
  • Volumio will pick them up and add them to its music library automatically
  • also see https://volumio.github.io/docs/FAQs/Audio_Sources.html the very last paragraph
  • you can put your music, audio books, etc.
  • Volumio is able to play a various amount of formats, see: https://volumio.github.io/docs/FAQs/General.html the paragraph "Readable formats"

Create Playlists from you Content

Configure MFRC522-trigger to trigger a Volumio Playlist

  • ssh into your Volumio music box: ssh [email protected]
  • the software should be running, check whether the software is running
$ ps awwwx | grep python
15269 ?        Ssl    0:03 python3 /home/volumio/devel/MFRC522-trigger/MFRC522-trigger.py
  • hold 1 or 2 NFC tags against your NFC reader
  • have a look a the MFRC522-trigger logfile, it should look something like this
$ cat ~/devel/MFRC522-trigger/MFRC522-trigger.log 
2019-02-24 18:08:39,714 INFO Welcome to MFRC522-trigger!
2019-02-24 18:08:39,716 INFO Press Ctrl-C to stop.
2019-02-24 18:11:50,020 WARNING No mapping for tag 1364223230181
2019-02-24 18:11:54,392 WARNING No mapping for tag 1364215230189
  • note the NFC tag ids
  • edit MFRC522-trigger's config file: vi ~/devel/MFRC522-trigger/config.json
  • change config.json accordingly, e.g. map NFC tag ids to Volumio playlists
  • restart MFRC522-trigger sudo systemctl restart MFRC522-trigger
  • hold the same NFC tags again against the reader, actions should be triggered now

gpio-trigger

About

How to build a music box (not only) for children based on Raspberry Pi and NFC.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published