Wednesday, 25 March 2015

More fun with the Pimoroni Explorer HAT

I've been playing a bit more with the new Pimoroni Explorer HAT.

One of the most exciting features of the Pro version is the analogue interface.

Once you've installed the ExplorerHAT package using pip, you can try typing in the examples in the README on github.

If you want some more examples, you can clone the github repository into a directory of your choice. Then you'll be able to run the code from the examples directory. Type

git clone
cd explorer-hat
sudo python examples/

You'll see a series of rapidly varying numbers displayed in the console. These show the current voltage as seen on analogue input 1. Since you (presumably) haven't connected that to anything, the output will be fluctuating random values.

To see something more sensible, use a jump wire to connect analogue input 1 to the Hat's 3.3 volt output, and you should see the display stabilize showing a value of about 3.3

The github repsoitory now contains an experimental fritzing library containing parts for the HAT and Pro HAT; I used the Pro version to create the diagram above.

I'm really excited by the Explorer HAT. I will blog some more about it as I play, and I am going to use the blog posts as the basis of an inexpensive Experimenter's e-book. If you might be interested, sign up here and I'll let you know when the book is available.

Tuesday, 24 March 2015

Pimoroni Explorer Pro Hat - first impressions

This morning my new Explorer Hat from Pimoroni arrived, and the tempation to play has proved to much to resist.

There are two versions of the Explorer Hat, standard and Pro. I greedily ordered one of each; the standard version is great for experimenting, but the Pro version offers several extra useful features.

I started with the Pro.

I love it.

Here's what the Explorer hats provide:
  • Four buffered 5V tolerant inputs
  • Four powered 5V outputs (up to 500mA!)
  • Four capacitive touch pads
  • Four capacitive crocodile clip pads
  • Four coloured LEDs
  • PRO ONLY Four analog inputs
  • PRO ONLY Two H-bridge motor drivers
  • PRO ONLY A heap of useful (unprotected) 3v3 goodies from the GPIO
  • A mini breadboard on top!
It took me a couple of minutes to get the environment set up
The Readme on the github site tells you how prepare your Pi, and then walks you though some fun experiments.

One thing to watch: the setup instructions suggest that you install pip by typing
sudo apt-get install python-pip

Just say no

I recommend that you don't install pip that way. The version of pip that's included in the raspbian distribution is quite old, and it will bring python2.6 in with it! With yet another version of Python on your pi, the possibilities for confusion are considerable, and using the outdated version of pip can cause other problems.

Instead, I recommend that you start by installing setuptools and use easy_install (part of setuptools) to install pip. Here's what you need to type:

sudo apt-get install python-setuptools
sudo easy_install pip

and now you can type

sudo pip install explorerhat

Apart from that, the installation instructions are fine, and very clear.

Once you've configured i2c and installed all the required software, you can start to flash LEDs and write code that responds to button presses.

Lights On!

Here's the Python code to turn the red led on:

That's simple and intuitive. I'll bet you can guess how you turn the red light off, and the blue light on :)

I suspect you'll find that the Explorer Hat makes it as easy to do Physical Computing on the Pi as it is on the Arduino.

You'll be programming interactively in Python instead of editing, compiling and uploading code in the Arduino's c-based Wiring language. Many people will find that development is faster and the learning curve is less steep.

I think Pimoroni have a real winner here, especially at the very attractive price. The Pro is £18, and the standard Explorer Hat is just £10.

Spread the good news! You can share this post using the buttons below.

Friday, 20 March 2015

Using the Raspberry Pi SPI as an AVR ISP (In-system programmer)

A few days ago I blogged about using the Arduino IDE on the Raspberry Pi. It works fine, but of course the Arduino or clone needs to have a boot-loader installed in order for the IDE to work its magic.

I wondered if you could also use a Pi to install the boot-loader in the first place. There are lots of ways to install a boot-loader, but most of them require that you start out with at least one working Arduino or clone. What if you don't have one? Could you use a Pi as a programmer?

(c) Jason Mann
I'd recently seen a rather cool project which uses a custom board with an ATTiny AVR chip and an LED display to show the Pi's IP address.

Jason Mann, the author, explained how he used the Pi to program the ATTiny.

It looked to me as if his technique should work just as well on an ATMega 328p. (That's the chip that forms the heart of the Arduino Uno and the Shrimp).

It does.

I hit some minor complications while getting things to work and thought I should share the solutions here.

The Software

In order to install the bootloader I used avrdude. This does not support programming using the Pi's SPI port out of the box, but there's a forked version written by Kevin Cuzner which does.

Enabling SPI

Jason's article refers to an old way of configuring the Pi to use SPI ports. The raspi-blacklist.conf file appears to have disappeared. Instead, this article describes three ways of enabling SPI.

I went for the simplest, ran sudo raspi-config, selected the option to enable SPI, and rebooted.

I followed  Kevin Cuzner's instructions to build his forked version, and then realised that I had another potential problem. I now had a modified version of avrdude in the /usr/local/bin directory, but I also had an un-patched copy which the Arduino IDE had installed.

Luckily, the Arduino IDE finds its own version because it comes earlier in the search path, so the IDE still works perfectly. To use the patched version I referred to its location explicitly. You can see that in the example at the end of this post.

The Hardware

Jason's project runs the ATTiny at 3.3 volts but the Arduino normally runs at 5v. While you can just about get away with directly connecting a 5v Arduino to a Pi if you're using I2C, you cannot do so using SPI.

I had an Adafruit Pi Cobbler+ and couple of SparkFun level shifters lying around. I connected the Pi via the cobbler to the shifters and the shifters to the Arduino. You can see a picture at the top of the page.

Trying it out

I ran

sudo /usr/local/bin/avrdude -c linuxspi -p m328p -v -P /dev/spidev0.0

Here was the tail of the response:

         Programmer Type : linuxspi
         Description     : Use Linux SPI device in /dev/spidev*

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK (E:05, H:DA, L:FF)

avrdude done.  Thank you.

More detail

This post is already long enough. If you want the full details of the installation and build process, along with a fritzed diagram of the breadboard connections, I'll be posting them in next Friday's free newsletter.

You can sign up for the newsletter here.