Getting started with Explorer HAT

Explorer HAT does exactly what it says on the... tin? It's an opportunity to explore the functionality of your Raspberry Pi safely, without the risk of shorting GPIO pins or blowing things up. It includes 8 capacitive touch pads, 4 LEDs, 4 protected inputs, 4 buffered outputs and a mini breadboard for your projects.

Explorer HAT Pro adds a 2 channel, bi-directional motor driver and 4 analog inputs. It also breaks out some of the essential GPIO from your Pi, for easy access.

In this tutorial we'll get Explorer HAT set up and ready to use, and cover the very basics. If you're familiar with Pibrella then you'll recognise how it works- the software is very similar!

Before we start

Before installing Explorer HAT, it's good practise to update the software on your Pi. If you already know how to do this, go right ahead, otherwise you can read our guide to "Keeping your Pi Up-to-date".

Setting up Explorer HAT

We've made Explorer HAT easy to get up and running with a one-liner install script. That's one line that you have to type, or copy and paste, in order to run all the necessary steps required for the install. Once your Pi is up-to-date just open LXTerminal, type in the following and press the Enter key:

curl | bash

Verify that Explorer HAT is installed and working correctly

If you've got your Explorer HAT plugged in while the install is running, you should see the LEDs flash to confirm that install was successful. Either way, let's try running one of the example scripts to make sure... and have a little fun in the process!

With LXTerminal still open, navigate to the Explorer HAT examples folder and run one of the Python scripts you find there, you can CD ( change directory ) into the Explorer HAT examples folder like so:

cd ~/Pimoroni/explorerhat

You'll find all of our examples in ~/Pimoroni, the ~ character ( tilde ) is a handy shortcut in Linux that always points to your home directory ( Which is usually /home/pi ).

Once you're in the examples folder, run an example like so:

sudo python

Now make sure your TV is turned up, or you've got some speakers connected, and tap the capacitive touch pads ( numbered 1 to 8 on the Explorer HAT ) to bash out a rockin' drum solo!

You can also see what examples, or subfolders, are available simply by typing:


A brief introduction to Explorer HAT

If you're still with me, and sitting in front of LXTerminal ( or your the terminal your Pi boots up into, if it does, either is fine! ) then let's try playing with some of Explorer HAT's features.

First off, fire up an interactive Python shell by typing the following and pressing enter:

sudo python

We use sudo because Explorer HAT's functionality requires some extra access that a normal Raspberry Pi system user isn't allowed!

You should see a message pop up with the version number of Python and some other information, and you'll have a new kind of command prompt that looks like this:


At this prompt you can type anything you'd normally put into a Python script. To use Explorer HAT we first need to import it, so type:

>>> import explorerhat

Easy enough! You should see a message pop up confirming what version of Explorer HAT you've got plugged in. Let's toggle some LEDs:


And off again:


Now you're ready to progress to some more advanced tutorials, good luck!

In Conclusion

You should now have at least a basic understanding of how to approach new Python code and figure out how it works, and how to write and document your own code. Each new article in this series will now deal with a different aspect of Python- from bit-shifting, to lists, to class inheritance and when and where to use these things effectively.

Remember, 4 lines isn't always better than 10. If you're reducing the amount of code but increasing the complexity, and you don't have a good reason to be doing so, you should probably stop and stick with the simple approach.

That's all folks!

Search above to find more great tutorials and guides.

Plasma 2040

Swathe everything in rainbows with this all-in-one, USB-C powered controller for WS2812/Neopixel and APA102/Dotstar addressable LED strip.