Multiple i2c for DC and Servo hats

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
RogerTheDodger
 
Posts: 1
Joined: Wed Mar 22, 2023 12:43 pm

Multiple i2c for DC and Servo hats

Post by RogerTheDodger »

I have built a robot forklift truck which functions perfectly using a two motor hat.
I have now modified the design to use a four motor hat to enable use of Mecanum wheels for sideways movement.
Description of Forklift Mast and Tilt operation: address 0x60 assumed, no links made
Uses Adafruit 16-Channel PWM / Servo HAT for Raspberry Pi - Mini Kit, Adafruit SKU: ADA2327
Description of DC motor hat for Mecanum wheels: address 0x61 assumed, A0 linked.
Adafruit DC & Stepper Motor HAT for Raspberry Pi - Mini Kit, Adafruit SKU: ADA2348
I created a demo .py script just to run the Mecanum wheels which ran successfully.
I then integrated this demo script into the original script for two wheel operation and found that errors occurred as follows:
Traceback (most recent call last):
File "/media/pi/FA65-17C03/ForkLiftTruck/ForkLiftTest.py", line 550, in <module>
kit.motor1.throttle = 0.5
AttributeError: 'ServoKit' object has no attribute 'motor1'
I suspect there is confusion with Servokit and Motorkit functions.
Running sudo i2cdetect -y 1 shows two i2c slaves 0x40 & 0x61
It does not show 0x60
Originally with the two motor hat it indicated 0x40 & 0x70
Errors seem related to operating two Adafruit i2c hats at the same time. Adafruit documentation refers to formatting as kit, kit1 etc. These do not work.
Further reseach seems to say i2c is a master/slave function or that i2c may require a form of polling to synchronise address/data packets.
preventing overlap.
If repeated sequential i2c requests are made without a time delay the demo script hangs, where as single stepping i2c requests function correctly. Is there a way to ensure i2c requests go to the intended hat?
I would very much appreciate any assistance anyone can give.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Multiple i2c for DC and Servo hats

Post by adafruit_support_mike »

You only have to use polling if the bus has more than one central/master device. If you only have one microcontroller, it has complete control over who sends messages and when.

The chips used in the Servo Hat and Motor Hat are designed to share the same I2C bus, so they have six pins that can change their I2C address. Each pin sets one bit in the I2C address, so you can have up to 64 of the same chip connected to the same SDA and SCL lines, each of which will respond to a different address.

Our code libraries are built to accomodate that. When you create an object to talk to one of the ICs, you have the option to set the I2C address it will use.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”