Spotlight: Mike Riley (Author) Interview and AMA!

1pBb5XjX_400x400

Author Spotlight:
Mike Riley (@mriley)

This month, we turn the spotlight on Mike Riley, author of Portable Python Projects. Mike’s book helps you discover easy ways to control your home with Raspberry Pi hardware and the fun of Python scripting. Create custom Internet-of-Things projects with Mike’s guidance.

This is also an AMA. Everyone commenting or asking a question will automatically be entered into our drawing to win one of his books!

3 Likes

Please introduce yourself.

Hi. I’m Mike Riley, author of Portable Python Projects and several other Pragmatic Bookshelf books and video series.

What is Portable Python Projects? Hearing the name, you might not think kits or Raspberry Pi.

That’s right. As a matter of fact, it is mostly about home automation using Python, and the Raspberry Pi happens to be the platform that is most convenient and the least expensive to deploy and operate on. All the projects in the book could be run on PCs, Macs, and Linux computers, but because the finished applications are usually expected to be running twenty-four hours a day, seven days a week, running them on such an overpowered computer (such as just waiting for changes in the environment), that would be much less efficient. The Raspberry Pi is a great, low-power computer, fully Linux compatible, and it runs all the applications that you see in the book. It does a great job as a consequence.

What made you choose to go with Python as your scripting language?

Python is currently, according to most of the indexes out there, the number one programming language in the world. It’s a relatively easy language to learn. In fact, it’s being taught in many middle schools, and even in certain situations, kindergartens. It’s easy enough for youngsters to learn yet powerful enough to use in enterprise environments.

For me, choosing Python for the book’s projects was a no-brainer. I’ve been using Python since it was released back in the ’90s. It’s always been a wonderful language because of its adherence to readability and its vast number of third-party libraries available to do work that a lot of smart people have put together already solving some tough problems. This makes simply importing those libraries to do the things that you want to do a breeze, so you’re not reinventing the wheel rolling your own solution with every project.

If somebody wanted to roll their own projects for this book, they would buy Raspberry Pi, right? What’s the cheapest Raspberry Pi they could get away with?

Oh, these days, just to be on the more modern side, I would say it’s the Pi Zero 2 W, and that was recently refreshed to be just as powerful as the original Pi 3 Model. It has 512 GB RAM and a fast WiFi and Bluetooth stack on it, all packed within the size of a gum stick. If you don’t need a lot of expansions, such as on multiple USB ports or an ethernet port on board, it makes for a great little computer. In fact, I use mine for powering on and off my TV, as well as a small GitHub-style server so that I can do my local to code check-ins on it.

So you need a Pi. You need, I assume, a microSD card?

MicroSD card, yep.

What else?

Before you plug in the microSD, you need to install the latest operating systems on it. The Raspberry Pi installer, which is available from the Raspberry Pi Foundation, allows you to install not just its own distribution called Raspberry OS, but a number of other Linux-based distributions as well.

One that I particularly like using—but then again, I’m more of an advanced user—is Manjaro, which is a variant of Arch Linux. Arch is a very powerful yet minimalistic type of Linux distribution. But if you’re just getting started with the Pi and you’re not too comfortable or familiar with all the various Linux distros that are out there, I would say the Raspberry Pi foundation version, called Raspberry OS, is a super distribution to get started with.

As a matter of fact, if you are using the newer versions of the Pi, whether that’s the Raspberry Pi Zero that I mentioned, or anything Pi 3 or above, you can now install the officially supported 64-bit version, which is great because a lot of the newer applications these days are being compiled just for 64-bit support. A lot of the legacy 32-bit apps won’t run on the newer systems, but if you have a Pi 3 or later, or the newer Pi Zero 2, it will run those 64-bit apps with the Raspberry OS 64-bit version of the operating system just fine.

What are some ways that a lot of people are using the Raspberry Pi? What are some of the more popular?

Certainly from just a usability standpoint, configure it, deploy it, and let it run day and night. One popular Pi app called a Pi-hole, is a service that protects your privacy and security by blocking a lot of trackers or unnecessary advertising that might be carrying malicious payloads that you really don’t want showing up in your browser anyway. The Pi-hole is really just a proxy server that allows it to filter all that nasty stuff, particularly those things that could carry viral payloads and such, or malicious JavaScripts, et cetera. It also makes the browser experience a little bit more manageable by filtering out the constant onslaught of popup ads, banners, and such. That’s one very popular use for the Pi or for the Raspberry Pi. Others use it as a VPN server. And others like me use it for home automation projects. That’s what I wrote about in the book.

