ROS2 Jazzy driver for PCF8591 8-bit 4-channel ADC + 1-channel DAC over I2C (NXP).
The PCF8591 is a popular combo ADC/DAC chip that provides 4 analog input channels and 1 analog output channel in a single I2C device. It is widely used with Raspberry Pi for reading analog sensors and generating simple analog output signals.
- Publishes
std_msgs/Float32per active ADC channel onadc/channel{0-3} - Publishes DAC feedback on
dac/output(std_msgs/Float32) - Subscribes to
dac/command(std_msgs/Float32) to set DAC output fake_modefor testing without hardware- 8-bit resolution (256 steps) for both ADC and DAC
- Configurable reference voltage and active channels
- Voltage offset calibration via service call
- Runtime
publish_ratechange viaros2 param set
- ROS 2 Jazzy
- Python 3
smbus2(pip install smbus2) — only needed for real hardware
cd ~/ros2_ws
colcon build --packages-select pcf8591_adc_dac --symlink-install
source install/setup.bashros2 launch pcf8591_adc_dac pcf8591_launch.pyros2 run pcf8591_adc_dac pcf8591_node.py --ros-args -p fake_mode:=trueros2 topic pub /dac/command std_msgs/msg/Float32 "{data: 1.65}" --onceros2 topic echo /adc/channel0
ros2 topic echo /dac/outputpcf8591_node:
ros__parameters:
fake_mode: false
i2c_bus: 1
device_address: 0x48
vref: 5.0
active_channels: [0, 1]| Parameter | Type | Default | Description |
|---|---|---|---|
fake_mode |
bool | true |
Use fake driver (no hardware) |
i2c_bus |
int | 1 |
I2C bus number |
device_address |
int | 0x48 |
I2C address (0x48–0x4F) |
vref |
double | 3.3 |
Reference voltage (Volts) |
publish_rate |
double | 10.0 |
Publishing rate (Hz) |
active_channels |
int[] | [0,1,2,3] |
ADC channels to read (0–3) |
| Service | Type | Description |
|---|---|---|
pcf8591/calibrate |
std_srvs/srv/Trigger |
Collect samples for 2s, compute ADC voltage offset bias |
pcf8591/reset |
std_srvs/srv/Trigger |
Clear bias, reinitialise sensor |
pcf8591_adc_dac/
├── CMakeLists.txt
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── .gitignore
├── package.xml
├── config/
│ └── pcf8591_params.yaml
├── launch/
│ └── pcf8591_launch.py
├── nodes/
│ └── pcf8591_node.py
├── pcf8591_adc_dac/
│ ├── __init__.py
│ └── pcf8591_driver.py
└── test/
└── test_pcf8591_node.py
Tested on Ubuntu 24.04 (WSL2) with fake_mode: true.
| Test Category | Test | Result |
|---|---|---|
| Topics | adc/channel{0-3} publishes std_msgs/Float32 |
PASS |
| Topics | dac/output publishes std_msgs/Float32 |
PASS |
| Services | pcf8591/calibrate returns success=True |
PASS |
| Services | pcf8591/reset returns success=True |
PASS |
| Parameters | publish_rate runtime change |
PASS |
| Shutdown | Clean exit | PASS |
| Linting | pep257, flake8, copyright, xmllint | PASS |
MIT