1

I would like to ask a question regarding the usage of secondary channel of i2c in rpi 4b. I have enabled the secondary channel through adding "dtoverlay=i2c-gpio,bus=2,i2c_gpio_sda=22,i2c_gpio_scl=23" in the "config.txt" file. Thus, I was able to attain the address "0x40" by typing in "i2cdetect -y 2" in the terminal of my rapsberry pi 4b. However when I run my python code, it states an error which "no i2c device found at address 0x40." I tried to debug the program and it is the problem with the "busio" module. The strange thing is that when I connect it to the primary i2c channel, it works, however, if I connect it to my secondary channel the program doesn't work. It would be so much appreciated if anyone can help me solving up this issue.

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_motor = servo.Servo(pca.channels[0])

    while True:
       servo_motor.angle = 0
       time.sleep(1)
       servo_motor.angle = 90
       time.sleep(1)
       servo_motor.angle = 180
       time.sleep(1)
2
  • what is the question that you would like to ask? ... please format your code ... click the Edit button
    – jsotola
    Mar 20 at 7:56
  • Please provide clear photos of the connections.
    – joan
    Mar 20 at 9:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.