I would like to ask some opinions regarding i2c communications with pca9685. My i2c1(SDA=GPIO2, SCL=GPIO3) of my rpi 4b is used by my mpu6050, which I had to enable one more i2c channel of my raspberry pi. So, I enabled it through the figure below:
I rebooted my rpi 4b after, then successfully detected the address through i2cdetect.
I went through to test the device writing some codes, and the giving me some errors which said "ValueError: No I2C device at address: 0x40"
The strange thing is that when I connect pca9685 through the i2c1(SDA=GPIO2, SCL=GPIO3), it works.
My code was:
import time
import board
import busio
from adafruit_pca9685 import PCA9685
from adafruit_motor import servo
i2c = busio.I2C(board.SCL, board.SDA)
pca = PCA9685(i2c, address = 0x40)
pca.frequency = 50
servo_m = servo.ContinuousServo(pca.channels[0])
servo_m.throttle = -1
time.sleep(1)
servo_m.throttle = 0
time.sleep(1)
servo_m.throttle = 1
time.sleep(1)
servo_m.throttle = 0
time.sleep(1)
I will post the specific error for a better visualization. Moreover, I will post the picture regarding the configurations of the pins (Black - GND, Orange = SCL, Green = SDA, Red = Vcc, White = V+). Thanks!
The followings are the error I got:
Traceback (most recent call last):
Eile "/usr/local/lib/python3.9/dist-packages/adafruit bus
device/i2c device.py", line 176, in _ probe for device
Self.i2c.writeto(self.device address, b"")
File "/usr/local/lib/python3.9/dist-packages/busio.py", line
175, in writeto
return self. _i2c.writeto(address, buffer, stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit
blinka/microcontroller/generic linux/i2c.py", line 52, in
writeto
self. _i2c_bus.write_bytes(address, buffer[start:end])
File "/usr/local/lib/python3.9/dist-packages/Adafruit
PureI0/smbus.py", ling 320, in write bytes
self. _device.write(buf)
OSError: [Errno 121] Remote I/O error
During handling of the above exception, another exception
occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/adafruit bus
device/i2c_device.py", line 182, in _ probe for device
self.i2c.readfrom_into(self.device address, result)
Eile "/usr/local/lib/python3.9/dist-packages/busio.py", line
165, in readfrom_into
return self. _i2c.readfrom_into(address, buffer, stop=stop)
File "/usr/local/lib/python3.9/dist-packages/adafruit
blinka/microcontroller/generic linux/i2c.py", line 59, in
readfrom into
readin = self. _i2c_bus.read_bytes(address, end - start)
File "/usr/local/lib/python3.9/dist-packages/Adafruit
PureIO/smbus.py", line 187, in read bytes
return self._device.read (number)
OSError: [Errno 121] Remote I/O error
During handling of the above exception, another exception
occurred:
Traceback (most recent call last):
Eile "/home/bob/FYP/Servo/test110.py", line 13, in <module>
pca = PCA9685(i2c, address=0x40)
Eile "/usr/local/lib/python3.9/dist-packages/adafruit
pca9685.py", line 141, in _ init
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
Eile “/usr/local/lib/python3.9/dist-packages/adafruit bus
device/i2c_device.py", line 63, in _ init
self.__probe_for_device()
Eile "/usr/local/lib/python3.9/dist-packages/adafruit bus
device/i2c_device.py", line 185, in __ probe for device
raise ValueError("No I2C device at address: Ox%x" %
self.device_address)
ValueError: No I2C device at address: 0x40