Pan Tilt Hat Problem


No matter what I try and do to get the Pan Tilt Hat working I simply cannot find a way to import pantilthat.

Here’s my Terminal traceback:
pi@david:~/Pimoroni/pantilthat/examples $ python

Traceback (most recent call last):

File "", line 6, in <module>

import pantilthat

ImportError: No module named pantilthat

I’m running Stretch with Python 3.5.3.




im no expert ,so my first question will have to be did you do the install of the pantilt hat

.following th git hub or by installing the pimoroni dashboard
install pantilt using github

long way lots of typing .

or dashboard install–,less typing
Dashboard - What is it and what was it created in?


The quickest way to install should be the one line installer.
curl | bash
How are you running the example?
If from command line try “python3” instead of just “python”. Using python runs it in python 2.
That being said, I do believe most of Pimoroni’s installers install for python 2 and python 3?


@Caperjack1953 Thanks for your message. I have tried every iteration of installation possible through the support pages. I have done the installation inside and outside my virtualenv. The installation completes perfectly every time, no errors for all methods. I even did it through the Pimoroni GUI and still it doesn’t work. Same error message every time. Thank you

@alphanumeric Thank you for your message. I’m running the example from the Terminal. For example python or python3 Same error every time, cannot import pantilthat. I’ve literally spent 8 hours today trying to figure this out and I’m getting nowhere. I’ll gladly accept any new ideas to resolve the problem. Thank you

This is the complete Terminal response to the above command:

curl | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 38344  100 38344    0     0  45571      0 --:--:-- --:--:-- --:--:-- 45593

This script will install everything needed to use
Pan-Tilt HAT

Always be careful when running scripts and commands copied
from the internet. Ensure they are from a trusted source.

If you want to see what this script does before running it,
you should run: 'curl'

Note: Pan-Tilt HAT requires I2C communication

Do you wish to continue? [y/N] y

Checking environment...
Updating apt indexes...

Checking hardware requirements...

I2C already enabled

Checking packages required by I2C interface...
Python 2 smbus installed and up-to-date
Python 3 smbus installed and up-to-date

Pan-Tilt HAT comes with examples and documentation that you may wish to install.
Performing a full install will ensure those resources are installed,
along with all required dependencies. It may however take a while!

Do you wish to perform a full install? [y/N] y

Checking for dependencies...

Installing python-pantilthat...
install ok installed
Installing python3-pantilthat...
install ok installed

Checking for additional software...
python-picamera is already installed
python3-picamera is already installed

Downloading examples and documentation...

The examples directory already exists on your system!
We've backed them up as examples-backup, just in case you've changed anything!

Resources for your Pan-Tilt HAT were copied to

All done. Enjoy your Pan-Tilt HAT!


so open the terminal and change directory - if you haven’t all ready done so.
type in
cd /home/pi/Pimoroni/pantilt-hat/examples

then type in , sudo python


What version of Raspbian are you using?
Try sudo pip2 install pantilthat


Thanks @Caperjack1953 - this is what I was doing in my first post. Unfortunately, that doesn’t work. Now I have tried:

sudo python

and I get the same response as before, cannot import pantilthat.

@alphanumeric - this is where things start to get interesting. I am using Stretch:

Linux david 4.14.84-v7+ #1169 SMP Thu Nov 29 16:20:43 GMT 2018 armv7l GNU/Linux

I have tried sudo pip2 install pantilthat and this is the response I get to running python (same as before):

> pi@david:~/Pimoroni/pantilthat/examples $ python
> Traceback (most recent call last):
>   File "", line 6, in <module>
>     import pantilthat
> ImportError: No module named 'pantilthat'

However, if I now run what @Caperjack1953 suggested, sudo python or python2 I get this:

pi@david:~/Pimoroni/pantilthat/examples $ sudo python
Traceback (most recent call last):
  File "", line 19, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pantilthat/", line 466, in servo_one
  File "/usr/local/lib/python2.7/dist-packages/pantilthat/", line 80, in setup
  File "/usr/local/lib/python2.7/dist-packages/pantilthat/", line 118, in _set_config
    self._i2c_write_byte(self.REG_CONFIG, config)
  File "/usr/local/lib/python2.7/dist-packages/pantilthat/", line 209, in _i2c_write_byte
    raise IOError("Failed to write byte")
IOError: Failed to write byte

Looks to me like we’re making progress. Unless you have an immediate solution to this problem, let me spend some time troubleshooting this latest issue in the forums and I’ll try to resolve. Thanks.


I don’t think it matters but did you by chance install Raspbian via NOOBS? Kind of clutching at straws now to be honest.
What model Pi are you using? If it’s a Zero, did it have pre soldered header?
A lot of the time an IO error is the result of said hat not being firmly attached to the GPIO header. Not making good contact etc.


I flashed an SD card with Raspbian. Model 3B+. I’ll triple check my contacts and get back to you. Thanks.


Ok, just trying to eliminate what might be the issue. Soldering can be an issue with the Pi Zero if poorly done etc.
And some hats have that slim narrow surface mount female GPIO header. I’ve seen a few instances where it wasn’t pressed down firmly. Or no stand offs used and the hat tilts / slants messing up the connection. I personally try to always use stand offs. Especially if you have a heat sink on the Pi. It can short out against the bottom of the hat if you don’t use stand offs.


Is there a way to test the hat independently of the pi?


You’d have to use female to male jumper wires. Other than that I don’t know of a way?
Try this, from the command line run sudo i2cdetect -y 1
You should see a 15 in the window that pops up.
It should be in the 10 row and 5 column. If you do see it, I would think the hardware is OK and its a software issue. Not 100% sure about that, but thats what my brain is telling me.
If you don’t see it that means i2c isn’t detecting the pan tilt hat. That could be software or hardware, I’d be leaning more towards a hardware issue if i2c is enabled in raspi-config. The one line installer enabled i2c if it isn’t enabled. Can’t hurt to verify that it is turned on in the Raspberry Pi configuration menu.

I got that i2c address from here,


You could test the servo’s separately on the Pi with PWM. Might be a bit of a pain and time consuming though. I’d be more inclined to believe its a hat issue and not anything wrong with the servo’s. You could unplug them or double check that they are connected correctly though. Make sure the headers aren’t on backwards or something.

I meant to mention, to be patient, its the weekend. You’ll more than likely get somebody from Pimoroni chiming in Monday. Somebody more in the know than I am. ;)