Pi-Touch

A long time ago I realised that I'm driven by curiosity to learn new stuff regardless of whether or not I have anything to gain from learning it. For example, I use (and support) Windows at work, have a perfectly good Mac at home but do all my tinkering with a Linux laptop just to learn about all the main operating systems available today. I even switched from a perfectly good Ubuntu installation to Arch Linux simply because I wanted to explore another distribution. I also find myself re-inventing the wheel and building things, not because I have a need for them, but because I can.

This is exactly what the Pi-Touch project I started in Spring 2017 is: a touchscreen clock radio that could easily have been created using a tablet and a few apps but which I chose to build myself using a Raspberry Pi 3 and an official 7" touchscreen.



There are many tutorials on the Internet for installing and configuring Music Player Daemon and tons of examples on how to control the command line mpc client using Python so I was able to get the Internet Radio functionality going pretty quickly.

The first real hurdle was making the leap from writing simple command line Python scripts to a touch-enabled application. My research lead me to Kivy, an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. The project even provides an excellent guide to getting Kivy running on a Pi.

Getting Kivy installed may have been easy but I really struggled to get my head around creating an interface where one part refreshed automatically every second while other parts sat there waiting until someone touched them. There are many free resources available but the one I found most useful was a book I bought - Creating Apps in Kivy: Mobile with Python by Dusty Phillips.

After more weekends and evenings than I care to admit, I had a working clock and radio player. As there was a lot of unused space on the screen I started adding more "widgets" to the screen. Living in Calgary, knowing the weather forecast is very important so I dove into figuring out how to pull weather data from Weather Underground and display nice looking graphics on the touchscreen. As usual, my lack of coding skills made this an interesting challenge. Once I'd created the weather widgets I still had some room left on the screen so I decided to use my new skills to add the sensor data from my smart home project to the display. Now I knew the temperature inside AND outside!

Around the time I got all of this working, Google released the Google Assistant SDK. My Pi-Touch seemed like the perfect place to deploy and play with this exciting new tool and, since I'd disassembled Pinkybot, I had a spare microphone available. Thanks to the excellent step-by-step instructions provided by Google, getting the Assistant installed and running was a piece of cake.

One of the first things I did was setup an applet in IFTTT that allowed me to use Google Assistant to control a WeMo switch I had lying around. This worked so well that I got to thinking - could I use the Google Assistant for voice control of my Internet radio? IFTTT's maker channel allows the triggering of web requests from a voice command to Google Assistant so, in theory, all I had to do was setup a Flask web application on Pi-Touch to run the same code that I had already written for my touch screen application!

My lack of coding experience made this effort harder than it ought to have been but eventually I had two Python applications running at the same time controlling mpd without interfering with each other. The code for PiConsole (the Kivy touchscreen app) and PiWebAPI (the Flask application that responds to web requests from IFTTT) is available from my GitHub repository.

One of the great things about this project is that my wife and kids find the Pi-Touch useful and use it regularly. Unlike Pinkybot, Pi-Touch is a permanent fixture and will (hopefully) not be disassembled to provide parts for other projects. In fact, I keep adding new functionality to it whenever I think of something else that I can use it for. For example, I have installed shairport-sync on it so that I can use the speaker connected to Pi-Touch as an AirPlay speaker and I'm always experimenting with new voice commands triggered via Google Assistant and IFTTT.


Comments

Popular posts from this blog

Welcome

Smart Home