PiicoDev_Servo i2c connection

Hi
Does the PiicoDev Servo Driver require the i2c connection only via a PiicoDev cable or can it be connected directly from the Pico i2c pins (pin 1 - sda, pin 2 - sci, pin 3 gnd, and pin 39 - 3.3v) to the i2c ‘pins’ on the end of the PiicoDev board?

This issue has arisen where the project does not include a PiicoDev expansion board but the i2c connection needs to be hard wired.

Thanks
Toni

1 Like

I’ve not used this motor driver but I have used other piicodev products.

Best I understand the piicodev cable and the adapter is just a JST with no bells and whistles.
From experience with other piicodev stuff, you’ll find joy connecting this to any I2C bus via the pin-outs provided or by hard wiring it to any compatible plug. Most* piicodev product, including this one, have internal pullup resistors required for the i2c protocol.

I’m basing this on the schematic. :slight_smile:

*all?

1 Like

Thanks Jonny

Just to clarify my question, a Raspberry Pi Pico does not incorporate an i2c socket so i2c can only be used via the appropriate 4 pins on the board.

Using these pins I have previously made successful i2c connections to PCA9685 16-channel driver boards and assumed the process with the PicoDev Servo Driver would be similar.

With this cabled connection I have tried to run the code(s) published in the guide but they fail when it comes to the i2c address. I have tried to get on top of the PiicoDev_Servo.py library file which is where the error messages originate from but am not having much success.

Can you help?

Regards
Toni

1 Like

There’s nothing magical about an I2C socket - it simply connects straight to the appropriate GP pins and power. What is the code you are using to create the I2C bus on pins GP0 and GP1?

What is the error you are getting? What address have you configured the PiicoDev Servo Driver for, and have you confirmed that the device is detected at that address?

1 Like

By “i2c socket” are do you mean one of these? :slight_smile:

Like @Jeff105671 I’d love to see an error message. :slight_smile:

1 Like

Thanks gents

Attached are photo of the physical setup and resulting error messages.

The coding is exactly the same as that in the Getting Started Guide.


Hope this helps
Toni

1 Like

Can you post a description of your wiring - it is not possible to check it completely from an image, where some of wires are concealed.

What I2C address have you configured the driver module for? Have you used the I2C scan utility to confirm that it is responding correctly at that address?

1 Like

I have experienced a situation where I needed to power off and on the Pico to get I2C to work after making some changes to the code. Something in the micropython code startup I put it down to.

Was extremely frustrating till I accidently removed power and it worked when powered up again. I was able to duplicate it too. But this situation has occurred very rarely.

Suggest try a power cycle and see what happens, might not be the problem but worth a try after what I experienced.

BTW I have successfully hardwired a I2C piicodev cable to a pico board and it worked. the main problem I had was getting the data lines the right way around. Always check that first.

Cheers
Jim

1 Like

Jeff, my answers to your questions are as follows:

Ii2c GND - pico pin3
i2c 3.3V - pico pin39
i2c SDA - pico pin 1
i2c SCL - pico pin2

i2c.scan() gives ie nothing connected

Unlike with the successful code I wrote for the 16 Chanel PCA9685 board, the code for the PiicoDev servo board, as given in the Guide, does not include the set up i2c statements I would have expected.
Further delving into the published libraries seems to indicate that the i2c definitions are buried in these documents including a statement _I2C_ADDRESS = 0x44 . I’m not clear how this operates but would not expect the i2c ‘address’ to be in a library document rather I would expect it to be in the operating code.

Thanks
Toni

1 Like

Thanks Jonny, I am hoping not to have to go down that road but even if I do the pins of the JST-SH Connector do not align with those on the Pico, so some hard wiring would inevitably be required.
Toni

1 Like

Thanks James,

Yes I have already tried the old power on/off trick to no avail.

With your connection to the Pico am I right in assuming that you used an I2C PiicoDev cable with one end cut off and soldered to the pico pins? In my case I am not using the I2C PiicoDev cable connector but am wiring the cable directly from the pico to the i2c pins at the end of the board. Perhaps this is an issue?

Did you use the published code?

Toni

1 Like

Hi Toni,

The servo driver is expecting the I2C pins to be on the micropython default I2C pins (8/9)

For pins 0/1 to be used they can be specified manually like:

from machine import Pin, I2C
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400_000)
controller = PiicoDev_Servo_Driver(i2c=i2c) 
# Rest of your code here

Let us know how that goes!
Liam

That’s the clue. The scan is telling you that the device is not visible, and the lack of a specific setup is telling you that the default is being used, The default bus is not the one the device is connected to. Either use the default bus and leave the code as is, or adjust the code to use the bus you are connected to.

It is not unusual for a library to include default values. That means that a simple form of the initialisation will use those defaults, but there are override forms of the initialisation that allow you to specify a different configuration.

1 Like

Yes,Picodev cable one end cut off and header pins crimped on. (Core actually sell these I found out later) The header pins and the Pico plugged into a piece of vero board with sockets. Allows for removal of the parts if necessary. The connection was to GP8 & GP9 and used the PicoDev library.

As @Liam has mentioned GP8 & GP9 are used by the PicoDev libraries. The defaults are built into the library but you can override them by passing the pins numbers in your code, as @Liam showed.

Cheers
Jim

1 Like

Thanks all

With Liam’s code installed the error message is still unexpected keyword argument i2c at the controller = line.

Adding the i2c.scan() code produces:
[68,112]
so something is happening but still the error message appears.

Toni

2 Likes

note 68 decimal is 44 hex which is what is nominated in the library PiicoDev_Servo.py

2 Likes

Hi @Toni135859

Looks like Liam had a human moment there, the code should have been

from machine import Pin, I2C
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400_000)
controller = PiicoDev_Servo_Driver() 
# Rest of your code here
3 Likes

Sorry Dan, but the following code still produces the attached error messages:

from machine import Pin, I2C
from PiicoDev_Unified import sleep_ms
from PiicoDev_Servo import PiicoDev_Servo, PiicoDev_Servo_Driver

i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=400_000)
print(i2c.scan())
controller = PiicoDev_Servo_Driver()

I must be really missing something!!
Toni

2 Likes

Hi @Toni135859

My apologies, the frequency should be set to 400000 not 400_000, remove that underscore and see how you go

2 Likes

Hi Dan

That change didn’t fix the problem, same error message appears. I’ve tried power on/off etc but nothing changes.

Toni

2 Likes