This project is part of Microsoft’s Hack the Home initiative, which provides makers with free, open-source components for effortless interfacing with the devices and services that makers use most to hack their homes.
This project shows how you can use the power and flexibility of the Raspberry Pi and Windows IoT core to recycle an existing device (in this case a Clock Radio) and extend its existing functionality using the power of an Internet Connected operating system.
Using the the universal Windows platform and IoT Core extensions you can quickly and easily interface with the existing controls on the device and this walk-through should provide you with the information required to reuse a clock radio device of your own or even extend the example to be used on different devices with more functionality.
The aim of this project was to take a used clock radio, strip the original components out of the casing and mount a Raspberry Pi inside to make the device internet connected. The use of an existing device is not a requirement though, a simple internet radio device can be created by just following the wiring for the LCD and buttons (explained in the Hardware section) and then deploying the supplied application to your Pi (explained in the Software section) and a simple case could even be 3D printed.
I wanted to keep the device close in appearance to the original but change and expand the functionality to take advantage of the fact that it is now running a full, internet connected operating system.
HardwareThe first step in this project was to create a circuit that could replicate the original functionality of the device, interface with the Raspberry Pi's built in I/O circuits and fit into a case. The circuit I used to prototype during application development (and that was later soldered onto a prototype board for installation) is shown in the fritzing diagram below. This setup requires 11 individual GPIO pins (5 for the buttons and 6 for the LCD) but the actual pins chosen aren't significant and are configurable in the application source (as described later in the Application section).
The wiring setup for the radio is shown in the fritzing diagram below and the steps you can follow to setup this circuit are as follows (pin diagrams for the LCD and Raspberry pi can also be found below):
LCD Screen:
- Connect the GND, LED - and R/W pins of the LCD to a ground pin on the Raspberry Pi (I used pin 39).
- Connect the Vcc and LED + (sometimes also labeled as BL1) pins on the LCD to a 5v pin on the Raspberry Pi (I used pin 2).
- Connect the RS, EN, DB4, DB5, DB6 and DB7 pins on the LCD to GPIO pins on the Raspberry Pi (I used 18, 23, 24, 5, 6 and 13 respectively but these pins can be configured in the software later).
- Connect pin 1 of the 10k potentiometer to a 5v pin on the Raspberry Pi (I used pin 2).
- Connect pin 3 of the 10k potentiometer to a ground pin on the Raspberry Pi (I used pin 39).
- Connect pin 2 of the 10k potentiometer to the VEE (sometimes also labeled as V0) pin on the LCD (this controls contrast).
Buttons (repeat these steps for the amount of buttons you want in your project):
- Connect one end of the 330Ω resistor to a 5v pin on the Raspberry Pi (I used pin 2).
- Connect the other end of the 330Ω resistor to a PTM (push to make) button.
- Connect the other end of the PTM button to a ground pin on the Raspberry Pi (I used pin 39).
- Add a wire inbetween the resistor and the PTM button and connect it to a GPIO pin on the Raspberry Pi (I used 27, 22, 16, 12 and 4 for my buttons).
The sounds from the radio streams are played through the Pi's 3.5mm stereo out jack, to allow integration with the existing speaker in the case I chose I used a mono sound breakout board (as described later) but any speaker or headphones that have a 3.5mm plug can be connected to the Pi.
All of the code described below is available in the repository listed in the code section of this Hackster post so that you can easily deploy and extend it to fit your specific application.
This project makes use of 2 separate UWP (Universal Windows Platform) applications, one of these runs on the Raspberry Pi that is a part of the Clock Radio device and the other runs on any other device that can run UWP applications (Windows 10 Desktop, Window Phone 10, another Raspberry Pi running Windows IoT Core). The purpose of the second application is to function as a remote control for the device in the case where you cannot reach the physical buttons. The applications communicate using the AllJoyn protocol (https://allseenalliance.org/) using the Windows Runtime AllJoyn APIs and therefore the Internet Radios methods and properties are exposed to any device that is able to enumerate AllJoyn devices (like AllJoyn Explorer).
Device ApplicationThe device application is found in the main solution in the repository (InternetRadioDevice\InternetRadioDevice.csproj). The following steps will outline getting the base application deployed onto the Raspberry Pi device and then once that's done you are free to fork, modify and expand on the functionality.
- First setup your Pi and Developer environment, to do this follow the instructions listed here: http://ms-iot.github.io/content/en-US/win10/SetupPCRPI.htm
- Get the code from the Github repository listed below
- Open "InternetRadioDevice.sln" in visual studio.
- Right click on InternetRadio in the Solution Explorer and select "Set as StartUp Project"
- Find the C# file called "Config.cs" and make sure the configurations listed there matches the hardware you have setup (i.e. the Pins listed in the ButtonPins list match the physical pins you have these buttons linked to).
- Open the file InternetRadio\lib\TextDisplay\TextDisplayManager\screens.config and make sure the pins listed match the pins your display is connected to (default are the pins in the hardware setup section above).
- Use Visual Studio to deploy the application to your Pi by selecting the ARM processor type from the drop-down, right clicking on the project name in solution explorer and choosing "deploy" (you will need to enter the IP address and set the "Use Authentication" to false).
- Connect to the Raspberry Pi using SSH (instructions shown here: https://ms-iot.github.io/content/en-US/win10/samples/SSH.htm)
- Run the command "IoTStartup list headless" and copy the full text of the application that starts with "InternetRadio" (this is called the application full name.
- Run the command "
IoTStartup add <The text you just copied>
". A confirmation message should be shown on the screen.
- Reboot the Pi and the LCD should show the radio welcome text.
- By default the radio will have no preset stations (and therefore will not play anything), the network API must be used to add channels, so the next step is to launch the remote app. To do this go back to the Visual Studio solution and find the project called "InternetRadioController" and set that as the startup project.
- Set the build architecture to x86 or x64 and choose to deploy the application on your local machine then press F5 to launch the project using Visual Studio.
- Once the application launched find your radio listed in the box (the ID is shown on the radio screen when it is booting). Select your radio and click "Connect".
- The next screen shows a list of commands that are you can send to the remote device and down the bottom are 2 text boxes for adding preset channels, fill the address box with a valid MP3 stream (such a this one for the University of Washington's NPR station KUOW: http://kuow.streamguys1.com/kuow1-hi.mp3) and enter the name you would like to see on the screen in the name box.
- Now when you press Next/Previous on the remote or on the device it will cycle through these presets.
N.B. The application requires an active WiFi network (it offers no functionality for network configuration), so make sure the WiFi is configured properly before closing up the case (or have an Ethernet cable run out of the back of the case).
CaseA trip to the local thrift store turned up 4 possible candidate radios for the build, all priced at ~$5 (pictured above). 3 of them with an LCD display and a 4th one where the front is dominated by the speaker grill that could be used as a completely headless/display-less speaker unit. The eventual goal is to convert them all but for the purpose of this post I have only included the first one that has been completed.
For the first conversion I chose the radio that looked like it had the largest interior space and would require the least modification to integrate the new components (the bottom right case in the main picture). The first step was to remove the old components from the case and since these radios were made in a time where everything was designed to be easily serviceable this turned out to be a very simple task (as simple as removing a few screws in fact). The result of this is the empty case shown in the first picture below and the second picture shows some of the internal components that I kept.
We happened to have a few 16x2 LCD screen lying around and they fit the space left by the original screen fairly well (it could use a card surround to hide the back-light overflow but that's a job for another time).
I also ended up integrating some of the wiring onto a soldered prototyping board along with the components for the buttons and this is outlined in the buttons section below.
The buttons on top of the clock radio were part of a separate PCB that also handled the original LCD display and luckily enough the contacts for the buttons and the traces were isolated from the rest circuitry. This allowed me to use a pillar drill (this could also probably be achieved with an xacto knife or other sharp implement) to cut the original traces in the PCB and solder new wires onto the button contacts (see picture 2 below).
Since the Pi only has 2 5v pins (and I needed 1 free for the amp detailed in the next section) I put together a quick prototype board to hold a small 5v rail that all the buttons and the LCD could feed off of. I also used this board to hold the potentiometer that controls the LCD screen contrast and the resistors used by the buttons.
The original amplifier was was a part of the PCB and the speaker was soldered straight onto that, since I removed the PCB to fit the new components another solution was needed. There is only space for a single speaker in the case so I went with a mono amplifier and reusing the original speaker. Sparkfun provide a class D mono amplifier (listed in the components section) that was completely fit for purpose as it runs off 5v (meaning I could have it draw power from the Pis 5v Pin and therefore only need 1 power supply. The wiring for this is shown in the second image below.
To finish it off I replaced the Ethernet cable with a Raspberry Pi Wifi adapter and tidied/taped the internal wiring so that the top fit back onto the case.
This was a quick, fun project that made use of the Pi's onboard networking, audio and GPIO capabilities to create a device that I use daily in my office (the snooze/sleep button is especially useful when someone walks in and doesn't want to have to talk over my radio!).
Comments