ROS2 Jazzy driver for MCP3008 10-bit 8-channel ADC over SPI (Microchip).
The MCP3008 is one of the most popular ADCs for Raspberry Pi projects. It provides 8 single-ended analog input channels via SPI, making it easy to read analog sensors (potentiometers, thermistors, photoresistors, etc.) with a Raspberry Pi that has no built-in ADC.
- Publishes
std_msgs/Float32per active channel onadc/channel{0-7} fake_modefor testing without hardware (random Gaussian data)- 8 single-ended channels, 10-bit resolution (1024 steps)
- SPI interface (no I2C address conflicts)
- Configurable reference voltage and SPI speed
- Voltage offset calibration via service call
- Runtime
publish_ratechange viaros2 param set
- ROS 2 Jazzy
- Python 3
spidev(pip install spidev) — only needed for real hardware- SPI enabled on Raspberry Pi (
sudo raspi-config)
cd ~/ros2_ws
colcon build --packages-select mcp3008_adc --symlink-install
source install/setup.bashros2 launch mcp3008_adc mcp3008_launch.pyros2 run mcp3008_adc mcp3008_node.py --ros-args -p fake_mode:=trueros2 launch mcp3008_adc mcp3008_launch.py params_file:=my_params.yamlmcp3008_adc_node:
ros__parameters:
fake_mode: false
spi_bus: 0
spi_device: 0
vref: 3.3
active_channels: [0, 1, 2, 3]ros2 topic echo /adc/channel0| Parameter | Type | Default | Description |
|---|---|---|---|
fake_mode |
bool | true |
Use fake driver (no hardware) |
spi_bus |
int | 0 |
SPI bus number (0 or 1) |
spi_device |
int | 0 |
CE pin (0=CE0, 1=CE1) |
spi_speed |
int | 1000000 |
SPI clock speed (Hz) |
vref |
double | 3.3 |
Reference voltage (Volts) |
publish_rate |
double | 10.0 |
Publishing rate (Hz) |
active_channels |
int[] | [0..7] |
Channels to read (0–7) |
| Service | Type | Description |
|---|---|---|
adc/calibrate |
std_srvs/srv/Trigger |
Collect samples for 2s, compute voltage offset bias |
adc/reset |
std_srvs/srv/Trigger |
Clear bias, reinitialise sensor |
mcp3008_adc/
├── CMakeLists.txt
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── .gitignore
├── package.xml
├── config/
│ └── mcp3008_params.yaml
├── launch/
│ └── mcp3008_launch.py
├── nodes/
│ └── mcp3008_node.py
├── mcp3008_adc/
│ ├── __init__.py
│ └── mcp3008_driver.py
└── test/
└── test_mcp3008_node.py
Tested on Ubuntu 24.04 (WSL2) with fake_mode: true.
| Test Category | Test | Result |
|---|---|---|
| Topics | adc/channel{0-7} publishes std_msgs/Float32 |
PASS |
| Services | adc/calibrate returns success=True |
PASS |
| Services | adc/reset returns success=True |
PASS |
| Parameters | publish_rate runtime change |
PASS |
| Shutdown | Clean exit | PASS |
| Linting | pep257, flake8, copyright, xmllint | PASS |
MIT