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: the GrovePi+ Starter Kit

When it comes to hacking hardware there’s an easy way and there’s a hard way.

The hard way involves connecting peripherals direct to one of the standard buses supported by your Raspberry Pi, Arduino, Beaglebone or whatever. Buses like I²C, SPI, UART and 1-Wire. You’ll need to take care with your wiring: have you got the right pull-up or pull-down resistor? Is there too much capacitance in the line?

GrovePi+ Starter Kit

Dexter Industries and Seeed Studios’ GrovePi+ Starter Kit

Continue reading

Review: Pimoroni/Cyntech Pibrella

There is no shortage of clip-on boards designed for the Raspberry Pi, almost all designed to make the tiny computer’s GPIO pins more accessible in order to ease the connection of devices to it, particularly ones that operate at voltages that are not Pi friendly.

Pibrella

Electronics kit: Pimoroni/Cyntech Pibtrella

Continue reading

How to build your own Apple iBeacon… with a Raspberry Pi

US department store Macy’s recently said it is implementing iPhone-based tracking tech the better to encourage browsing punters to buy. Of course, Macy has chosen to pitch this as an Apple technology – figuring, presumably, iPhone owners are more receptive to inducements delivered through technology and have more cash to splash than Android fans.

But the fact is, the system Apple calls iBeacon simply makes use of features already part of the Bluetooth Low Energy (LE) spec.

This got me thinking: how difficult would it be to build a similar system of my own? Not very hard at all, it turns out. Choose the right kit and it can be quite cheap too. I created my beacon using a £30 Raspberry Pi and a £12 Bluetooth 4.0 USB dongle.

A Pi's UART pins, connected

Can this operate as an Apple iBeacon? Yes it can

Continue reading

How to program the Pebble smartwatch: Part 3

Update Pebble has released version 2 of its OS and this invalidates much of what follows, which was written for an earlier version of the OS.

As it stands, the app I created in Part 2 appears in the Pebble’s menu simply as a name, Ball, which is entered into the boilerplate PBL_APP_INFO created by the SDK’s create_pebble_project.py script. This also sets the app’s unique UUID, which you’ll see at the top of the file. You can also modify this to set the app’s version number and to add your name as author. But what’s really needed is a menu icon, and you can add one by editing the resource_map.json created for you in the /resources/src folder within the project folder.

Continue reading

How to program the Pebble smartwatch: Part 2

Update Pebble has released version 2 of its OS and this invalidates much of what follows, which was written for an earlier version of the OS.

In Part 1 we got our basic Pebble app up and running, but it doesn’t do very much. Let’s add some user interaction.

Continue reading

How to program the Pebble smartwatch: Part 1

Update Pebble has released version 2 of its OS and this invalidates much of what follows, which was written for an earlier version of the OS.

Pebble didn’t invent the smartwatch, but it has done more than most to bring this new product category to the attention of the world, largely thanks to its hugely successful and well-reported Kickstarter funding campaign.

Continue reading