New install Piano Hat not working

Installed Piano Hat on RPi3 per website and rebooted. Basic example program (listed below) throws errors:

Traceback (most recent call last):
File “/home/pi/Documents/”, line 1, in
import pianohat
File “/usr/lib/python3/dist-packages/”, line 175, in
_piano_ctog = cap1xxx.Cap1188(i2c_addr=0x28, alert_pin=4)
File “/usr/lib/python3/dist-packages/”, line 282, in init
self.product_id = self._get_product_id()
File “/usr/lib/python3/dist-packages/”, line 468, in _get_product_id
return self._read_byte(R_PRODUCT_ID)
File “/usr/lib/python3/dist-packages/”, line 493, in _read_byte
return self.i2c.read_byte_data(self.i2c_addr, register)
OSError: [Errno 5] Input/output error

import pianohat
import time
def handle_note(channel, pressed):
if pressed:
print (“You pressed key {}”.format(channel))
print (“You released key {}”.format(channel))


while True:

I’m a teacher with 25 eager Python students. Please help!

Looks like a problem talking to the HAT from the Pi.

Is the Piano HAT located properly on the Pi’s GPIO pins? Are you using any sort of ribbon cable extension setup?

What do you see if you run: i2cdetect -y 1 in terminal?

PianoHat seated properly. i2cdetect gives 28 and 2b.
Would love to get this working!! will be at PiCademy Austin next two days
and would like to share success with other attendees!

Well that’s all sane, very odd that i2cdetect would show a result but it would fail at the first attempt to talk to the devices!


i2cget -y 1 0x28 0xfd


i2cget -y 1 0x2b 0xfd

This is basically asking to grab the Product ID (register 0xfd) from each devices (the first hex number being the address).

A register, in loose terms, is a slot where a single 8bit (0-255) number can be stored/retrieved. All communication with Piano HAT is done by reading and writing numbers to these slots.

So for some reason, the example code is working now. Am happy but puzzled

  • wonder if the hat or Pi connector is flaky (gave it a snug before running
    code)…These Pis are used in classes with 6th graders and take some
    abuse…will let you know if problem recurs. Thanks a ton for the very
    prompt help!!!

I had exactly the same error as you with a different product not 5 minutes after I replied. Turned out I’d been handling it too gingerly and hadn’t pushed the pHAT all the way onto my Pi :D D’oh.

Glad it’s up and running!


I cannot get the basic piano hat download to work.
I copied the the line:
curl | bash
From the website to avoid typos, ifails saying it cannot connect to the internet. If I put:
Into the web browser on the same Pi it downloads the script !!
I have tried updating curl, I tried adding sudo to the beginning of the command but that didn’t work. When I tried putting sudo in front of the bash if failed saying “Running as root. Please login as a regular user with sudo rights”
I tried the ic2commands mention here and I got the same numbers as Anitatech.

Any ideas what I’m doing wrong ?

Regards Dave

See my answer over on: Piano Hat script not downloading using curl