Okay nice to hear
Sorry to bring this back to basics but what am I doing wrong?
I have my D1 Mini connected to my GY-302 (BH1750)
3V3 --> VCC
GND --> GND
D1 ---> SDA
D2 ---> SCL
My config is
i2c:
sensor:
- platform: bh1750
name: "BH1750 Illuminance"
address: 0x23
measurement_duration: 69
update_interval: 3s
#update_interval: 60s
But I get this error:
[22:51:41][C][bh1750.sensor:027]: BH1750 'BH1750 Illuminance'
[22:51:41][C][bh1750.sensor:027]: Device Class: 'illuminance'
[22:51:41][C][bh1750.sensor:027]: State Class: 'measurement'
[22:51:41][C][bh1750.sensor:027]: Unit of Measurement: 'lx'
[22:51:41][C][bh1750.sensor:027]: Accuracy Decimals: 1
[22:51:41][C][bh1750.sensor:028]: Address: 0x23
[22:51:41][E][bh1750.sensor:030]: Communication with BH1750 failed!
[22:51:41][C][bh1750.sensor:048]: Resolution: 0.5
[22:51:41][C][bh1750.sensor:049]: Update Interval: 3.0s
You have these back-to-front
Should be:
D1 ---> SCL
D2 ---> SDA
Also if you want the full Lux range set:
measurement_duration: 31
It still didn’t work.
I tried a different GY-302/BH1750
Same error.
I also tried with an ESP32-WROOM
SCL --> IO22
SDA --> IO21
Same error.
I must be doing something fundamentally wrong
Any pointers please?
Is the config correct? I use this:
i2c:
sda: D2
scl: D1
scan: True
# Example configuration entry
sensor:
- platform: bh1750
name: "BH1750 Illuminance"
address: 0x23
measurement_duration: 31
update_interval: 5s
You shouldn’t have to, but try connecting the GY-302 Address pin to GND.
Thanks, I tried both of those suggestions, neither helped…
[17:35:28][C][i2c:028]: I2C Bus:
[17:35:28][C][i2c:029]: SDA Pin: GPIO4
[17:35:28][C][i2c:030]: SCL Pin: GPIO5
[17:35:28][C][i2c:031]: Frequency: 50000 Hz
[17:35:28][I][i2c:033]: Scanning i2c bus for active devices...
[17:35:28][I][i2c:049]: Found no i2c devices!
[17:35:28][C][uptime.sensor:030]: Uptime Sensor 'Light Sensor Uptime'
[17:35:28][C][uptime.sensor:030]: State Class: ''
[17:35:28][C][uptime.sensor:030]: Unit of Measurement: 's'
[17:35:28][C][uptime.sensor:030]: Accuracy Decimals: 0
[17:35:28][C][uptime.sensor:030]: Icon: 'mdi:timer-outline'
[17:35:28][C][logger:189]: Logger:
[17:35:28][C][logger:190]: Level: DEBUG
[17:35:28][C][logger:191]: Log Baud Rate: 115200
[17:35:28][C][logger:192]: Hardware UART: UART0
[17:35:28][C][bh1750.sensor:027]: BH1750 'BH1750 Illuminance'
[17:35:28][C][bh1750.sensor:027]: Device Class: 'illuminance'
[17:35:28][C][bh1750.sensor:027]: State Class: 'measurement'
[17:35:28][C][bh1750.sensor:027]: Unit of Measurement: 'lx'
[17:35:28][C][bh1750.sensor:027]: Accuracy Decimals: 1
[17:35:28][C][bh1750.sensor:028]: Address: 0x23
[17:35:28][E][bh1750.sensor:030]: Communication with BH1750 failed!
[17:35:28][C][bh1750.sensor:048]: Resolution: 0.5
[17:35:28][C][bh1750.sensor:049]: Update Interval: 3.0s
Maybe I have something else wrong in the config?
#==================
#=== Substitutions
#==================
substitutions:
device_name: light-sensor
friendly_name: Light Sensor
#==================
# Board
esphome:
name: ${device_name}
platform: ESP8266
board: d1_mini
# WiFi
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: True
ap:
ssid: LightSensor
password: some.secret.password!
# Fallback portal
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
# Enable Over-The-Air updates
ota:
# I2C
i2c:
sda: D2
scl: D1
scan: True
#=== Sensors
sensor:
#=== Uptime
- platform: uptime
name: ${friendly_name} Uptime
#=== WiFi Signal
- platform: wifi_signal
name: ${friendly_name} WiFi Signal
update_interval: 60s
# Illuminance
- platform: bh1750
name: "BH1750 Illuminance"
address: 0x23
measurement_duration: 31
# measurement_duration: 69
update_interval: 3s
# update_interval: 60s
Check the continuity of your DuPont cables. Maybe you have a bad one?
Everything else you have is correct.
Continuity is good.
It’s a mystery…
Try a different i2c clock frequency, 100kHz, 200kHz or 400kHz.
Nope, same error!
Anything else you can think of?
Could I have some dodgy GY-302s?
I bought three off aliexpress at the same time.
Nope. I’m completely out of ideas.
Without an oscilloscope to check the i2c clock and data lines I cant think of anything else you can do.
Ok, thanks anyway for your help.
As you can probably tell that is way above my level
Maybe I’ll some more. Are they generic or if not perhaps someone could tell me exactly what they are using (and where it came from)?
I ordered mine so long ago that the order no longer appears on my Aliexpress account.
In the meantime there is another BH1750 sensor arrived from AliExpress which is also very nice and works great
@tom_l I have a question about the power cable to the board. What is your advice about the correct cable to use? The cable will be from the casing with the board and sensor to the inside of the roller shutter box and will then go to the inside of the house.
- Speaker cable (red/black)
- Signal cable (2 white cables connected to each other with some mark on 1 cable
- 1 cable with inside 2 wires (red/black).
And more important how thick should those 2 wires be? 0.5 mm2 each wire? Or could it be much thinner? I think the total length of this power cable will be 4 meter.
This will be in total connected:
- Wemos D1 Mini
- 1 x BH1750
- Maybe 1x pir (HC-SR501)
- 1 or 2 leds
The BH1750 uses next to no current at all (190uA max) so the cable can be very thin without dropping any voltage over a couple of meters.
A good cable to use would be rated for outdoor use like 2 pair outdoor telephone cable (as long as it is secured against vibration as it has solid conductors). It’s very cheap, e.g. 2 Pair External Telephone Cable per mtr | MJS Electrical Supplies
Okay so you don’t advice me to buy this kind of wires? (It is very thin and don’t have protection on the 2 wires)
And the reason to choose for that telephone cable is that you have also the data cables inside instead of only the power? So you could easy program the board from the inside of the house (when you don’t use ESPHOME but your own c++ sketch).
Can you explain me what the difference is between this signal cable and the telephone cable?
I will cut a standard micro usb cable. So the cable (signal/telephone) will be soldered on those 2 plugs (micro usb and USB-A) and the power will be like this (5v 1A):
I installed one and it worked perfectly!
Here is my code:
i2c:
sda: GPIO4
scl: GPIO5
scan: True
# Example configuration entry
sensor:
- platform: bh1750
name: "BH1750 Illuminance"
address: 0x23
update_interval: 10s
Note D1 is GPIO5 and D2 is GPIO4.
I’m going to also make a version with a transparent front and the BH1750 sensor.
But I was wondering how you have installed the BH1750 sensor in the case? Do you have glue it on the back of the front lid or on a different way?
@tom_l Do you have a picture how you have installed it in the case?
can you show this box in place? I have this box and Pg7 glands which I think are large for this, while you are using GN12 glands.