Could you talk a little about home automation and the Internet of Things, what they are and why people should care?

Sure. I’ve been involved with home automation for a long time, way back in the days of…oh gosh, back in the 1970s, even before they started developing various home automation solutions such as the X10 controller. I actually wrote about that in my first book, published by Pragmatic, called Programming Your Home back in the 2012 timeframe. Back then, there wasn’t a lot of standardization on home automation, libraries, and such because everything was still being rapidly developed. Even large tech companies like Apple and Google had their own spins on what they thought home automation interfaces should look like. Of course Apple now has their HomeKit and there’s Google Home, et cetera.

Now that the home automation environment has matured a little bit more, you certainly use those preconfigured solutions, but then you’re beholden to those vendors, and they don’t give you a lot of flexibility or transparency. You can’t modify the hardware and make it work with other operating systems. They are basically black boxes. They are easy to set up, but then you don’t know what is being communicated back to those cloud-based motherships that are controlling them. Are they being managed properly? What’s happening to all that data? Is the software controlling them being updated to protect against any vulnerabilities that might infect that product? A lot of the inexpensive hardware that you find on Amazon, for instance, is developed and manufactured overseas where they may or may not have the best security policies for home automation needs.

These black box solutions got me very concerned, because there were things that they were doing that I wasn’t comfortable about. They were sending lots and lots of data to servers outside the country. I didn’t have a say in what was sensitive or not, or even if it was something I wanted to share with an unknown data collector in the first place. With these manufactured solutions, you don’t have much recourse, plus, as we’ve seen time and again, every week it seems that there’s yet another vulnerability that’s been discovered on a device no longer supported by the manufacturer that people are still using today.

Why are people excited about the Internet of Things? What they’re using it for and so forth?

The whole idea of the Internet of Things is that it’s machine-to-machine communication. There’s little if any manual intervention. That means that these machines can work together and communicate state and events and triggers amongst themselves. If they can do that, then they can also start to make basic decisions amongst themselves. One of the projects in my book is essentially a thermostat where if the temperature in a room exceeds a certain threshold, a fan will turn on. When that temperature is below the threshold, then the fan will turn off.

That’s a fairly simplistic mechanism, but as you can imagine, as you start to connect these Internet of Things devices and workflows together, you can chain them so that they have fairly complex behaviors. It can get very sophisticated very quickly. As that level of sophistication grows, so too do opportunities for tremendous automation and somewhat in a way, not quite sentient behavior, but certainly a level of automation that we would never have been able to achieve without such a complex web of machine-to-machine interactivity.

You mentioned using a thermostat. What are examples of other tech that can be automated?

There are more simple things, such as lighting. Philips has a really easy solution that also provides an open API you can use to script and communicate with. It’s their Hue line, and that is probably the simplest mechanism by which you can either through voice by either triggering your Amazon Alexa, Google Home, or Apple Siri, turn on or off lights, et cetera. They’ve now extended their hardware line beyond lighting to include electrical switches and temperature monitors and such. Other home automation product companies are expanding their scope because they realize that there is a high degree of interest and marketability in these open products.

For example, you can’t get your Google Android to control an Apple HomeKit device. For those people who are fully ensconced in the Apple universe, that’s fine. But the moment they step out of it, or they have other family members who are not in the Apple ecosystem yet want to interact with these home-based devices, they’re not going to be able to do so. That’s one thing that I also strive to maintain within the book—making sure that the devices I used in the book were agnostic to the hardware interacting with them. Again, that you could run it on something other than a Pi, but the Pi is ideal, and that you could have iPhones, Androids, Windows, Linux, [Pback 00:14:57], whatever can also interact and talk with these devices and therefore participate in the Internet of Things, regardless of platform or protocol.

How do they communicate and what ensures safety?

Well, again, that’s where being able to do the project yourself, you get an awareness of what is happening in the environment and what you can control in the environment. If you are doing, let’s say, a REST-type web service, then it’s in your best interests to make sure that those endpoints are secure. Now, of course, if it’s on your local area network, hopefully the router that you’re using has a built-in firewall that doesn’t allow external traffic to come in. But that being said, even if it were, you would still want to practice the best practices from a security standpoint. If you’re developing your own applications, you definitely want to follow best practices whenever it comes to whichever language you’re using for development of those applications. I try to emphasize that in the book as well.

It sounds like these are primarily using WiFi. Are there any that use, for example, Bluetooth or other technologies?

I stuck predominantly with WiFi. In my previous automation book, I explored things like Zigbee, which is low-powered, but the problem with those is that you start to compound the complexity of the project because of the technical stacks required for those protocols to work. I also found that with the Zigbee devices, they actually cost more these days than WiFi devices due to the economies of scale. Zigbee can be lower power, but they are fairly niche. You’re going to pay for that privilege.

I’ve since shied away from Zigbee, and really just stuck with what’s native on the Pi boards. With something like a Pi Zero, which costs ten dollars, you’re not going to find a Zigbee stack with the connectors for that price. So unless you’ve got a special use case, the built-in Wi-Fi connectivity option should work just fine.

What’s happening with your light bulb? Does your light bulb have user accounts? Is it running an operating system?

Yup, I’m using the Philips Hue environment. All of that software stack is maintained by Phillips and it’s on their device, which is the controller and it’s part of the Philips Hue starter kit. In the book I talk about how to connect your Philips Hue controller to your Raspberry Pi so that your Pi can actually send it commands through a Python library called phue. That library essentially crafts Python calls into REST calls that are then sent to the Philips Hue controller and allow you to easily enumerate what lights you have as well as operate those lights to turn on, off, set brightness levels, et cetera. It makes the process very, very simple to control your home lighting environment.

You’ve mentioned the fan, you’ve mentioned the Philips Hue. How do you find technology, especially new and emerging technology, which is ready for this project?

Like most people, I tune into whatever is showing up in news feeds, various home automation and Raspberry Pi Reddit groups, GitHub repos, and the like. All of those different sources come into play when it comes to percolating new and interesting ideas. Sometimes, they just come out of the blue or they’ll be an amalgamate of different approaches. In fact, right now, I’m starting to play around with a high-resolution seven-color eInk display called the Inky Impression board, which is about roughly about five inches by five inches in size. It’s a way to constantly provide a low-power display, similar to what you see with a Kindle. You can refresh it with new content, such as a colorful display of data like outdoor temperature, calendar, quotes for the day, different news feeds, et cetera. You can set it up on a desk, just like an electronic photo album, but because it’s eInk-based, it’s very low power.

For example, I attached a Pi Zero to the back of it. So now, I have this low-power, very colorful display showing pertinent information sitting at my bed stand where I normally don’t have to turn on a computer, fiddle with a phone, unlocking it and such, just to see what news feeds are showing up. It’s an effortless way to summarize what’s going on. I’m also using Prometheus and Grafana to monitor my various Pis throughout the home, and I have alert triggers set up for any exceeding threshold. I can also easily get basic statistics like CPU utilization or disk storage capacity, and those can all be crafted on a nice little display like the Inky.

The PI Zero is what, ten bucks, fifteen bucks, something like that?

Yep.

How much does this eInk display cost?

It’s a little bit more expensive, mostly from a hobbyist standpoint. I think I got mine for around sixty dollars, but it’s still cheaper than a full-blown LED display. Plus, it doesn’t consume anywhere near the amount of power because it’s just like the eInk display you see on a Kindle. Once it flashes its update on the screen, no additional energy is needed. Because the power consumption is much, much lower, it makes this display more practical to use as a constant display.

Can you talk more about the different projects in the book and the range of projects that you show people how to do?

Sure. In addition to the thermostat project I talk about, there is also a water alert notifier. If you have a dishwasher or a washing machine that has an occasional leak, it’s nice to know that it’s leaking before you walk in and see a big puddle of water that’s quickly being soaked up by things that it probably shouldn’t be soaked up by. Another example is consuming text-based news feeds and turning them into an audible, podcast-like listening experience. It’s relatively easy for your Pi to pull these feeds down and do the text-to-speech conversion while you’re asleep. When you wake up the next day, you literally have a spoken newspaper ready to listen to. That’s just one of the many fun projects in the book.

Other projects include using the Pi camera, which is an inexpensive attachment that you can use as a way to either capture video or, in my case, just a still snapshot. You can combine that with a motion detector. Anytime motion is detected, you can have the camera take a snapshot and send it somewhere. In my case, I use Discord because it’s a relatively easy API to work with.

Discord is just one of the many messaging services out there. You can certainly use other services that use webhooks or a web service. You can use Zoom, Microsoft Teams, Google Chat, and various other ones that have open APIs that you can connect to. It’s somewhat easy to do. But in the book, just to minimize the amount of complexity, I really focused on one of the simplest to use, which is the Discord API.

Any other standout projects you would like to mention?

One of the projects in the book that I use every day is called the smart voice assistant, which turns on and off various appliances that may not have a smart IOT interface. I have an older television that only uses infrared as its means of turning things on and off. You literally have to have a line-of-sight remote to turn on and off the TV. Well, it’s a good TV and I don’t need to get a new one just yet, but it is inconvenient to always look for that remote, and also I got to make sure I’ve got a perfect line of sight so I can point the remote just perfectly to get that infrared signal to be read.

To solve this inconvenience, what I did was use a Pi Zero connected to a USB-based transceiver that can both send and receive infrared signals. I set that Pi Zero assembly underneath the television. When I send it commands through voice, I can say, “Hey, Google, tap the screen.”

Automated Voice:
Tapping the power button on the TV and soundbar.

And right now my television turned on and the soundbar underneath it turned on. Both of those consumer electronic appliances are not Internet of Things friendly, but now I simply can turn on and off the TV accordingly. I do the same thing with my computer when I tell it to turn on. Not only does the computer turn on, but an infrared-based sound system activates, as well as the Hue lighting around the computer and the computer desk, because I’ve got nice LED lighting that lights up and such. All of those things that you would normally have to manually select one at a time, it now becomes a series of automated workflows, which is all triggered by a single voice. It’s nice!

Speaking of older technology, could you talk a bit about the Atari.

The Atari, as in…

I’ve been told that you and the Atari have some extensive history?

Oh yeah. Well I guess so. That was one of probably my earliest magazine articles, way back in the late ’80’s.One of the first articles I wrote was for controlling a serial interface via an Atari ST that was connected to a LaserDisc player. If you remember the old arcade game Dragon’s Lair, which was a LaserDisc game that was controlled by whether you move the joystick up, down, left, right, I configured the same thing. Back then, I had an actual LaserDisc copy of Dragon’s Lair, and I was able to play the game to make it work on the Atari ST.

Good to know.

I wrote a follow up article at the time when Roland (www.roland.com) had put together a portable synthesizer unit. It had no keyboard, and it was called an MT=32. I assembled an interface to be able to programmatically control it from the Atari ST screen via the Atari ST’s built-in MIDI interface. So it was—I guess that was—my early foray, if you will, into controlling other computing devices.

What are three bits of advice you would give anyone who wants to build their own home projects like this?

First bit of advice is to get yourself a Raspberry Pi. It doesn’t matter if it’s a Raspberry Pi 3, 4, or a Zero, just get one. Number two, take a look at Python. If you don’t have any Python experience, there are a lot of really good Python tutorials available on YouTube. Of course, Pragmatic has some great Python books, with one of my favorites being Practical Programming. Just dip your toe into learning how to write some simple Python scripts. Finally, the third and most important thing is to play. This is where I think most people get the most satisfaction from these projects. They play around with them and discover things on their own. It’s a really wonderful feeling to know that you’re able to create these projects and put them into real-world, practical use. It’s not just an exercise or a homework assignment, but real-world solutions that you use every day. And you have full total control over it.

So that is probably the best way to be able to not only implement but also learn and advance your capabilities. When the next idea comes up, it’s no longer this mystery and you’ll be able to actually explore and do it on your own. You’re the one who will benefit from that experiential learning investment.

How can people keep track of what you’re doing?

Probably the best thing to do is visit my website for the various links of things that I’m working on. That’s mikeriley.com. You can follow me on Twitter, although I’m not all that active on social media because I find it more toxic these days than anything else. So the easiest thing is to just check out mikeriley.com and the various links that I have there. People are welcome to send me messages anytime. I always enjoy having open conversations, especially around the topic of technology.

Thank you, Mike. This has been awesome.

Great. I’m so glad.

3 Likes

Corresponding tweet for this thread:

Share link for this tweet.

2 Likes

This was a really cool read - thank you Mike and Erica! I am sure anyone interested in IoT will find it fascinating :023:

Reading through it my first question was…

Why!? …and I was glad to see that was answered later on in the interview :lol:

That’s really cool! Something we’ve talked about on the forum before is the need for smart modems/routers that keep a record of everything your devices send/receive and to which IPs/domains - just so we can see exactly what our programs and operating systems are dialling home with. It would be very cool if we could do something like that with a Pi!

I’m glad I’m not the only one suspicious of these companies getting their hands on so much of our data!

Thanks again for this interview it was a great read! The only question I have is something I often ask in these spotlights, and that is what do you think we’ll see in tech in the near, and maybe not so near future? :upside_down_face:

2 Likes

Thank you for your wonderful comments, Ashton. They really made my day!

Your future tech inquiry is a really good question. As for the near-term, I fear we are unfortunately going to enter a bit of an ice age until the supply chain constraints on computing technologies can be alleviated. Finding a new Pi 4 for sale today is nearly impossible unless one is willing to pay an unreasonably priced privilege to do so. I suspect we’ll be able to start thawing out in 2024, so that by 2025, chips will flow again like water. The timing for this will allow chip designers to truly hone the best configuration possible while they wait for the shortages to abate. This will bring on such a burst of innovation and a giant step forward that by 2028, we will begin to see another tectonic shift in the way people interact with computing technology. Smartphones will become like PC’s as whatever new form factor projects actionable information to us. Exciting times and new technologies are just around the corner!

3 Likes

Drop any questions you have for Mike into this thread. Everyone commenting or asking a question will automatically be entered into a drawing to win one of his books!

If you don’t want to wait, you can pick up your copy of Portable Python Projects today!

Don’t forget you get 35% off with the coupon code devtalk.com!

2 Likes

Hello, What Raspberry Pi limitations/quirks have you noticed during your projects? What is better not to try to do with this solution? For example, it seems to me that a PI will not be a very efficient as a NAS due to the IO architecture. Thanks.

3 Likes

While the Pi 4’s CPU’s are the best yet in the Raspberry Pi hardware line, they are still not quite capable of tasks requiring heavy compute needs. Even the desktop experience is still not something I would want to use as a daily driver. While it could drive a NAS, performance would likely be sub-par. I have found running a Kubernetes cluster on a Pi 4 consumes nearly 60% of CPU just running standard Ingress and web interface services like Portainer, so the Pi’s ARM-based CPU still has a long way to go to catch up to something like Apple’s M1.

4 Likes

Thank you Mike and Erica for the wonderful interaction. I have been on the fence about getting a Raspberry Pi for a while now, but I guess this convinced me to get one.

I want to pick Mike’s brain for any ideas he might have for projects for a particular context. The context I am thinking of is rural India and it is a slightly unique place globally because it is a large, young, “rustic” demographic with access to cheap internet. What kind of IOT / hardware projects or avenues would you think are relevant for us? Are you aware of any people / projects that we can take an inspiration from?

3 Likes

Hi mortz,

Assuming you have access to stable electrical and Internet connectivity, the Pi could make a good, reliable server for a variety of functions. Obvious services like file sharing, monitoring, security, along with IT-focused capabilities like running a Gitea server and even a Kubernetes server (Rancher’s K3s and Ubuntu’s microK8s work out of the box on the Pi’s ARM-based hardware).

As for a place for interaction and inspiration (in addition to my book :slight_smile: ), take a look at some of the projects Pi enthusiasts have posted in the Raspberry Pi reddit at:

Raspberry Pi Projects Hub (reddit.com)

Best of success with your Pi journey!

3 Likes

Hi Mike

Wondering about the feasibility of the Pi for an RC controller?

For quadcopters there are boards that translate movement requests into voltages that control motors. But if we want to try novel combinations of motors and tilting mechanisms some sort of toolkit is needed to construct responses to user input and device state changes.

Currently building an evtol rc with 4 motors of one size and 2 smaller motors. The RC is bilaterally symetrical, but the mid motors tilt, the rear and front motors are on tilting wings. There are 6 motors and 4 tilt controls, not to mention gyro, altimeter, etc.

Can a real time or close to real time support be achieved?

3 Likes

That’s a tricky proposition - RC’s typically use low power, embedded hardware specifically designed for these types of operations. Pi’s don’t have the kind of response timing yet to match embedded system response times, but it’s improving as the CPU’s get more powerful. However, that performance comes at the price of power consumption, something that a battery-powered RC unit is already thirsty for. It would be a good science project to prove out the prototype, but beyond that, I don’t think it would be an adequate, long-term solution to what you’re looking for. Good luck with the project, simonsay!

3 Likes

I really appreciate you sharing your experiences with Raspberry Pi and Atari. I had a Commodore 64 and an Intellivision, but never tried hacking on them. (Still wishing I had the Atari, hah) Not sure how many quarters I spent on Dragon’s Lair, but I certainly enjoyed my time in the arcades! Great to see it mentioned.

My question: I have an original Raspberry Pi and I also have a set of original Pinocchios. Do you have any suggestions on projects I could use those in? Or is it better to just get a new 64-bit Pi before I dive back in?

3 Likes

Thanks for the kind comments and recollections, SourceNode! As for the original Pi versus Pi 4 (if you can find one), I would definitely go with the Pi 4. The original Pi lacks on-board Bluetooth and WiFi connectivity, meaning you would need a USB dongle for either. Also, the original Pi has meager CPU and RAM capacity, so unless your projects can get by on Ethernet with minimal resources, I suggest at least a Pi 3 or newer if possible.

3 Likes