This portable cassette player is now an ambient IoT weather display with early 80s style, displaying a "current conditions" animation, scrolling temperature and rain probability graph through the tape window. When the weather condition changes the servo-controlled headphones on top jiggle back and forth as a subtle alert.
Opening the functional tape door we can see that the dusty original components have been replaced with a Raspberry Pi Zero W, a Pimoroni Unicorn Hat HD (LED Matrix) and a small servo. The weather data is sourced using a Python script that queries the ultra-accurate Dark Sky Weather API, tailored to my specific location.
It's a simple but lovely-looking and functional IoT build that sits on the opposite desk speaker to my YouTube counter, quietly keeping me up to date with the weather.
Tape TeardownThat discovery alone was enough to bump my cuckoo clock project further down the "to do" list and I started work straightaway, by dismantling the player. real draw though was that big tape window - after owning it about 15 seconds I had a ruler out, and was amazed to find that it's, to the mm, the same size as a standard Raspberry Pi HAT (Hardware Attached on Top).
That discovery alone was enough to bump my cuckoo clock project further down the "to do" list and I started work straightaway, by dismantling the player
The teardown went pretty well and I ended up with three distinct pieces to work with - I did manage to break a couple of the plastic parts, but nothing that couldn't be glued back together.
Dark Sky PiI've been using Dark Sky on my phone for a while and have been really impressed with the accuracy of the forecasts, so I was delighted to see they offer a comprehensive API that I could use in this project.It's nice and straightforward to set up too!
Firstly head over to https://darksky.net/dev and sign up for a free account - a "trial" account lets you make 1000 API requests a day, which is enough for a refresh every 1.5 minutes - frequently enough for even my British level of weather obsession.
Once signed up you'll get a "Secret Key" - this is what you need to access the data and it's used in the Python script, so keep it handy (and, you know, secret).
I began by adapting a script I used in the YouTube Subscriber Counter build, which uses the Requests module in Python to retrieve API data. The script I used is on GitHub, you'll just need to add in your Dark Sky API key and, of course, substitute your own Latitude & Longitude values.
It was pretty straightforward to pull down data on the current weather conditions, and I decided to make use of the "Icon", "Precipitation Probability" and "Temperature" elements.
The CodeIf you want to re-use or springboard off the code I used, it's in the WeatherMan repository on GitHub - clone or download the "weather" folder into the "pi" folder on your Raspberry Pi.
The main script functions are as follows:
weatherman.pyThis is the main script that extracts the weather data from Dark Sky. You'll need to set up a Dark Sky account at https://darksky.net/dev and put your Secret Key in the script where indicated. You'll also need to put in the latitude & longitude of the weather location you're interested in - this can be found on Google Maps, just right-click and select "What's Here?" and you'll get a pop-up showing the lat/long of the location.
After retrieving the API data weatherman.py passes parameters to several smaller scripts to kick off the animations and headphone jiggles.
The script is set to run on startup by editing the startup file...
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
...and adding:
@python3 /home/pi/weather/weatherman.py &
at the end of the file.
icon.pyThis script takes a "current conditions" parameter from the weatherman.py script and uses it to display a 16x16 weather animation - these are all stored in the "icons" folder and are part of the standard Unicorn HAT HD documentation. You can edit the PNG animation files easily in GIMP or a similar image editor to give them more character. You could edit the "rain" animation so that given a specific set of conditions it would show as "raining men" - a contemporary classic from 1983.
phones.pyIf the weather conditions have changed from the last API request (or it's a fresh boot and it isn't snowing) then this script is called from weatherman.py and instructs the servo to "jiggle" back & forth to alert you that conditions have changed.
precip.pyThis script accepts a "precipitation probability" parameter from weatherman.py and displays lines in blue on the Unicorn HAT relating to the % probabilty. If 100% all 16 rows will glow blue, if 50% only 8 rows etc.
temp.pyAnother standard Pimoroni script, this one takes a "temp" parameter from weatherman.py and displays it with scrolling text. It's set to use the Herkules truetype font (in the "fonts" folder) but could use a standard font if you prefer.You could even enhance it so that the displayed text changes colour depending on the temperature value!
Unicorn HAT & ServoBeing able to get hold of the weather data was great, but now I needed to display it on the Unicorn HAT. I looked at various sets of weather icons on the internet and was half-way through adapting these when I realised that there was a weather example included with the Pimoroni documentation - and this included weather animations!
Being able to get hold of the weather data was great, but now I needed to display it on the Unicorn HAT. I looked at various sets of weather icons on the internet and was half-way through adapting these when I realised that there was a weather example included with the Pimoroni documentation - and this included weather animations!
This saved a huge amount of work, and I was up & running in no time, with an animated icon for the current conditions, some scrolling text for the temperature and a graph for the % precipitation (which involved some light maths). I kept the scripts separate and used the Subprocess module of Python to pass parameters to and fro.
Powering the servo from the Pi wasn't ideal, but it would only ever be used for a momentary jiggle so precision wasn't a big deal here. It connected up as shown in the diagram, with Brown cable to GND, Red to 5v and Orange (the control cable) to GPIO17.Adding in the servo was the ideal vehicle for these alerts, as it would make a little bit of noise and be eye-catching without being too annoying. With the HAT already taking up many of the Pi's pins I soldered the servo cables to the underside of the board, using Pin 17 to control the servo's movement using Pulse Width Modulation.
Powering the servo from the Pi wasn't ideal, but it would only ever be used for a momentary jiggle so precision wasn't a big deal here. It connected up as shown in the diagram, with Brown cable to GND, Red to 5v and Orange (the control cable) to GPIO17.
Lastly I edited some of the weather animation files in GIMP to add in my own personal touches, like bats on the moon and a smiley face on the sun. I also added in a custom "Old Tech New Spec" cassette wheel animation to be played on startup, just for fun.
Headphone JiggleThe idea of the WeatherMan was that it would passively sit on my desk speaker, occasionally displaying the weather, but I wanted it to do just a little bit more! The earphones that came with it were toast but classic 80s, so I decided to do something with them. After stripping off all the cablee and hot-glueing the broken one I was left with three parts, the 3.5mm plug, the diamond-shaped button and the phones themselves on their flexible metal band.
The idea struck me that if I could find some way of mounting the phones on top of the unit then I could make them rotate back & forth with a servo, and use this as an additional notification.
Firstly I drilled out the 3.5mm plug and dismantled the diamond switch, then slipped these onto a piece of threaded rod. Next I glued a nut to a plastic connector, so that the rod would be able to sit securely (and straightly) atop the servo. At the other end of the rod I added in another nut. Finally I used grey Sugru to bond the top of the rod to the earphone band and also to cover up the nut at the bottom of the assembly. If you've not heard of Sugru it's a mouldable glue that comes in small coloured sachets - it moulds like Play-Doh but sticks like superglue and sets hard like plastic!
With the recent cold weather the Sugru took a few days to harden fully, but the headphones and their stand were soon ready for final assembly.
AssemblyThe Pi, HAT and Servo were all working fine on the bench so the next job was to get them into the case. Before starting on the big components I used some left-over grey Sugru to fix in the volume dial, headphone socket and "metal tape" switch, sorting out the cosmetics. I also glued the original Play, Stop, FF & Rew buttons to a piece of plastic conduit so they'd stay in just the right place. It was a shame not to re-use any of the buttons this time but there wasn't really anything for them to control!
I used the last of the grey Sugru to hold the servo in position, with its shaft poking through the enlarged headphone socket. Moving across to the other half of the case I then used some black Sugru to secure the HAT and Pi assembly to the tape door, so that they would open with it. I really enjoyed the final little touch - fixing in a GeoMag magnet so that the door would be held firmly closed.
Putting the two halves together was a nervous business as I feared the Pi & Servo would clash against each other, but in the end there was around a millimetre to spare, plenty in my book. As the funky opening door would give full access to the interior for future servicing I just hot-glued the two halves together, and after wiping down my greasy fingerprints fitted the headphone assembly on top - done!
Quiet ObsessionI love the way it quietly keeps me up to date with the current conditions and subtly alerts me to changes, and the Dark Sky API has proved very user friendly and accurate. I hope to upgrade it in the near future to show data from a Pi weather station as well as the online data, but for now it's doing just what I'd planned and it's in use every day.This was quite a personal project, you'd never see one of these as a product in the shops, but I'm really pleased with the final result.
My favourite part is the satisfyingly solid tape door, it's great to know I can easily swap SD cards or connect up a monitor if I decide to tweak the code or completely change its function. The jiggling headphones are very cute too though, and never fail to get my attention.
I love the way it quietly keeps me up to date with the current conditions and subtly alerts me to changes, and the Dark Sky API has proved very user friendly and accurate.
I hope to upgrade it in the near future to show data from a Pi weather station as well as the online data, but for now it's doing just what I'd planned and it's in use every day.
Thanks for reading! My other Old Tech. New Spec projects are all at https://www.hackster.io/martin-mander/projects
More details and a contact form are on our website at http://bit.ly/OldTechNewSpec. and we're on Twitter @OldTechNewSpec.
Comments