New install Piano Hat not working


#1

Installed Piano Hat on RPi3 per website https://learn.pimoroni.com/tutorial/piano-hat/getting-started-with-piano-hat and rebooted. Basic example program (listed below) throws errors:

Traceback (most recent call last):
File “/home/pi/Documents/piano_test.py”, line 1, in
import pianohat
File “/usr/lib/python3/dist-packages/pianohat.py”, line 175, in
_piano_ctog = cap1xxx.Cap1188(i2c_addr=0x28, alert_pin=4)
File “/usr/lib/python3/dist-packages/cap1xxx.py”, line 282, in init
self.product_id = self._get_product_id()
File “/usr/lib/python3/dist-packages/cap1xxx.py”, line 468, in _get_product_id
return self._read_byte(R_PRODUCT_ID)
File “/usr/lib/python3/dist-packages/cap1xxx.py”, 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))
else:
print (“You released key {}”.format(channel))

pianohat.on_note(handle_note)

while True:
time.sleep(0.001)

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


#2

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?


#3

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!


#4

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!

Try:

i2cget -y 1 0x28 0xfd

and

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.


#5

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!!!

#6

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!


#7

Hi,

I cannot get the basic piano hat download to work.
I copied the the line:
curl https://get.pimoroni.com/pianohat | bash
From the website to avoid typos, ifails saying it cannot connect to the internet. If I put:
https://get.pimoroni.com/pianohat
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


#8

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