I love to listen to the radio when I am making something or cooking, but where I live FM reception is terrible. And with the Internet, listening to radio stations of the world is a pleasure, but I don't like to use my smartphone to hear music, so with a lot of Googling, I found several solutions.
I based this project on another tutorial: Arduino / Raspberry Pi Internet Radio by akellyirl. The code is written in Python on the Raspberry Pi and basically uses the Linux music player daemon (mpd) and the player (mpd). There is a library nanpy that lets Python communicate with the Arduino which controls the push buttons and the LCD.
I used an LCD/keyboard shield for the Arduino that has push buttons: SainSmart LCD Keypad Shield for Arduino, and later added a 4 push button strip that I scrapped from a broken alarm clock. First I used a Raspberry Pi 2 with a USB WiFi adapter, but now I am using a RP3 which has built in WIFI and no need for antenna.
The hardest part was finding the right URLs of the stations I wanted. Finally I found this program: URL HELPER that sniffs the site you are on and show the URLs of the media playing. For the sound, I used a pair of active computer speakers also recovered from scrap.
Installation instruction for RP3 (from Arduino / Raspberry Pi Internet Radio by akellyirl in Arduino):
1. Update Raspbian to the latest packages:
$ sudo apt-get update
2. Install the mpd/mpc packages:
$ sudo apt-get install mpc mpd
We want to be able to talk to Arduino from Python running on the Pi. To do that, we need to install the nanpy library for Python and the nanpy firmware for Arduino:
1. Install Arduino packages to build the nanpy firmware for Arduino:
$ apt-get install arduino
2. Get the nanpy library for Python and extract from /home/pi:
$ wget http://pypi.python.org/packages/source/n/nanpy/nanpy-v0.7.tar.gz $ tar xvf nanpy-v0.7.tar.gz
3. Get setuptools for Python (a dependancy for nanpy) and extract:
$ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e $ tar xvf setuptools-0.6c11.tar.gz
4. Get pyserial for Python (a dependancy for nanpy) and extract:
$ wget http://pypi.python.org/packages/source/p/pyserial/pyserial-2.6.tar.gz $ tar xvf pyserial-2.6.tar.gz
5. Go to the setuptools directory and install Python setuptools:
$ cd setuptools-0.6c11 $ sudo python setup.py install
6. Go to the nanpy directory and install the Python nanpy library:
$ cd ../nanpy $ sudo python setup.py install
7. Go to the serial directory and install the Python serial library:
$ cd ../pyserial-2.6 $ sudo python setup.py install
Now we've got the files we need, let's put the nanpy firmware on the Arduino.
Firmwarenanpy allows a Python program running on the Raspberry Pi to operate the Arduino using conventional Arduino-Sketch syntax, e.g. the Python program to read an analogue input from Arduino might read:
int val = Arduino.analogRead(14)
Nanpy has two components:
- A library for Python that allows Arduino commands to be written in a familiar syntax and communicate with Arduino;
- Firmware that runs on Arduino, communicating with Python on the Pi.
We installed the Python part of nanpy and downloaded the Arduino part of nanpy on the Pi in the last step. Now we need to upload the nanpy firmware to Arduino.
Plug Arduino into the USB of the Raspberry Pi.
1. Go to the nanpy firmware directory and upload to Arduino:
$ cd ../nanpy/firmware $ export BOARD=uno $ make $ make upload
If you get a report that the device is not found on /dev/ttyACM0, plug the Arduino into the other USB port.
I created a playlist script and a Python script (published in the code tab) and made the Python script auto-run on the Raspberry boot. I also added another push button to show some menu options like showing the IP or choosing the audio output.
last update: i remade it: , added rotary encoders for dialing and volume it and 3d printed the case:
Comments