Skip to content

mingyo186/mcp4725_dac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcp4725_dac

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.

Features

  • Subscribes to dac/command (std_msgs/Float32) to set output voltage
  • Publishes feedback on dac/output (std_msgs/Float32)
  • fake_mode for 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_rate change via ros2 param set

Prerequisites

  • ROS 2 Jazzy
  • Python 3
  • smbus2 (pip install smbus2) — only needed for real hardware

Installation

cd ~/ros2_ws
colcon build --packages-select mcp4725_dac --symlink-install
source install/setup.bash

Usage

Launch (default: fake_mode)

ros2 launch mcp4725_dac mcp4725_launch.py

Direct execution

ros2 run mcp4725_dac mcp4725_node.py --ros-args -p fake_mode:=true

Set output voltage

ros2 topic pub /dac/command std_msgs/msg/Float32 "{data: 1.65}" --once

Read feedback

ros2 topic echo /dac/output

YAML override

mcp4725_dac_node:
  ros__parameters:
    fake_mode: false
    i2c_bus: 1
    device_address: 0x60
    vref: 5.0
    initial_voltage: 2.5

Parameters

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)

Services

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

Package Structure

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

Test Results

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

License

MIT

About

ROS2 Jazzy driver for MCP4725 12-bit single-channel DAC (I2C). Command/feedback topics, EEPROM write, configurable Vref.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors