python

Testing the Coral TPU Accelerator (M.2 or PCIe) in Docker

Google Coral TPU in PCIe carrier

I recently tried setting up an M.2 Coral TPU on a machine running Debian 12 'Bookworm', which ships with Python 3.11, making the installation of the pyCoral library very difficult (maybe impossible for now?).

Some of the devs responded 'just install an older Ubuntu or Debian release' in the GitHub issues, as that would give me a compatible Python version (3.9 or earlier)... but in this case I didn't want to do that.

Playing sounds with Python on a Raspberry Pi

Today I needed to play back an MP3 or WAV file through a USB audio device on a Raspberry Pi, in a Python script. "Should be easy!" I thought!

Clarence the Raspberry Pi Bell Slapper with USB audio output and speaker

Well, a couple hours later I decided to write this blog post to document the easiest way to do it, since I had to take quite a journey to get to the point where sound actually plays through the USB audio output.

The problem is most guides, like this simple one from Raspberry Pi's project site, assume two things:

Install Python 3.9 on Raspberry Pi OS or Debian 10 (for Ansible or other uses)

I've started getting a lot of bug reports on my repos to the effect of "Ansible won't install on my Raspberry Pi anymore". Accompanying it is a debug message like one of the following:

$ python3 -m pip install ansible
...
No matching distribution found for ansible-core<2.13,>=2.12.0 (from ansible)

# Alternatively:
ERROR: No matching distribution found for ansible-core<2.13,>=2.12.0

The problem is ansible-core 2.12 has a new hard requirement for Python 3.8 or newer. And ansible-core 2.12 is included in Ansible 5.0.0, which was recently released. Raspberry Pi OS, which was based on Debian 10 ("Buster") until recently, includes Python 3.7, which is too old to satisfy Ansible's installation requirements.

There was recently a fix that makes it so Ansible 5.x won't get installed on these older systems, but who wants to get stuck on old unsupported Ansible versions?

There are three options:

Face detection for my leaf blower

In the class of 'out there' projects, I recently added a little AI to my leaf blower:

Leaf blower with Raspberry Pi on top for AI ML Machine Vision blasting

The short of it: I have a face detection algorithm running which, when a certain individual enters the field of the Pi's vision, triggers a servo that powers on the blower, releasing a powerful air blast.

Red Shirt Jeff gets blasted by air cannon

I've been wanting to play around with face detection on the Pi for some time, but the Pi Zero I use in most of my camera projects is seriously underpowered for this kind of work.

CM4Ext Nano

So when Harlab (Hardware Laboratory) told me they'd like to send me a CM4Ext Nano board for testing, I thought it'd be the perfect opportunity to play with machine vision on the Pi.

The Raspberry Pi IoT Notification Bell

Harbinger of the Internet of Dings

Last year, I built the first version of what I call the "Raspberry Pi Bell Slapper." It was named that because it used a servo and a metal arm to slap the top of the bell in response to a stimuli—in this case, an email from a donation notification system for a local non-profit radio station.

This year, that same radio station had another one of their fund-raisers (a radiothon), and to celebrate, I thought I'd do the thing justice, with a better circuit (using a solenoid instead of a servo) and a 3D printed enclosure. And this is the result:

Clarence 2.0 - The Raspberry Pi Notification Bell

There is a Raspberry Pi Zero W with a custom solenoid control HAT on top inside the case to the left, and the solenoid right up against the bell, which is mounted on the right.

I also posted a video on YouTube exploring the project in detail: The Raspberry Pi IoT Notification Bell.

Fixing 'UNREACHABLE' SSH error when running Ansible playbooks against Ubuntu 18.04 or 16.04

Ubuntu 16.04 and 18.04 (and likely future versions) often don't have Python 2 installed by default. Sometimes Python 3 is installed, available at /usr/bin/python3, but for many minimal images I've used, there's no preinstalled Python at all.

Therefore, when you run Ansible playbooks against new VMs running Ubuntu, you might be greeted with the following error:

Changing a deeply-nested dict variable in an Ansible playbook

I recently had to build an Ansible playbook that takes in a massive inventory structure (read from a YAML file), modifies a specific key in that file, then dumps the file back to disk. There are some other ways that may be more efficient standalone (e.g. using a separate Python/PHP/Ruby/etc. script and a good YAML library), but since I had to do a number of other things in this Ansible playbook, I thought it would keep it simple if I could also modify the key inside the playbook.

I was scratching my head for a while, because while I knew that I could use the dict | combine() filter to merge two dicts together (this is a feature that was introduced in Ansible 2.0), I hadn't done so for a deeply-nested dict.