Skip to content

mingyo186/pcf8591_adc_dac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pcf8591_adc_dac

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.

Features

  • Publishes std_msgs/Float32 per active ADC channel on adc/channel{0-3}
  • Publishes DAC feedback on dac/output (std_msgs/Float32)
  • Subscribes to dac/command (std_msgs/Float32) to set DAC output
  • fake_mode for 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_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 pcf8591_adc_dac --symlink-install
source install/setup.bash

Usage

Launch (default: fake_mode)

ros2 launch pcf8591_adc_dac pcf8591_launch.py

Direct execution

ros2 run pcf8591_adc_dac pcf8591_node.py --ros-args -p fake_mode:=true

Set DAC output

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

Read ADC / DAC

ros2 topic echo /adc/channel0
ros2 topic echo /dac/output

YAML override

pcf8591_node:
  ros__parameters:
    fake_mode: false
    i2c_bus: 1
    device_address: 0x48
    vref: 5.0
    active_channels: [0, 1]

Parameters

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)

Services

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

Package Structure

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

Test Results

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

License

MIT

About

ROS2 Jazzy driver for PCF8591 8-bit 4-channel ADC + 1-channel DAC combo (I2C). ADC read + DAC write in one chip.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors