Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python-mqtt-gpio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Alexander Wellbrock
python-mqtt-gpio
Commits
88dd16c4
Commit
88dd16c4
authored
6 years ago
by
shbatm
Committed by
Ellis Percival
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add module for BH1750 light level sensor (#72)
parent
1445844f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+4
-0
4 additions, 0 deletions
.gitignore
README.md
+13
-0
13 additions, 0 deletions
README.md
pi_mqtt_gpio/modules/bh1750.py
+51
-0
51 additions, 0 deletions
pi_mqtt_gpio/modules/bh1750.py
with
68 additions
and
0 deletions
.gitignore
+
4
−
0
View file @
88dd16c4
...
...
@@ -95,3 +95,7 @@ ENV/
#Kate
*.kate-swp
# User's Config File
config.yml
This diff is collapsed.
Click to expand it.
README.md
+
13
−
0
View file @
88dd16c4
...
...
@@ -18,6 +18,7 @@ Sensors
-
LM75 i2c temperature sensor (
`lm75`
)
-
DHT11 DHT22 AM2302 temperature/humidity sensor (
`dht22`
)
-
BH1750 light level sensor (
`bh1750`
)
Installation
------------
...
...
@@ -136,6 +137,18 @@ sensor_inputs:
digits
:
4
# number of digits to be round
type
:
humidity
# Can be temperature or humidity
sensor_modules
:
-
name
:
bh1750
module
:
bh1750
i2c_bus_num
:
1
chip_addr
:
0x23
sensor_inputs
:
-
name
:
bh1750_lux
module
:
bh1750
interval
:
10
digits
:
2
```
#### SSL/TLS
...
...
This diff is collapsed.
Click to expand it.
pi_mqtt_gpio/modules/bh1750.py
0 → 100644
+
51
−
0
View file @
88dd16c4
"""
BH1750 Light Intensity Sensor.
"""
from
pi_mqtt_gpio.modules
import
GenericSensor
CONFIG_SCHEMA
=
{
"
i2c_bus_num
"
:
{
"
type
"
:
"
integer
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
"
chip_addr
"
:
{
"
type
"
:
"
integer
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
}
# Define some constants from the datasheet
DEVICE
=
0x23
# Default device I2C address
POWER_DOWN
=
0x00
# No active state
POWER_ON
=
0x01
# Power on
RESET
=
0x07
# Reset data register value
# Start measurement at 4lx resolution. Time typically 16ms.
CONTINUOUS_LOW_RES_MODE
=
0x13
# Start measurement at 1lx resolution. Time typically 120ms
CONTINUOUS_HIGH_RES_MODE_1
=
0x10
# Start measurement at 0.5lx resolution. Time typically 120ms
CONTINUOUS_HIGH_RES_MODE_2
=
0x11
# Start measurement at 1lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_HIGH_RES_MODE_1
=
0x20
# Start measurement at 0.5lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_HIGH_RES_MODE_2
=
0x21
# Start measurement at 1lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_LOW_RES_MODE
=
0x23
class
Sensor
(
GenericSensor
):
"""
Implementation of Sensor class for the BH1750 light sensor.
"""
def
__init__
(
self
,
config
):
"""
Initialize sensor class.
"""
import
smbus
self
.
bus
=
smbus
.
SMBus
(
config
[
"
i2c_bus_num
"
])
self
.
address
=
config
[
"
chip_addr
"
]
def
setup_sensor
(
self
,
config
):
"""
Perform setup for the sensor.
"""
return
True
# nothing to do here
def
get_value
(
self
,
config
):
"""
Get the light value from the sensor.
"""
value
=
self
.
bus
.
read_i2c_block_data
(
self
.
address
,
ONE_TIME_HIGH_RES_MODE_1
)
value
=
(
value
[
1
]
+
(
256
*
value
[
0
]))
/
1.2
return
value
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment