Browse Source

add BH1750

ir
Hendrik Langer 5 years ago
parent
commit
2a3fc9317d
  1. 25
      README.md
  2. 1
      platformio.ini
  3. 23
      src/main.cpp

25
README.md

@ -36,6 +36,29 @@ SDA | IO21 |
SDO | nc | SPI only
CS | nc | SPI only
### BH1750 (GY-30)
I2C
GY-30 pin | ESP32 pin | Notes
-----------|-----------|----------
GND | |
AD0 | nc |
SDA | IO21 |
SCL | IO22 |
VCC | |
### VEML6075
I2C
GY-30 pin | ESP32 pin | Notes
-----------|-----------|----------
VIN | |
GND | |
SCL | IO22 |
SDA | IO21 |
### SDS011
Serial (HardwareSerial2)
@ -76,3 +99,5 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md
* [GxEPD2](https://github.com/ZinggJM/GxEPD2) - E-Paper display library
* [Adafruit BME680](https://github.com/adafruit/Adafruit_BME680) - BME680 sensor library
* [Nova Fitness SDS dust sensors arduino library](https://github.com/lewapek/sds-dust-sensors-arduino-library.git) - SDS011 Laser dust sensor library
* [BH1750](https://github.com/claws/BH1750/) - BH1750 sensor library
* [VEML6075](https://github.com/adafruit/Adafruit_VEML6075) - VEML6075 sensor library

1
platformio.ini

@ -43,6 +43,7 @@ lib_deps =
Adafruit Unified Sensor
Adafruit BusIO
Adafruit VEML6075 Library
BH1750
; SDS011 sensor Library
; Nova Fitness Sds dust sensors library
https://github.com/lewapek/sds-dust-sensors-arduino-library.git

23
src/main.cpp

@ -24,6 +24,7 @@
#include "Adafruit_BME680.h"
#include "Adafruit_VEML6075.h"
#include <BH1750.h>
#define ARDUINO_SAMD_VARIANT_COMPLIANCE
#include "SdsDustSensor.h"
@ -48,6 +49,7 @@ Adafruit_BME680 bme680; // I2C (also available: hardware SPI
//HardwareSerial Serial2(2);
SdsDustSensor sds(Serial2);
Adafruit_VEML6075 uv = Adafruit_VEML6075();
BH1750 lightMeter;
XD0OTA ota("esp32-weatherstation");
XD0MQTT mqtt;
@ -59,6 +61,7 @@ struct __attribute__((packed)) sensor_readings_t {
uint32_t voc = 0; // Ohm
float pm10 = NAN; // µg/m³
float pm25 = NAN; // µg/m³
float lux = NAN;
float uvi = NAN;
float uva = NAN;
float uvb = NAN;
@ -75,6 +78,7 @@ uint32_t lastDisplayRefresh = 0;
bool bme280_active = false;
bool bme680_active = false;
bool uv_active = false;
bool light_active = false;
bool sds_active = false;
void helloWorld()
@ -161,6 +165,10 @@ void getSensorMeasurements() {
sensor_readings.uvb = uv.readUVB();
}
if (light_active) {
sensor_readings.lux = lightMeter.readLightLevel();
}
if (sds_active) {
PmResult pm = sds.readPm();
if (pm.isOk()) {
@ -325,6 +333,11 @@ void displayValues() {
display.printf("%.1f", pm10);
display.setCursor(200,y_offset+65);
display.printf("%.1f", pm25);
// Lux
//display.setCursor(200,y_offset+80);
//display.println("Lux:");
//display.setCursor(200,y_offset+90);
//display.printf("%.1f", sensor_readings.lux);
// UV
float uvi, uva, uvb;
if (uv_active) {
@ -451,6 +464,12 @@ void sendValues() {
delay(10);
}
if (light_active) {
String topic_lux = String("thomas/sensor/") + ota.getMAC() + String("/lux");
mqtt.publish(topic_lux.c_str(), sensor_readings.lux, "%.2f");
delay(10);
}
if (sds_active) {
String topic_pm10 = String("thomas/sensor/") + ota.getMAC() + String("/pm10");
String topic_pm25 = String("thomas/sensor/") + ota.getMAC() + String("/pm25");
@ -515,6 +534,10 @@ void setup()
Serial.println("Failed to communicate with VEML6075 sensor, check wiring?");
}
if (lightMeter.begin()) {
light_active = true;
}
sds.begin();
FirmwareVersionResult sds_fw = sds.queryFirmwareVersion();

Loading…
Cancel
Save