ROS2 Jazzy driver for the ROHM BH1750FVI digital ambient light sensor over I2C.
- Publishes
sensor_msgs/Illuminanceonbh1750/illuminance fake_modefor testing without hardware (random Gaussian data)- Three measurement modes: high (1 lx), high2 (0.5 lx), low (4 lx)
- 16-bit output, 1–65535 lux range
- Runtime
publish_ratechange viaros2 param set - Calibration and reset services
- ROS 2 Jazzy
- Python 3
- Real hardware only:
smbus2(pip install smbus2)- BH1750FVI breakout board (I2C)
cd ~/ros2_ws
colcon build --packages-select bh1750_light --symlink-install
source install/setup.bashros2 launch bh1750_light bh1750_launch.pyros2 run bh1750_light bh1750_node.pyros2 launch bh1750_light bh1750_launch.py \
params_file:=path/to/your_params.yamlSet fake_mode: false and device_address in your YAML file.
ros2 topic echo /bh1750/illuminance| Parameter | Type | Default | Description |
|---|---|---|---|
fake_mode |
bool | true |
Generate random data without hardware |
i2c_bus |
int | 1 |
I2C bus number (/dev/i2c-N) |
device_address |
int | 0x23 |
I2C address (ADDR=LOW: 0x23, ADDR=HIGH: 0x5C) |
mode |
string | high |
Measurement mode: high (1 lx), high2 (0.5 lx), low (4 lx) |
publish_rate |
float | 5.0 |
Publishing rate in Hz |
frame_id |
string | light_link |
TF frame ID |
| Service | Type | Description |
|---|---|---|
bh1750/calibrate |
std_srvs/srv/Trigger |
Collect samples for 2 s, report averages |
bh1750/reset |
std_srvs/srv/Trigger |
Clear bias, reinitialize sensor |
bh1750_light/
├── CMakeLists.txt
├── package.xml
├── config/
│ └── bh1750_params.yaml
├── launch/
│ └── bh1750_launch.py
├── bh1750_light/
│ ├── __init__.py
│ └── bh1750_driver.py
├── nodes/
│ └── bh1750_node.py
├── test/
│ └── test_bh1750_node.py
├── .gitignore
├── LICENSE
├── CONTRIBUTING.md
└── README.md
Tested on Ubuntu 24.04 (WSL2) with fake_mode: true.
| Test Category | Test | Result |
|---|---|---|
| Topics | bh1750/illuminance publishes sensor_msgs/Illuminance |
PASS |
| Topics | Illuminance non-negative, correct frame_id | PASS |
| Services | bh1750/calibrate returns success=True |
PASS |
| Services | bh1750/reset returns success=True |
PASS |
| Parameters | publish_rate runtime change |
PASS |
| Shutdown | Clean exit | PASS |
| Linting | pep257, flake8, copyright, xmllint | PASS |
MIT