Make a Mac OS X ‘Task Done’ NeoPixel Notification Light

I regularly back-up my Raspberry Pi storage card because it’s so easy to damage the card with an improper shutdown or some such. I back up to a Mac, and you can read how I do it here. This wasn’t much of a chore in the early days when I was working with 4GB cards, but now I use 16GB Micro SDs and I know of folks who have much, much larger storage capacities thanks to never-cheaper cards. All this means the back-up takes a long time. So I wondered if I could create a gadget to tell me the task was done, allowing me to get on with other jobs in the meantime.

NeoPixel/FT232H Notifier

At-a-glance notification when your Pi back-up is done, anyone?

Coincidentally, I dug out an Adafruit FT232H which I’d bought some months previously but never really played with. The FT232H is a small breakout board containing an FTDI FT232H chip. FTDI specialises in USB-to-serial converters. I use a cable containing an FTDI chip to connect Raspberry Pi UART pins to host computers, for example. But the Adafruit board goes further: it uses the FTDI tech to provide not only a serial line, but also access to GPIO pins and I²C and SPI buses.

Every one of these feeds can be controlled and interacted with by code running on your computer. All you need is the right driver software, some Python code and a USB micro cable.

NeoPixel/FT232H Notifier

Adafruit’s small FT232H breakout board

I had intended to explore the FT232H, but had been held up by the need to find an application. Now I had one: my aforementioned Raspberry Pi back-up task notifier. The key was the FT232H’s SPI support — could I use it to drive a NeoPixel?

It turns out I can. I’ve some experience of driving NeoPixels — WS2812 RGB LEDs, to be accurate — via SPI, thanks to an Electric Imp Internet of Things project I did. NeoPixels have their own bus protocol, but one that’s easy to emulate using SPI. NeoPixels also run on 5V power, so they can be driven by USB.

So here’s what I built and how.

First, the circuit. I put the FT232H and a single NeoPixel on a small solderless breadboard. The latter I hooked up to the breakout’s GND and 5V pins; I wired its Data In pin to the FT232H’s D1 pin, its SPI MOSI (Master Out, Slave In) port.

NeoPixel/FT232H Notifier

FT232H and NeoPixel wired up on the breadboard

Adafruit has a great tutorial on setting up its board for use with all the major operating systems — I’ll paraphrase the Mac OS X instructions. Note that you’ll have to install Homebrew if you haven’t done so already. Run the following from the Terminal:

brew install cmake
brew install libusb
brew install swig
brew install --build-from-source libftdi
mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo '/usr/local/lib/python2.7/site-packages' >
    ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth

If you plug in the FT232H now and try to run code that does anything other than communicate with the breakout by serial, it won’t work. You’ll get an “FTDI USB open error: unable to claim usb device. Make sure the default FTDI driver is not in use (-t)” error. Adafruit’s tutorial was written a couple of years ago, and Apple’s FTDI driver has changed in the interim. What you need to do is temporarily unload it, which you can do by entering this line at the Terminal prompt:

sudo kextunload -bundle-id com.apple.driver.AppleUSBFTDI

You can check it has worked by entering:

kextstat | grep -i ftdi

which should come up blank. If it doesn’t the driver is still loaded. You can re-load the driver if you need to by restarting your Mac or using:

sudo kextload -bundle-id com.apple.driver.AppleUSBFTDI

Now use your preferred text editor to enter the following Python code:

Next, create a hidden file called .status on your machine. Save it where you like, but make sure you enter the path correctly in the code above (line 51). Put the characters 0.0.0 in the first and only line.

Finally, edit your .bash_profile file — it’s in your home folder but hidden, so you may need to access it through the Terminal nano — and add the following lines:

alias taskdone='echo "1.0.0" > ~/.status'
alias taskclear='echo "0.0.0" > ~/.status'
alias taskset='sudo kextunload -bundle-id com.apple.driver.AppleUSBFTDI;
    python ~/Dropbox/Programming/Python/statuslight.py'

Save the file and you’re ready to go. Plug in the hardware and enter taskset at the command line. Your light should start running a sweep through the colours of the spectrum. You can test out the notification by entering:

sleep 4;taskdone

After four seconds, the light will flash red. Enter:

taskclear

to clear the notification.

Now when you come to do a backup of your Raspberry Pi’s storage card — or run any other Terminal task that takes a long time to execute — add ;taskdone to the end of the command line. For example:

sudo dd if=/dev/rdisk2 of=pi.img bs=1m ; taskdone

When the task completes, the light will flash red to let you know.

Once I’d got it working, I mounted the breadboard inside a small project box and cut a piece of translucent plastic to fit on top. The are many other ways you could mount the light on or by your computer. And the code above is easily customised for other roles and modes. You might simply want it off when there’s no notification to signal.

NeoPixel/FT232H Notifier

The Notifier looks even better when cased

I didn’t used two of the three digits in the source file in this project, but they’re there to be used, and the “0.0.0” sequence can be extended even further if you wish. You code just needs to check the appropriate entry in the item[] array and cue up a suitable notification colour. You’ll want to adapt your code to be able to signal multiple notifications, of course, so that one doesn’t ‘overwrite’ another. For example, it’s not hard to get red and blue to flash alternately, signalling two notifications.

A couple of things to note: the Apple FTDI is always loaded at a restart — hence the unload code in the taskset alias. And quitting the Python code and restarting it will generate an error unless you unplug and replug the FT232H from USB. If you forget to run taskclear before starting a new task, just open another Terminal tab and enter taskclear there.

NeoPixel/FT232H Notifier

 

I bought my Adafruit FT232H from Pimoroni. Ditto the NeoPixels

Review: Circuitbeard PiZero Hub Case

The Raspberry Pi Zero may have been out for a while, but it’s proving perishingly hard to get hold off. Unless, of course, you’re right at the head of the virtual queue when the online retailers put their latest batches on sale. Still, the little micro’s scarcity isn’t stopping hackers from coming up with ingenious solutions to its other limitations — too few USB ports, primarily — and accessory suppliers from issuing add-ons.

Here’s one that (kind of) does both. Sheffield-based Circuitbeard’s case doesn’t only house a Zero, it’s also intended to hold an equally diminutive four-port USB hub. Think of it as a tiny bunk bed with the Zero resting on top and the hub’s main circuit board reposing on the level below.

Circuitbeard Pi Zero Hub Case

Zero above, four ports below

The design is very reminiscent of Pimoroni’s Pibow: all laser-cut clear acrylic sheets and those annoying nylon nuts and bolts you can never tighten properly without smearing the thread. The circuit boards are each sandwiched by a couple of acrylic sheets. The whole assembly is held together by four bolts at the corners. The Zero is fixed to its base-sheet with four smaller bolts which you’ll need to cut down to size once they’re in place. The hub is held in place by a bolt that runs between two of the USB connectors and by gaps in the base sheet which trap solder points on the PCB. Small circular spacers stop the corners pulling in when you tighten the main bolts.

Circuitbeard supplies two top-sheets: one with a gap cut to make room for GPIO pins and a second that covers the Zero entirely.

Circuitbeard Pi Zero Hub Case

One upper sheet is cut to provide easy GPIO access

You have to figure out what goes where yourself, but there’s a set of photos of the complete unit on Circuitbeard to work from. The various lumps and bumps on the two circuit boards guide you too. To be fair to Circuitbeard, the case started life as a design anyone could download and use for themselves. It was demand from the laser cutter-less that prompted the case’s evolution into a retail item.

It should be no surprise that the case doesn’t come with a Zero, and the hub is extra too. You’ll need to pull it apart to free the circuit board, but that’s not hard. It’s a specific model of hub: the LogiLink UA0160, but Circuitbeard says you can use the Belkin F5U404 instead. You can find either on eBay.

Circuitbeard Pi Zero Hub Case

What goes where

I used the Belkin. Unfortunately, it’s not exactly the same as the Logilink. A couple of extra surface-mount components on the base of the board prevented it from aligning with the case’s base correctly, causing the base to bend slightly. These components aren’t present in Circuitbeard’s photos, so I’d recommend you go for the UA0160. Also, according to my multimeter, the Belkin is only outputting 3.3V from the power pin the tutorials indicate (unlike the IA0160, I believe), but there is a 5V point elsewhere on the board.

Circuitbeard Pi Zero Hub Case

The Belkin hub’s circuit board causes bending

With the case assembled and fully laden, you can use a supplied mini-to-micro USB cable to connect the hub to the Zero. There’s room within the curve of the short cable for an HDMI adaptor. But it has to be said, getting the Zero’s Micro SD card in and out of this case is a pain. If you need to re-flash your card, you’ll need tweezers or plenty of patience while you disassemble the case.

Circuitbeard Pi Zero Hub Case

Pi-to-hub connector cable supplied

You can hook up the hub’s own AC adaptor if you need hub power. Or you can wire a couple of tiny pins on the bottom of the hub’s PCB to two pads on the underside of the Zero, and feed power to the hub from the Zero, or vice versa. Trouble is, you still need the external cable for data, so all it does is save you a second power cable.

It’s also possible to run a couple of wires from other pads on the Zero to a different bit of the hub and do away with the USB adaptor cable altogether, but the case doesn’t expose that part of the Zero. That said, if you’re up for the soldering anyway, you shouldn’t have too much trouble drilling the case to create the holes you need for the USB data wires to pass through.

My soldering’s not quite up to the task, alas, so I’ll stick with the cable and bus-powered devices: a WiFi dongle and, occasionally, a keyboard. The external cable is a but ugly, but no worse than a dangly USB on-the-go cable and an external hub, powered or otherwise.

Circuitbeard’s case makes for a much neater, more readily portable package. I like it.

Price £12
More Info Circuitbeard

Review: Google Chromecast 2

OK, so we all know what Google’s Chromecast is, yes? Someone at the back — why are they always at the back? — seems unsure. In a sentence, then, Chromecast is a small WiFi-connected slug that you slip into a spare HDMI port on your TV, and which plays video and audio under the direction of a remote control app.

Chromecast 2

The curvy and cabled Chromecast 2

Continue reading

Review: Slice, the Pi Compute Module-based media player

Updated My original idea was to review the Raspberry Pi Compute Module. But the thing about the Compute Module is that it’s not an end-user product: it was designed for manufacturers looking for an ARM-based platform on which they can build devices they can sell. Unlike the Raspberry Pi itself, the Compute Module is not intended for makers or for computing hobbyists. To evaluate the Compute Module what I really needed to look at was a product based upon it.

So I waited for one.

Slice

Slice of Pi?

Continue reading

Review: Imagination Technologies’ MIPS Creator CI20

Time was when chip makers’ processor evaluation boards were well beyond the reach of ordinary mortals. That didn’t matter, of course: ordinary mortals weren’t interested in small, nude motherboards designed to help designers of embedded systems judge a microprocessor’s suitability for the application they were working on.

MIPS Creator CI20

Imagination Technologies’ MIPS Creator CI20

Continue reading