Adds configurable I2C address for PCA9685 PWM driver (#26051)

* Adds configurable I2C address for PCA9685 PWM driver

Introduces a parameter to set the I2C address for the PCA9685 PWM output driver, enhancing flexibility for hardware variations. Updates documentation and board initialization scripts to support the new configuration and streamline device startup.

* Update src/drivers/pca9685_pwm_out/module.yaml

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/drivers/pca9685_pwm_out/module.yaml

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
This commit is contained in:
Alex Klimaj
2025-12-12 11:31:19 -07:00
committed by GitHub
parent c25fcabcc6
commit 12745baf6c
13 changed files with 74 additions and 4 deletions
+1
View File
@@ -40,6 +40,7 @@ CONFIG_DRIVERS_MAGNETOMETER_ST_IIS2MDC=y
CONFIG_DRIVERS_POWER_MONITOR_INA226=y
CONFIG_DRIVERS_POWER_MONITOR_INA228=y
CONFIG_DRIVERS_POWER_MONITOR_INA238=y
CONFIG_DRIVERS_PCA9685_PWM_OUT=y
CONFIG_DRIVERS_PWM_OUT=y
CONFIG_DRIVERS_PX4IO=y
CONFIG_COMMON_RC=y
+6
View File
@@ -97,5 +97,11 @@ bmm150 -I start
# Internal Baro on I2C
bmp388 -I start
# Start an external PWM generator
if param greater PCA9685_EN_BUS 0
then
pca9685_pwm_out start
fi
unset HAVE_PM2
unset HAVE_PM3
+1
View File
@@ -21,6 +21,7 @@ CONFIG_DRIVERS_IMU_MURATA_SCH16T=y
CONFIG_COMMON_LIGHT=y
CONFIG_COMMON_MAGNETOMETER=y
CONFIG_DRIVERS_OSD_MSP_OSD=y
CONFIG_DRIVERS_PCA9685_PWM_OUT=y
CONFIG_DRIVERS_PWM_OUT=y
CONFIG_COMMON_RC=y
CONFIG_DRIVERS_UAVCAN=y
+6
View File
@@ -16,3 +16,9 @@ iis2mdc -R 0 -I -b 4 start
# Internal Baro on I2C
bmp388 -I -b 2 start
# Start an external PWM generator
if param greater PCA9685_EN_BUS 0
then
pca9685_pwm_out start
fi
+1
View File
@@ -19,6 +19,7 @@ CONFIG_COMMON_LIGHT=y
CONFIG_DRIVERS_MAGNETOMETER_MEMSIC_MMC5983MA=y
CONFIG_DRIVERS_MAGNETOMETER_ST_IIS2MDC=y
CONFIG_DRIVERS_OPTICAL_FLOW_PAW3902=y
CONFIG_DRIVERS_PCA9685_PWM_OUT=y
CONFIG_DRIVERS_POWER_MONITOR_INA226=y
CONFIG_DRIVERS_PWM_OUT=y
CONFIG_COMMON_RC=y
+6
View File
@@ -34,3 +34,9 @@ paw3902 -s -b 3 start -Y 90
# Internal distance sensor
afbrs50 start
# Start an external PWM generator
if param greater PCA9685_EN_BUS 0
then
pca9685_pwm_out start
fi
@@ -74,5 +74,5 @@ ist8310 -X -b 1 -R 10 start
# Start an external PWM generator
if param greater PCA9685_EN_BUS 0
then
pca9685_pwm_out start -b 1
pca9685_pwm_out start
fi
@@ -11,3 +11,7 @@ param set BAT1_V_DIV 5.7
# Always keep current config
param set SYS_AUTOCONFIG 0
# PCA9685 PWM Out defaults
param set-default PCA9685_EN_BUS 4
param set-default PCA9685_I2C_ADDR 64
@@ -28,7 +28,7 @@ then
echo "ads1115 not found."
fi
if ! pca9685_pwm_out start -a 0x40 -b 4
if ! pca9685_pwm_out start
then
echo "pca9685_pwm_out not found."
fi
@@ -486,6 +486,16 @@ The integer refers to the I2C bus number where PCA9685 is connected.
| ------ | -------- | -------- | --------- | ------- | ---- |
| &nbsp; | 0 | 10 | | 0 |
### PCA9685_I2C_ADDR (`INT32`) {#PCA9685_I2C_ADDR}
I2C address of PCA9685.
The default address is 0x40 (64).
| Reboot | minValue | maxValue | increment | default | unit |
| ------ | -------- | -------- | --------- | ------- | ---- |
| &nbsp; | 0 | 127 | | 64 |
### PCA9685_FAIL1 (`INT32`) {#PCA9685_FAIL1}
PCA9685 Output Channel 1 Failsafe Value.
+2
View File
@@ -899,6 +899,8 @@ fetching the latest mixing result and write them to PCA9685 at its scheduling ti
It can do full 12bits output as duty-cycle mode, while also able to output precious pulse width
that can be accepted by most ESCs and servos.
The I2C bus and address can be configured via parameters `PCA9685_EN_BUS` and `PCA9685_I2C_ADDR`, or via command line arguments.
### Examples
It is typically started with:
+25 -2
View File
@@ -47,6 +47,7 @@
#include <drivers/drv_hrt.h>
#include <px4_platform_common/getopt.h>
#include <px4_platform_common/sem.hpp>
#include <lib/parameters/param.h>
#include "PCA9685.h"
@@ -356,8 +357,30 @@ int PCA9685Wrapper::custom_command(int argc, char **argv) {
int PCA9685Wrapper::task_spawn(int argc, char **argv) {
int ch;
int address=PCA9685_DEFAULT_ADDRESS;
int iicbus=PCA9685_DEFAULT_IICBUS;
int address = PCA9685_DEFAULT_ADDRESS;
int iicbus = PCA9685_DEFAULT_IICBUS;
int32_t en_bus = 0;
param_t param_handle = param_find("PCA9685_EN_BUS");
if (param_handle != PARAM_INVALID) {
param_get(param_handle, &en_bus);
if (en_bus > 0) {
iicbus = en_bus;
}
}
int32_t i2c_addr = 0;
param_handle = param_find("PCA9685_I2C_ADDR");
if (param_handle != PARAM_INVALID) {
param_get(param_handle, &i2c_addr);
if (i2c_addr > 0) {
address = i2c_addr;
}
}
int myoptind = 1;
const char *myoptarg = nullptr;
+10
View File
@@ -29,6 +29,16 @@ parameters:
min: 0
max: 10
default: 0
PCA9685_I2C_ADDR:
description:
short: I2C address of PCA9685
long: |
I2C address of PCA9685.
The default address is 0x40 (64).
type: int32
min: 1
max: 127
default: 64
PCA9685_SCHD_HZ:
description:
short: PWM update rate