Piicodev servo board i2c issue on pi 5

I am attempting to use the piicodev servo controller board on a Pi 5 and have been following the tutorial at

When I run the basic example for an angular servo the code fails on the initialisation of the servo driver module

controller = PiicoDev_Servo_Driver()

Following the stack trace down the failure is:

File “/home/pk/piicodvservos/lib/python3.11/site-packages/smbus2/smbus2.py”, line 311, in open
self.fd = os.open(filepath, os.O_RDWR)
FileNotFoundError: [Errno 2] No such file or directory: ‘/dev/i2c-1’

looking in /dev on my pi 5 I note that only the devices ic2-11 and ic2-12 exist. My simple attempts to force the code to set the bus number to 11 have not been successful. Is this what I should be trying to do, or is the issue elsewhere?

1 Like

Hey Peter,

Welcome to the forums!

It looks like the error here is most often seen when i2C is not enabled on the Pi itself. You can get this fixed up by going through raspi-config and then navigating to Interface Options and I2C then confirming your choice. From there reboot the Pi and give it another try.

Hopefully that fixes the issue you are having!

Cheers,
Blayden

1 Like

Blayden, Many thanks. I now have i2c-1!

Alas I am still stuck at the controller initialisation
controller = PiicoDev_Servo_Driver()

I am now getting a timeout error within the i2c_rdwr() function in smbus2.py

File "/home/pk/piicodvservos/lib/python3.11/site-packages/smbus2/smbus2.py", line 658, in i2c_rdwr ioctl(self.fd, I2C_RDWR, ioctl_data) TimeoutError: [Errno 110] Connection timed out

What obvious thing have I missed now …?

I have just tried the servo control board on a Pi 3 and have ended up with the same timeout error.

On both the Pi 3 and Pi 5 I am using the 64 bit operating system. Could that be the problem, should I install the 32 bit system?

Wouldn’t think the operating system bit size is the problem.
Connection timed out means the I2C software cannot see the Servo Controller.
This could be wiring or address mismatch.

Open a terminal window and type the following.
i2cdetect -y 1

It will scan I2C bus ‘1’ for connected devices listing what it finds.
The Servo Controller addresses are 0x44, 0x45, 0x46, 0x47.
If you don’t see these it is a wiring problem.

The addresses above are referred to as channels 1,2,3,4 in the software.
ie servo = PiicoDev_Servo(controller, 1) is channel 1 address 0x044.

Changing the Dip switches changes the address.

I suggest using the PiicoDev Pi break out and the one of the Cables, it is the easiest way to connect I2C to a Pi 5.

Regards
Jim

1 Like

Jim, Many thanks for that. Unfortunately the i2cdetect probing comes up blank on all addresses. I am using the PiicoDev adapter and cable. I will get myself another cable and see if that is the failure point

1 Like

When you connect the Servo Controller to the Adaptor does the Power LED come on, it should ??

1 Like

I have had the same problem as Peter and have now enabled i2c. I now get a TypeError on smbus.py line 365 "argument must be an int’ or have a fileno() method.
i2cdetect -y 1 shows a 44 and also a 70.
Any clues please? Geoff

Line 365 is ioctl(self.fd, I2C_FUNCS, f)
Doing a print on each argument gives None, 1797, c_uint32(0). I am a complete Python newbie but I suspect that self.fd as None is the culprit. Is the class not being instanteated?

1 Like

Hey @Geoff45102,

That would be my guess as well. self.fd should be passed to this function as an int and it being None instead is probably the cause of this issue.

44 is the default address for the servo driver board so it looks like this is being detected correctly.

It may be worth double-checking your packages are installed correctly and up to date. If you could share the code you are using we can give it a check for any issues that may be causing this?

1 Like

I didn’t do any testing on this after the OP did not respond any further. But …
Today I successfully tested this on a Raspberry Pi 4 using Bullseye and Bookworm.
The Thonny install of PiicoDev worked ok with Bullseye but not with Bookworm.

Installed version: 1.10.3
Installed to: /home/pi/MyEnv/lib/python3.11/site-packages

Latest stable version: 1.10.3
Summary: MicroPython Drivers for the PiicoDev ecosystem of sensors and modules
Author: Core Electronics
License: Could not find the package info from PyPI. Error code: wrong # args: should be “.!localcpythonpipdialog.!frame.!panedwindow.!frame2.!textframe.!enhancedtext_orig insert index chars ?tagList chars tagList …?”

With Bookworm I created a virtual environment /home/pi/MyEnv as detailed in the guide, then used pip in a terminal window to install PiicoDev. Just need to specify the path to pip in the virtual environment. pi@raspberrypi:~ $ sudo /home/pi/MyEnv/bin/pip3 install piicodev

Suggest, as @Samuel has said, to reinstall everything.
I started with reloading Bookworm using the Pi Imager on a Windows PC. Once the SD card was installed on the Pi and the OS started let it update as it needed then use Thonny to setup the virtual environment.

The error message above should be investigated by Core Electronics as the PiicoDev stuff belongs to them. It worked OK with Bullseye. I also note the guide is version 1.10.0.

Cheers
Jim

2 Likes

With a new piicodev driver module and a new cable the “PiicoDev Servo Driver PCA9685 | Getting Started Guide” example now works. It would appear that I had a hardware problem. Thanks for your assistance. Geoff

2 Likes

Hey @Geoff45102,

That sounds like good progress towards getting it fixed, let us know if you get stuck on anything else. :grinning:

The hardware problem I had was that cables between the pi and the servo board bought from Altronics have the wires swapped over to those from Core’s. Core’s work - Altronics don’t.

2 Likes

@Geoff45102 well done for spotting that!! Clutching at straws I too had bought another board and cable - from Altronics… I had given up and abandoned the project.

I have just cut one of my cables in half, resoldered the wires in reverse order and now everything runs as it should.

Thank you for persevering and finding the problem.

1 Like

Good find @Geoff45102, I’m sure that would have driven you crazy! Glad to hear it’s working for you now.