Rainbow HAT review

By Russell Barnes. Posted

A versatile HAT to try out Android Things or use with Python

Originally known as Project Brillo, Google’s recently relaunched Android Things operating system is designed to be used with IoT devices including the Raspberry Pi 3. To save you the trouble of connecting various individual electronic components to your Pi to try out the new system, Pimoroni has designed the all-singing, all-dancing Rainbow HAT. Jam-packed with LEDs, buttons and sensors, it enables you to experiment with Android Things and use it with the wide range of protocols available on the Raspberry Pi, such as GPIO, I2C, SPI, and PWM.

To show numbers and letters, there’s an I2C-connected four-digit alphanumeric display, which is a cut above the standard type with 14 segments per digit, enabling it to accurately show the full alphabet. GPIO is used for the three capacitive touch buttons and their built-in LEDs (red, green, and blue respectively). The most visually impressive feature is the SPI-operated ‘rainbow’ arc of seven super-bright APA102 RGB LEDs that gives the HAT its name. PWM is employed for the piezo buzzer, which can be used to play buzzy tunes. I2C is also used for the BMP280 sensor, which measure temperature and pressure. Finally, there’s a line of 15 breakout pins for servo, I2C, SPI, and UART – all powered by 3V3. One notable omission, however, is an accelerometer/magnetometer, as featured in Pimoroni’s Enviro pHAT – possibly there wasn’t room on the board for one.

The Rainbow HAT can be programmed using Python in Raspbian, but we first tried it out with Android Things (see boxout for more details). Since the coding – via a remote computer – is mainly done in Java, it helps if you have a working knowledge of the language. Alternatively, like us, you can import one of the example projects from the Android Things GitHub repo. The first time you do this, you’ll be prompted to install and update various tools and plug-ins, which is a bit of a hassle, but after that it works smoothly.

Android examples

To start with, we tried out the sample-button app from the Android Things repo. All it does is light up the LED of the Rainbow HAT’s capacitive button A when you press it. By digging into the code, you can change the GPIO pin numbers to use a different button and LED, although you’ll need to refer to pinout.xyz to find the correct numbers. Next, we imported the weather station project, which showed off more of the HAT’s capabilities. By default, the segment display displays the current temperature, although we soon noticed it rising. As usual with a board-mounted sensor, this is due to the heat from the board and the Raspberry Pi just below it, but you could always calibrate it by comparing the real ambient temperature (using a standard thermometer) to discover the average difference. A press of a button switches the display to pressure, which is also indicated by the rainbow arc of LEDs. You can also configure this example app to publish sensor data to Google Cloud Pub/Sub, from which you can process it and visualise it using various Google tools.

Alternatively, in the Raspbian OS, Python can be used to program the HAT. There’s a dedicated library, added using the one-line installer. Example programs include a pirate-themed demo that plays the What Shall We Do with the Drunken Sailor? sea shanty on the piezo buzzer while gradually changing the colour of the rainbow arc and showing AHOY, YARR or GROG on the alphanumeric display depending on the capacitive button pressed! Other examples include a temperature gauge and an RGB/HSV lamp whose shade is set using the touch buttons.

A look at the library example code – or the getting started tutorial – reveals a simple syntax for using the HAT’s features, such as weather.temperature to obtain temperature data and display.print_str(‘AHOY’) to show a string on the four-digit alphanumeric display.

Whether programmed using Python or Android Things, the Rainbow HAT has an impressive number of features crammed into it, making it useful for all sorts of projects. Suggestions from Pimoroni include a weather station, stopwatch or countdown timer, three-note piano, reaction time game, and mood light.

Last word

4/5

A potpourri of LEDs, buttons, and sensors makes the Rainbow HAT very useful for experimenting with Android Things, or programming with Python in Raspbian. It may be overkill for some projects, but it’s a versatile add-on that offers good value for money.

From The MagPi store

Subscribe

Subscribe to the newsletter

Get every issue delivered directly to your inbox and keep up to date with the latest news, offers, events, and more.