Skip to content

mingyo186/bh1750_light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BH1750FVI Ambient Light Sensor — ROS2 Jazzy Driver (I2C)

ROS2 Jazzy driver for the ROHM BH1750FVI digital ambient light sensor over I2C.

Features

  • Publishes sensor_msgs/Illuminance on bh1750/illuminance
  • fake_mode for 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_rate change via ros2 param set
  • Calibration and reset services

Prerequisites

  • ROS 2 Jazzy
  • Python 3
  • Real hardware only:
    • smbus2 (pip install smbus2)
    • BH1750FVI breakout board (I2C)

Installation

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

Usage

Launch (fake mode — default)

ros2 launch bh1750_light bh1750_launch.py

Run node directly

ros2 run bh1750_light bh1750_node.py

Real hardware (Raspberry Pi)

ros2 launch bh1750_light bh1750_launch.py \
  params_file:=path/to/your_params.yaml

Set fake_mode: false and device_address in your YAML file.

Verify output

ros2 topic echo /bh1750/illuminance

Parameters

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

Services

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

Package Structure

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

Test Results

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

License

MIT

About

ROS2 Jazzy driver for BH1750FVI ambient light sensor (I2C, lux, high/high2/low modes, fake_mode)

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors