Reference
PCA9685
16-channel PWM/servo controller.
- Connects over
- I²C
- Address
- 0x40 (or 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F)
- Made by
- NXP
- Datasheet
- nxp.com
Use it
hardware {
device pca9685: PCA9685
}
every 1s {
pca9685.set_servo(1, 1)
}
On its own, the declaration puts the PCA9685 on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x40. To choose the pins or the address, declare the bus and attach the device: device pca9685: PCA9685 on i2c0 at 0x41 with i2c i2c0(sda: 21, scl: 22).
Methods
-
pca9685.set_servo(channel: int, angle: int)
Set servo angle 0-180
-
pca9685.set_duty(channel: int, duty: int)
Set PWM duty 0-255
Wiring
| Pin | Connect to |
|---|---|
VCC | 3.3V or 5V |
GND | Ground |
SDA | Pull-up to VCC (often on breakout board) |
SCL | Pull-up to VCC |
OE | Output enable — pull low to enable PWM, high to blank all |
V+ | Servo/LED supply — separate from logic VCC (e.g. 6V for servos) |
Specifications
- Voltage
- 2.3V – 5.5V (logic); separate V+ for LED/servo supply
- Current
- 8 mA active
- Channels
- 16 PWM outputs
- Resolution
- 12-bit per channel
- Frequency
- 24 Hz – 1526 Hz (shared across all channels)
Tips
- Set PWM frequency to ~50 Hz for hobby servos, 1 kHz for LED dimming.
- All channels share the same frequency — pick the one that fits your worst case.
- Don't power servos from the MCU's USB rail — they brown out the MCU on startup.
Alternatives worth knowing:
- TLC59711: 12 channels, 16-bit resolution, SPI — better resolution for LED projects.