The Official Raspberry Pi Projects Book - Projects_Book_v4

(singke) #1

Review


raspberrypi.org/magpi The Official Raspberry Pi Projects Book 175


RAINBOW HAT


Last word


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.

magpi.cc/2lX1r6h


£24 / $26


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 at
    magpi.cc/2lX6Jih – 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.

Installing Android Things


Once you’ve downloaded the latest image of
the Android Things OS (see magpi.cc/ssGoaw),
you can flash it to a microSD card to insert in the
Raspberry Pi. On booting up, it shows a logo with
network connection information underneath


  • you’ll need to hook the Pi up to the router
    via Ethernet at first, as there’s no way to set
    up wireless connectivity beforehand. With the
    Android Studio application installed on a remote
    computer, you can then connect to the Pi from a
    terminal using the adb tool from the SDK. You can
    then start building an app in Android Studio and
    deploy it to the Pi.


The most visually


impressive feature is the


SPI-operated ‘rainbow’ arc


Above Android Studio helps you program the Rainbow HAT
Free download pdf