ROS2 Jazzy driver for MCP4725 12-bit single-channel DAC over I2C (Microchip).
The MCP4725 is a popular I2C DAC for generating analog output voltages from a Raspberry Pi or other microcontroller. It provides 12-bit resolution (4096 steps) with fast write mode and optional EEPROM storage for power-on default output.
- Subscribes to
dac/command(std_msgs/Float32) to set output voltage - Publishes feedback on
dac/output(std_msgs/Float32) fake_modefor testing without hardware- 12-bit resolution (4096 steps), configurable Vref
- Fast write mode for low-latency updates
- EEPROM write support for power-on defaults
- 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 mcp4725_dac --symlink-install
source install/setup.bashros2 launch mcp4725_dac mcp4725_launch.pyros2 run mcp4725_dac mcp4725_node.py --ros-args -p fake_mode:=trueros2 topic pub /dac/command std_msgs/msg/Float32 "{data: 1.65}" --onceros2 topic echo /dac/outputmcp4725_dac_node:
ros__parameters:
fake_mode: false
i2c_bus: 1
device_address: 0x60
vref: 5.0
initial_voltage: 2.5| Parameter | Type | Default | Description |
|---|---|---|---|
fake_mode |
bool | true |
Use fake driver (no hardware) |
i2c_bus |
int | 1 |
I2C bus number |
device_address |
int | 0x60 |
I2C address (0x60 or 0x61) |
vref |
double | 3.3 |
Reference voltage (Volts) |
publish_rate |
double | 10.0 |
Feedback publishing rate (Hz) |
initial_voltage |
double | 0.0 |
Output voltage at startup (Volts) |
| Service | Type | Description |
|---|---|---|
dac/calibrate |
std_srvs/srv/Trigger |
Measure offset at 0V, store as bias |
dac/reset |
std_srvs/srv/Trigger |
Clear bias, set output to 0V, reinitialise |
mcp4725_dac/
├── CMakeLists.txt
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── .gitignore
├── package.xml
├── config/
│ └── mcp4725_params.yaml
├── launch/
│ └── mcp4725_launch.py
├── nodes/
│ └── mcp4725_node.py
├── mcp4725_dac/
│ ├── __init__.py
│ └── mcp4725_driver.py
└── test/
└── test_mcp4725_node.py
Tested on Ubuntu 24.04 (WSL2) with fake_mode: true.
| Test Category | Test | Result |
|---|---|---|
| Topics | dac/output publishes std_msgs/Float32 |
PASS |
| Services | dac/calibrate returns success=True |
PASS |
| Services | dac/reset returns success=True |
PASS |
| Parameters | publish_rate runtime change |
PASS |
| Shutdown | Clean exit | PASS |
| Linting | pep257, flake8, copyright, xmllint | PASS |
MIT