Raspdio
An connected radio checking the internet to see when and for how long it should play.
++++++
Operation Principle: The Raspberry Pi queries a google spreadsheet to retrieve the "wake up" time, the "sleep time" & the duration of the play. A button can also start/stop the radio. Volume control is also available.
More Info: http://univership.org/projects/NXf9Bzunz9owYdx5d/...
Github: https://github.com/gcool-info/raspdio
++++++
Created @Tink Tank with @Arthur Schmitt as part of my Univership
Get Your Material
Connect the Speaker
The speaker is connected to 5V and Ground for power.
It received the audio signal from the 3.5mm jack.
(If you're unsure about the pin location, check this: http://elinux.org/RPi_Low-level_peripherals)
Connect the Button
The push button is connected to pins GPIO4, GND & GPIO17.
Current passes through GPIO17 & GND and the RPi detects whether the button has been pressed.
This button has a led inside it. GPIO4 controls whether the LED is turned on or off.
Volume Control
To control the volume we will use a potentiometer. The output signal is analogue but the RPi doesn't have a built-in ADC. So we have to include one....
I followed this excellent tutorial by adafruit to do this: Connect RPi to MCP3008
Note that I connected the potentiometer to CH7 of the MCP3008!
Create the Google Spreadsheet
You can copy the google spreadsheet from my drive: Control Room
After you copy it to your drive, make sure to note down the spreadsheet's key. We will use it later.
In this example shown below, it is the part of the URL which is bold / underlined
docs.google.com/spreadsheets/d/1IAP4HOacD4Az6q_PFfZgIX7lZVoHrRKM9KBX-IMO25s/edit?usp=sharing
Configure the Wifi on the Raspberry Pi
1. Boot the Raspberry Pi and run: sudo nano etc/network/interfaces
Edit the file so that it looks like:
etc/network/interfaces
auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
2. Run the command: sudo nano etc/wpa_suppilicant/wpa_suppilicant.conf
- If you are on a WPA-EAP network, edit the file so that it looks like:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1network {ssid=""
key_mgmt=WPA-EAP password="" identity=""}
- If you are on a WPA-PSK network, edit the file so that it looks like:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1network {ssid=""
key_mgmt=WPA-PSK psk=""}
Add the Files to the Raspberry Pi
You can clone all files to the raspberry pi from my github by using:
(if you haven't installed git on your Pi, you can run: sudo apt-get install git)
Otherwise, just copy the files inside "pi.zip" in some directory on your Pi.
- Make sure to change the following lines in the file "main.py":
gDocURL = "YOUR_GDOC_KEY" gDocLogin = "YOUR_GMAIL" gDocPSW = "YOUR_GMAIL_PASSWORD"
You can also modify the radio stream (if you don't want to the most boring station ever!!)
streamURL = "http://2QMTL0.akacast.akamaistream.net/7/953/177387/v1/rc.akacast.akamaistream.net/2QMTL0"
++++++++++
In this file, we take a look at the gSpreadsheet every 5min & we get the "wake up", "sleep" time & duration.
We check these against the current time & if there is a match, we play the music for "duration". We also adjust the volume on whether it it the "wake-up" or the "sleep" time.
We then configure an interrupt to check whether the button is pressed (to stop or start the music accordingly).
Finally, if the radio is playing, we are constantly querying the ADC to get the volume.
Downloads
Add Dependancies
- We will have to install the gspread python library, which will do the heavy lifting of connecting to google docs and updating the spreadsheet!
sudo apt-get install python-pip
sudo pip install gspread
- We also need to install a streaming music library by using the commands:
sudo apt-get install mpc mpd
This installs the Music Player Daemon (mpd) and it's client mpc.You use the mpc client to configure mpd to add radio streams to the playlist, start and stop the player etc.
Run Program on Pi Boot
To run the program immediately when the Pi boots up, we use a crontab. A crontab is a background (daemon) process that lets you execute scripts at specific times. It's essential to Python and Raspberry Pi. To do this, open the file launcher.sh
nano connected-doorbell/pi/launcher.sh
Make sure that the line
cd home/pi/Desktop/raspdio
is pointing to the directory containing your main.py program.
Then, follow this excellent tutorial: https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/ (starting from step 2)
3D Print and Assemble!
Open the stl files & print them. If you're using different components, make sure to change their dimensions!
Then assemble, plug-in and play!