OS error :Failed to write byte

Hey,
I am running in to this error almost every time i use the pan-tilt hat and the servo’s doesnt even move.
Anyone know any solutions to this?

Traceback (most recent call last):
File “/home/pi/track/facetracker.py”, line 37, in
pan(cam_pan-90)
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 466, in servo_one
self.setup()
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 80, in setup
self._set_config()
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 118, in _set_config
self._i2c_write_byte(self.REG_CONFIG, config)
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 209, in _i2c_write_byte
raise IOError(“Failed to write byte”)
OSError: Failed to write byte

You aren’t Sreehar, are you?

It sounds like you’re getting intermittent failure of the I2C bus. Is this a program you’ve written yourself? If so, do any of the default examples work? If not, how have you connected the pan-tilt to the Pi?

Yes same person.
I did not write the code.
Default examples shows same error.
like this

That doesn’t look like Pimoroni’s Pan Tilt Hat?
And if it isn’t, that’s why their code doesn’t work on it.

Yeah, that looks like a Waveshare Pan Tilt (although it also looks like a product shot, so maybe they just grabbed the first vaguely similar thing off google to illustrate?)

I have the Pimoroni PanTilt hat and I am getting the same error. Any thoughts?

127.0.0.1 - - [01/Dec/2024 13:44:12] “GET /api/tilt/88 HTTP/1.1” 500 -
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/flask/app.py”, line 2548, in call
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/flask/app.py”, line 2528, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/flask/app.py”, line 2525, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/flask/app.py”, line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/flask/app.py”, line 1820, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3/dist-packages/flask/app.py”, line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/steve/pantilt-hat/examples/pantiltweb/pantiltweb.py”, line 29, in api
pantilthat.tilt(angle)
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 496, in servo_two
self.setup()
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 80, in setup
self._set_config()
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 118, in _set_config
self._i2c_write_byte(self.REG_CONFIG, config)
File “/usr/lib/python3/dist-packages/pantilthat/pantilt.py”, line 209, in _i2c_write_byte
raise IOError(“Failed to write byte”)
OSError: Failed to write byte

I should also mention, I am testing this on a Raspberry Pi 5 with the latest 64-bit Bookworm OS. The I2C interface is enabled. Running everything in a virtual environment. Python is version 3.11.2. Python3-smbus is installed and is the latest version (4.3-2+b3)

thanks.

Maybe it is just the photo, but it doesn’t look like the pins on your GPIO extender are actually connecting with the HAT? They should slot into the holes in the black socket.

Ouch, you are 100% correct. Trying to add space above the active cooler, but I definitely messed up and made the standoffs too long and didn’t see it until you mentioned. I will fix that and retry.

thanks

That was indeed the issue. The hat is working properly now.
Many thanks!

Fixed :)

I’m glad it’s working!