led controle with pca9685

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
djhieronymus
 
Posts: 5
Joined: Mon Jun 13, 2022 5:16 pm

led controle with pca9685

Post by djhieronymus »

Hello,

I have a raspberry pi zero w with pca9685 board contect.
On the pca board will only be connect led.
I can control the led's but not individual.
Exaple if channel 0 is on and i also want channel 2 on.
Then channel 0 is going off.
is there a script or can some help me out to fix this

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: led controle with pca9685

Post by mikeysklar »

Can you post a photo of how you have connected the LEDs and the code you are using to drive them? Are you using setPWM()?

User avatar
djhieronymus
 
Posts: 5
Joined: Mon Jun 13, 2022 5:16 pm

Re: led controle with pca9685

Post by djhieronymus »

led are connected true the yellow and black pin off the pca9685
download.png
download.png (9.15 KiB) Viewed 281 times

Code: Select all

#!/usr/bin/python

import Adafruit_PCA9685
pwm2 = Adafruit_PCA9685.PCA9685(address=0x41)

pwm2.set_pwm_freq(1000)

pwm2.set_pwm(x, 4096, 0);
i also done this the same for channel 2 , 3 ....

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: led controle with pca9685

Post by mikeysklar »

Are you missing some lines of code? The example code has an i2c initialization.

Code: Select all

import board
import busio
import adafruit_pca9685
i2c = busio.I2C(board.SCL, board.SDA)
pca = adafruit_pca9685.PCA9685(i2c)
https://learn.adafruit.com/16-channel-p ... 2998544-10

The full code for dimming LEDs looks like:

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

# This simple test outputs a 50% duty cycle PWM single on the 0th channel. Connect an LED and
# resistor in series to the pin to visualize duty cycle changes and its impact on brightness.

from board import SCL, SDA
import busio

# Import the PCA9685 module.
from adafruit_pca9685 import PCA9685

# Create the I2C bus interface.
i2c_bus = busio.I2C(SCL, SDA)

# Create a simple PCA9685 class instance.
pca = PCA9685(i2c_bus)

# Set the PWM frequency to 60hz.
pca.frequency = 60

# Set the PWM duty cycle for channel zero to 50%. duty_cycle is 16 bits to match other PWM objects
# but the PCA9685 will only actually give 12 bits of resolution.
pca.channels[0].duty_cycle = 0x7FFF
https://learn.adafruit.com/16-channel-p ... 2998655-26

User avatar
djhieronymus
 
Posts: 5
Joined: Mon Jun 13, 2022 5:16 pm

Re: led controle with pca9685

Post by djhieronymus »

when i use fullscript , i get this error:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 174, in __probe_for_device
self.i2c.writeto(self.device_address, b"")
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 169, in writeto
return self._i2c.writeto(address, buffer, stop=stop)
File "/usr/local/lib/python3.7/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.7/dist-packages/Adafruit_PureIO/smbus.py", line 314, 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.7/dist-packages/adafruit_bus_device/i2c_device.py", line 180, in __probe_for_device
self.i2c.readfrom_into(self.device_address, result)
File "/usr/local/lib/python3.7/dist-packages/busio.py", line 159, in readfrom_into
return self._i2c.readfrom_into(address, buffer, stop=stop)
File "/usr/local/lib/python3.7/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.7/dist-packages/Adafruit_PureIO/smbus.py", line 181, 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):
File "test.py", line 17, in <module>
pca = PCA9685(i2c_bus)
File "/usr/local/lib/python3.7/dist-packages/adafruit_pca9685.py", line 141, in __init__
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 61, in __init__
self.__probe_for_device()
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 183, in __probe_for_device
raise ValueError("No I2C device at address: 0x%x" % self.device_address)
ValueError: No I2C device at address: 0x40

User avatar
djhieronymus
 
Posts: 5
Joined: Mon Jun 13, 2022 5:16 pm

Re: led controle with pca9685

Post by djhieronymus »

have fixed my selves , first led is working

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: led controle with pca9685

Post by mikeysklar »

What was the resolution to your issue?

User avatar
djhieronymus
 
Posts: 5
Joined: Mon Jun 13, 2022 5:16 pm

Re: led controle with pca9685

Post by djhieronymus »

first i had board error

clean install sd with raspberry pi lite to start
then follow the instructions off:

https://learn.adafruit.com/circuitpytho ... -test-3-15

after that install driver off pca9685

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”