It’s just a small project. A friend of mine asked me for an mp3 player which randomly plays a song each time you close a contact. The Raspberry Pi was predestined for this. The sound output of the Pi is not optimal, so I used a 7$ USB sound card.
VideoNo action, but informative.
Part List
- 1 Raspberry Pi
- 1 USB sound card
- 1 USB flash drive
- 1 Micro SD card
- 1 Power supply
- 1 Enclosure
The Pi is running on Arch Linux (booting up in under 25 secs). You also need python 3.5, the RPI.GPIO package and mpg123. In the home, directory you need this 3 files. You can find them here GitHub.
- play.py (main program)
- mp3.sh (play the mp3)
- system.mp3 (sound file)
Create a folder “mp3” on the flash drive and copy all the needed mp3s in it.
Start on bootCreate a file under /usr/lib/systemd/system and name it “playmp3.service”. Copy this inside the file you just created:
[Unit] Description=PlayMP3 After=multi-user.target
[Service] Type=idle ExecStart=/usr/bin/python /home/play.py
[Install] WantedBy=multi-user.target
To run the system on boot, do the following:
systemctl enable playmp3.service
Now create this directory: mkdir /mnt/usb
. Open the file /etc/fstab and add the following line:
/dev/sda1 /mnt/usb
Ready to useShorting the GPIO 17 with the ground, makes the thing do what the thing should do.
Comments