Additional I2C improvements (#547)
* Add support for BMP280/BMP085/180 * Fixes I2C pin defaults for M5Stick and M5Atom
This commit is contained in:
parent
83d0250eb0
commit
508ae3e716
|
@ -74,6 +74,8 @@ lib_deps =
|
||||||
beegee-tokyo/DHT sensor library for ESPx @ ^1.18
|
beegee-tokyo/DHT sensor library for ESPx @ ^1.18
|
||||||
starmbi/hp_BH1750 @ ^1.0.0
|
starmbi/hp_BH1750 @ ^1.0.0
|
||||||
adafruit/Adafruit BME280 Library@^2.2.2
|
adafruit/Adafruit BME280 Library@^2.2.2
|
||||||
|
adafruit/Adafruit BMP085 Library@^1.2.1
|
||||||
|
adafruit/Adafruit BMP280 Library@^2.6.3
|
||||||
adafruit/Adafruit TSL2561@^1.1.0
|
adafruit/Adafruit TSL2561@^1.1.0
|
||||||
|
|
||||||
[env:esp32]
|
[env:esp32]
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace BH1750
|
||||||
|
|
||||||
void Setup()
|
void Setup()
|
||||||
{
|
{
|
||||||
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
if (BH1750_I2c != "0x23" && BH1750_I2c != "0x5C") return;
|
if (BH1750_I2c != "0x23" && BH1750_I2c != "0x5C") return;
|
||||||
|
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -83,13 +83,15 @@ namespace BH1750
|
||||||
|
|
||||||
void SerialReport()
|
void SerialReport()
|
||||||
{
|
{
|
||||||
Serial.print("BH1750_I2c Sensor: ");
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (BH1750_I2c.isEmpty()) return;
|
||||||
|
Serial.print("BH1750: ");
|
||||||
Serial.println(BH1750_I2c + " on bus " + BH1750_I2c_Bus);
|
Serial.println(BH1750_I2c + " on bus " + BH1750_I2c_Bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loop()
|
void Loop()
|
||||||
{
|
{
|
||||||
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
if (!initialized) return;
|
if (!initialized) return;
|
||||||
|
|
||||||
if (BH1750_I2c == "0x23" || BH1750_I2c == "0x5C")
|
if (BH1750_I2c == "0x23" || BH1750_I2c == "0x5C")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifdef SENSORS
|
#ifdef SENSORS
|
||||||
#include "BME280Sensor.h"
|
#include "BME280.h"
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
|
@ -21,7 +21,7 @@ namespace BME280
|
||||||
|
|
||||||
void Setup()
|
void Setup()
|
||||||
{
|
{
|
||||||
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
|
||||||
if (BME280_I2c == "0x76" && BME280_I2c_Bus == 1) {
|
if (BME280_I2c == "0x76" && BME280_I2c_Bus == 1) {
|
||||||
BME280_status = BME280.begin(0x76, &Wire);
|
BME280_status = BME280.begin(0x76, &Wire);
|
||||||
|
@ -59,13 +59,15 @@ namespace BME280
|
||||||
|
|
||||||
void SerialReport()
|
void SerialReport()
|
||||||
{
|
{
|
||||||
Serial.print("BME280_I2c Sensor: ");
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (BME280_I2c.isEmpty()) return;
|
||||||
|
Serial.print("BME280: ");
|
||||||
Serial.println(BME280_I2c + " on bus " + BME280_I2c_Bus);
|
Serial.println(BME280_I2c + " on bus " + BME280_I2c_Bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loop()
|
void Loop()
|
||||||
{
|
{
|
||||||
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
if (!initialized) return;
|
if (!initialized) return;
|
||||||
|
|
||||||
if (millis() - bme280PreviousMillis >= sensorInterval) {
|
if (millis() - bme280PreviousMillis >= sensorInterval) {
|
|
@ -0,0 +1,81 @@
|
||||||
|
#ifdef SENSORS
|
||||||
|
#include "BMP180.h"
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
#include "defaults.h"
|
||||||
|
#include <AsyncWiFiSettings.h>
|
||||||
|
#include "string_utils.h"
|
||||||
|
|
||||||
|
#include <Adafruit_BMP085.h>
|
||||||
|
|
||||||
|
namespace BMP180
|
||||||
|
{
|
||||||
|
Adafruit_BMP085* bmp;
|
||||||
|
long BMP180_status;
|
||||||
|
String BMP180_I2c;
|
||||||
|
int BMP180_I2c_Bus;
|
||||||
|
unsigned long BMP180PreviousMillis = 0;
|
||||||
|
int sensorInterval = 60000;
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
|
void Setup()
|
||||||
|
{
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
|
||||||
|
bmp = new Adafruit_BMP085();
|
||||||
|
if (BMP180_I2c == "0x77") {
|
||||||
|
BMP180_status = bmp->begin(BMP085_STANDARD, BMP180_I2c_Bus == 1 ? &Wire : &Wire1);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BMP180_status) {
|
||||||
|
Serial.println("[BMP180] Couldn't find a sensor, check your wiring and I2C address!");
|
||||||
|
} else {
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectToWifi()
|
||||||
|
{
|
||||||
|
AsyncWiFiSettings.html("h4", "BMP085/BMP180 Barometric Pressure + Temp sensor");
|
||||||
|
BMP180_I2c_Bus = AsyncWiFiSettings.integer("BMP180_I2c_Bus", 1, 2, DEFAULT_I2C_BUS, "I2C Bus");
|
||||||
|
BMP180_I2c = AsyncWiFiSettings.string("BMP180_I2c", "", "I2C address (0x77)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialReport()
|
||||||
|
{
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (BMP180_I2c.isEmpty()) return;
|
||||||
|
Serial.print("BMP180_I2c Sensor: ");
|
||||||
|
Serial.println(BMP180_I2c + " on bus " + BMP180_I2c_Bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Loop()
|
||||||
|
{
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (!initialized) return;
|
||||||
|
|
||||||
|
if (BMP180PreviousMillis == 0 || millis() - BMP180PreviousMillis >= sensorInterval) {
|
||||||
|
|
||||||
|
float temperature = bmp->readTemperature();
|
||||||
|
float pressure = bmp->readPressure() / 100.0F;
|
||||||
|
|
||||||
|
mqttClient.publish((roomsTopic + "/bmp180_temperature").c_str(), 0, 1, String(temperature).c_str());
|
||||||
|
mqttClient.publish((roomsTopic + "/bmp180_pressure").c_str(), 0, 1, String(pressure).c_str());
|
||||||
|
|
||||||
|
BMP180PreviousMillis = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SendDiscovery()
|
||||||
|
{
|
||||||
|
if (BMP180_I2c.isEmpty()) return true;
|
||||||
|
|
||||||
|
return sendSensorDiscovery("BMP180 Temperature", EC_NONE, "temperature", "°C")
|
||||||
|
&& sendSensorDiscovery("BMP180 Pressure", EC_NONE, "pressure", "hPa");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
#ifdef SENSORS
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
namespace BMP180
|
||||||
|
{
|
||||||
|
void ConnectToWifi();
|
||||||
|
void SerialReport();
|
||||||
|
bool SendDiscovery();
|
||||||
|
void Setup();
|
||||||
|
void Loop();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,91 @@
|
||||||
|
#ifdef SENSORS
|
||||||
|
#include "BMP280.h"
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
#include "mqtt.h"
|
||||||
|
#include "defaults.h"
|
||||||
|
#include <AsyncWiFiSettings.h>
|
||||||
|
#include "string_utils.h"
|
||||||
|
|
||||||
|
#include <Adafruit_BMP280.h>
|
||||||
|
|
||||||
|
namespace BMP280
|
||||||
|
{
|
||||||
|
Adafruit_BMP280* bmp;
|
||||||
|
long BMP280_status;
|
||||||
|
String BMP280_I2c;
|
||||||
|
int BMP280_I2c_Bus;
|
||||||
|
unsigned long BMP280PreviousMillis = 0;
|
||||||
|
int sensorInterval = 60000;
|
||||||
|
bool initialized = false;
|
||||||
|
|
||||||
|
void Setup()
|
||||||
|
{
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
|
||||||
|
bmp = new Adafruit_BMP280(BMP280_I2c_Bus == 1 ? &Wire : &Wire1);
|
||||||
|
if (BMP280_I2c == "0x76") {
|
||||||
|
BMP280_status = bmp->begin(0x76);
|
||||||
|
} else if (BMP280_I2c == "0x77") {
|
||||||
|
BMP280_status = bmp->begin(0x77);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BMP280_status) {
|
||||||
|
Serial.println("[BMP280] Couldn't find a sensor, check your wiring and I2C address!");
|
||||||
|
} else {
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bmp->setSampling(
|
||||||
|
Adafruit_BMP280::MODE_FORCED,
|
||||||
|
Adafruit_BMP280::SAMPLING_X1, // Temperature
|
||||||
|
Adafruit_BMP280::SAMPLING_X1, // Pressure
|
||||||
|
Adafruit_BMP280::FILTER_OFF
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectToWifi()
|
||||||
|
{
|
||||||
|
AsyncWiFiSettings.html("h4", "BMP280 - Weather Sensor:");
|
||||||
|
BMP280_I2c_Bus = AsyncWiFiSettings.integer("BMP280_I2c_Bus", 1, 2, DEFAULT_I2C_BUS, "I2C Bus");
|
||||||
|
BMP280_I2c = AsyncWiFiSettings.string("BMP280_I2c", "", "I2C address (0x76 or 0x77)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialReport()
|
||||||
|
{
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (BMP280_I2c.isEmpty()) return;
|
||||||
|
Serial.print("BMP280_I2c Sensor: ");
|
||||||
|
Serial.println(BMP280_I2c + " on bus " + BMP280_I2c_Bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Loop()
|
||||||
|
{
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (!initialized) return;
|
||||||
|
|
||||||
|
if (BMP280PreviousMillis == 0 || millis() - BMP280PreviousMillis >= sensorInterval) {
|
||||||
|
|
||||||
|
bmp->takeForcedMeasurement();
|
||||||
|
float temperature = bmp->readTemperature();
|
||||||
|
float pressure = bmp->readPressure() / 100.0F;
|
||||||
|
|
||||||
|
mqttClient.publish((roomsTopic + "/bmp280_temperature").c_str(), 0, 1, String(temperature).c_str());
|
||||||
|
mqttClient.publish((roomsTopic + "/bmp280_pressure").c_str(), 0, 1, String(pressure).c_str());
|
||||||
|
|
||||||
|
BMP280PreviousMillis = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SendDiscovery()
|
||||||
|
{
|
||||||
|
if (BMP280_I2c.isEmpty()) return true;
|
||||||
|
|
||||||
|
return sendSensorDiscovery("BMP280 Temperature", EC_NONE, "temperature", "°C")
|
||||||
|
&& sendSensorDiscovery("BMP280 Pressure", EC_NONE, "pressure", "hPa");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
#ifdef SENSORS
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
namespace BMP280
|
||||||
|
{
|
||||||
|
void ConnectToWifi();
|
||||||
|
void SerialReport();
|
||||||
|
bool SendDiscovery();
|
||||||
|
void Setup();
|
||||||
|
void Loop();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -114,11 +114,12 @@ namespace DHT
|
||||||
|
|
||||||
void SerialReport()
|
void SerialReport()
|
||||||
{
|
{
|
||||||
|
if (!dht11Pin && !dht22Pin) return;
|
||||||
Serial.print("DHT11 Sensor: ");
|
Serial.print("DHT11 Sensor: ");
|
||||||
Serial.println(dht11Pin ? "enabled" : "disabled");
|
Serial.println(dht11Pin ? "enabled" : "disabled");
|
||||||
Serial.print("DHT22 Sensor: ");
|
Serial.print("DHT22 Sensor: ");
|
||||||
Serial.println(dht22Pin ? "enabled" : "disabled");
|
Serial.println(dht22Pin ? "enabled" : "disabled");
|
||||||
Serial.print("DHT Temp Offset: ");
|
Serial.print("DHT Offset: ");
|
||||||
Serial.println(dhtTempOffset ? "enabled" : "disabled");
|
Serial.println(dhtTempOffset ? "enabled" : "disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
217
src/I2C.cpp
217
src/I2C.cpp
|
@ -2,137 +2,120 @@
|
||||||
|
|
||||||
#include "I2C.h"
|
#include "I2C.h"
|
||||||
|
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
|
#include <AsyncWiFiSettings.h>
|
||||||
|
|
||||||
|
#include "defaults.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
#include "defaults.h"
|
|
||||||
#include <AsyncWiFiSettings.h>
|
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
#include <Adafruit_BME280.h>
|
namespace I2C {
|
||||||
|
bool I2CDebug = false;
|
||||||
|
int I2C_Bus_1_SDA;
|
||||||
|
int I2C_Bus_1_SCL;
|
||||||
|
int I2C_Bus_2_SDA;
|
||||||
|
int I2C_Bus_2_SCL;
|
||||||
|
|
||||||
namespace I2C
|
void ConnectToWifi() {
|
||||||
{
|
AsyncWiFiSettings.heading("I2C Settings <a href='https://espresense.com/configuration/settings#i2c-settings' target='_blank'>ℹ️</a>", false);
|
||||||
bool I2CDebug = false;
|
|
||||||
|
|
||||||
void ConnectToWifi()
|
AsyncWiFiSettings.html("h4", "Bus 1:");
|
||||||
{
|
|
||||||
AsyncWiFiSettings.heading("I2C Settings <a href='https://espresense.com/configuration/settings#i2c-settings' target='_blank'>ℹ️</a>", false);
|
|
||||||
|
|
||||||
AsyncWiFiSettings.html("h4", "Bus 1:");
|
I2C_Bus_1_SDA = AsyncWiFiSettings.integer("I2C_Bus_1_SDA", -1, 39, DEFAULT_I2C_BUS_1_SDA, "SDA pin (-1 to disable)");
|
||||||
|
I2C_Bus_1_SCL = AsyncWiFiSettings.integer("I2C_Bus_1_SCL", -1, 39, DEFAULT_I2C_BUS_1_SCL, "SCL pin (-1 to disable)");
|
||||||
|
|
||||||
I2C_Bus_1_SDA = AsyncWiFiSettings.integer("I2C_Bus_1_SDA", 0, 39, DEFAULT_I2C_BUS_1_SDA, "SDA pin (-1 to disable)");
|
AsyncWiFiSettings.html("h4", "Bus 2:");
|
||||||
I2C_Bus_1_SCL = AsyncWiFiSettings.integer("I2C_Bus_1_SCL", 0, 39, DEFAULT_I2C_BUS_1_SCL, "SCL pin (-1 to disable)");
|
|
||||||
|
|
||||||
AsyncWiFiSettings.html("h4", "Bus 2:");
|
I2C_Bus_2_SDA = AsyncWiFiSettings.integer("I2C_Bus_2_SDA", -1, 39, DEFAULT_I2C_BUS_2_SDA, "SDA pin (-1 to disable)");
|
||||||
|
I2C_Bus_2_SCL = AsyncWiFiSettings.integer("I2C_Bus_2_SCL", -1, 39, DEFAULT_I2C_BUS_2_SCL, "SCL pin (-1 to disable)");
|
||||||
|
|
||||||
I2C_Bus_2_SDA = AsyncWiFiSettings.integer("I2C_Bus_2_SDA", -1, "SDA pin (-1 to disable)");
|
I2CDebug = AsyncWiFiSettings.checkbox("I2CDebug", false, "Debug I2C addreses. Look at the serial log to get the correct address");
|
||||||
I2C_Bus_2_SCL = AsyncWiFiSettings.integer("I2C_Bus_2_SCL", -1, "SCL pin (-1 to disable)");
|
|
||||||
|
|
||||||
I2CDebug = AsyncWiFiSettings.checkbox("I2CDebug", false, "Debug I2C addreses. Look at the serial log to get the correct address");
|
if (I2C_Bus_1_SDA != -1 && I2C_Bus_1_SDA != -1) {
|
||||||
|
I2C_Bus_1_Started = Wire.begin(I2C_Bus_1_SDA, I2C_Bus_1_SCL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialReport()
|
if (I2C_Bus_2_SDA != -1 && I2C_Bus_2_SDA != -1) {
|
||||||
{
|
I2C_Bus_2_Started = Wire1.begin(I2C_Bus_2_SDA, I2C_Bus_2_SCL);
|
||||||
}
|
|
||||||
|
|
||||||
void Setup()
|
|
||||||
{
|
|
||||||
if (I2C_Bus_1_SDA != -1 && I2C_Bus_1_SDA != -1) {
|
|
||||||
Wire.begin(I2C_Bus_1_SDA, I2C_Bus_1_SCL);
|
|
||||||
I2C_Bus_1_Enabled = true;
|
|
||||||
Serial.println("Initialized I2C Bus 1 (SDA: " + String(I2C_Bus_1_SDA) + ", SCL: " + String(I2C_Bus_1_SCL) + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (I2C_Bus_2_SDA != -1 && I2C_Bus_2_SDA != -1) {
|
|
||||||
Wire1.begin(I2C_Bus_2_SDA, I2C_Bus_2_SCL);
|
|
||||||
I2C_Bus_2_Enabled = true;
|
|
||||||
Serial.println("Initialized I2C Bus 2 (SDA: " + String(I2C_Bus_2_SDA) + ", SCL: " + String(I2C_Bus_2_SCL) + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Loop()
|
|
||||||
{
|
|
||||||
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
|
|
||||||
if (!I2CDebug) return;
|
|
||||||
I2CDebug = false;
|
|
||||||
|
|
||||||
byte error, address;
|
|
||||||
int nDevices;
|
|
||||||
nDevices = 0;
|
|
||||||
|
|
||||||
if (I2C_Bus_1_Enabled)
|
|
||||||
{
|
|
||||||
Serial.println("Scanning I2C for devices on Bus 1...");
|
|
||||||
for (address = 1; address < 127; address++)
|
|
||||||
{
|
|
||||||
Wire.beginTransmission(address);
|
|
||||||
error = Wire.endTransmission();
|
|
||||||
if (error == 0)
|
|
||||||
{
|
|
||||||
Serial.print("I2C device found on bus 1 at address 0x");
|
|
||||||
|
|
||||||
if (address < 16)
|
|
||||||
{
|
|
||||||
Serial.print("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(address, HEX);
|
|
||||||
nDevices++;
|
|
||||||
}
|
|
||||||
else if (error == 4)
|
|
||||||
{
|
|
||||||
Serial.print("Unknown error on bus 1 at address 0x");
|
|
||||||
if (address < 16)
|
|
||||||
{
|
|
||||||
Serial.print("0");
|
|
||||||
}
|
|
||||||
Serial.println(address, HEX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (I2C_Bus_2_Enabled)
|
|
||||||
{
|
|
||||||
Serial.println("Scanning I2C for devices on Bus 2...");
|
|
||||||
|
|
||||||
for (address = 1; address < 127; address++)
|
|
||||||
{
|
|
||||||
Wire1.beginTransmission(address);
|
|
||||||
error = Wire1.endTransmission();
|
|
||||||
if (error == 0)
|
|
||||||
{
|
|
||||||
Serial.print("I2C device found on bus 2 at address 0x");
|
|
||||||
|
|
||||||
if (address < 16)
|
|
||||||
{
|
|
||||||
Serial.print("0");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println(address, HEX);
|
|
||||||
nDevices++;
|
|
||||||
}
|
|
||||||
else if (error == 4)
|
|
||||||
{
|
|
||||||
Serial.print("Unknown error on bus 2 at address 0x");
|
|
||||||
if (address < 16)
|
|
||||||
{
|
|
||||||
Serial.print("0");
|
|
||||||
}
|
|
||||||
Serial.println(address, HEX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nDevices == 0)
|
|
||||||
{
|
|
||||||
Serial.println("No I2C devices found\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SendDiscovery()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Loop() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Setup() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialReport() {
|
||||||
|
if (I2C_Bus_1_Started)
|
||||||
|
Serial.println(String("I2C Bus 1: sda=") + I2C_Bus_1_SDA + " scl=" + I2C_Bus_1_SCL);
|
||||||
|
if (I2C_Bus_2_Started)
|
||||||
|
Serial.println(String("I2C Bus 2: sda=") + I2C_Bus_2_SDA + " scl=" + I2C_Bus_2_SCL);
|
||||||
|
|
||||||
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (!I2CDebug) return;
|
||||||
|
byte error, address;
|
||||||
|
int nDevices;
|
||||||
|
nDevices = 0;
|
||||||
|
|
||||||
|
if (I2C_Bus_1_Started) {
|
||||||
|
Serial.println("Scanning I2C for devices on Bus 1...");
|
||||||
|
for (address = 1; address < 127; address++) {
|
||||||
|
Wire.beginTransmission(address);
|
||||||
|
error = Wire.endTransmission();
|
||||||
|
if (error == 0) {
|
||||||
|
Serial.print("I2C device found on bus 1 at address 0x");
|
||||||
|
|
||||||
|
if (address < 16) {
|
||||||
|
Serial.print("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
nDevices++;
|
||||||
|
} else if (error == 4) {
|
||||||
|
Serial.print("Unknown error on bus 1 at address 0x");
|
||||||
|
if (address < 16) {
|
||||||
|
Serial.print("0");
|
||||||
|
}
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (I2C_Bus_2_Started) {
|
||||||
|
Serial.println("Scanning I2C for devices on Bus 2...");
|
||||||
|
|
||||||
|
for (address = 1; address < 127; address++) {
|
||||||
|
Wire1.beginTransmission(address);
|
||||||
|
error = Wire1.endTransmission();
|
||||||
|
if (error == 0) {
|
||||||
|
Serial.print("I2C device found on bus 2 at address 0x");
|
||||||
|
|
||||||
|
if (address < 16) {
|
||||||
|
Serial.print("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
nDevices++;
|
||||||
|
} else if (error == 4) {
|
||||||
|
Serial.print("Unknown error on bus 2 at address 0x");
|
||||||
|
if (address < 16) {
|
||||||
|
Serial.print("0");
|
||||||
|
}
|
||||||
|
Serial.println(address, HEX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nDevices == 0) {
|
||||||
|
Serial.println("No I2C devices found\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SendDiscovery() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // namespace I2C
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "defaults.h"
|
#include "defaults.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
#include "TSL2561Sensor.h"
|
#include "TSL2561.h"
|
||||||
#include <AsyncWiFiSettings.h>
|
#include <AsyncWiFiSettings.h>
|
||||||
#include <AsyncMqttClient.h>
|
#include <AsyncMqttClient.h>
|
||||||
#include <Adafruit_TSL2561_U.h>
|
#include <Adafruit_TSL2561_U.h>
|
||||||
|
@ -31,15 +31,16 @@ namespace TSL2561
|
||||||
|
|
||||||
void SerialReport()
|
void SerialReport()
|
||||||
{
|
{
|
||||||
Serial.print("TSL2561_I2c Sensor: ");
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
if (TSL2561_I2c.isEmpty()) return;
|
||||||
|
Serial.print("TSL2561: ");
|
||||||
Serial.println(TSL2561_I2c + " on bus " + TSL2561_I2c_Bus);
|
Serial.println(TSL2561_I2c + " on bus " + TSL2561_I2c_Bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loop()
|
void Loop()
|
||||||
{
|
{
|
||||||
if (!I2C_Bus_1_Enabled && !I2C_Bus_2_Enabled) return;
|
if (!I2C_Bus_1_Started && !I2C_Bus_2_Started) return;
|
||||||
|
|
||||||
// TODO: This should move to setup
|
|
||||||
int tsl2561_address;
|
int tsl2561_address;
|
||||||
|
|
||||||
if (TSL2561_I2c == "0x39") {
|
if (TSL2561_I2c == "0x39") {
|
|
@ -49,9 +49,27 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// I2C Defaults
|
// I2C Defaults
|
||||||
|
#ifdef M5STICK
|
||||||
|
#define DEFAULT_I2C_BUS_1_SDA 32
|
||||||
|
#define DEFAULT_I2C_BUS_1_SCL 33
|
||||||
|
#define DEFAULT_I2C_BUS_2_SDA 21
|
||||||
|
#define DEFAULT_I2C_BUS_2_SCL 22
|
||||||
|
#define DEFAULT_I2C_BUS 1
|
||||||
|
#else
|
||||||
|
#ifdef M5ATOM
|
||||||
|
#define DEFAULT_I2C_BUS_1_SDA 26
|
||||||
|
#define DEFAULT_I2C_BUS_1_SCL 32
|
||||||
|
#define DEFAULT_I2C_BUS_2_SDA 25
|
||||||
|
#define DEFAULT_I2C_BUS_2_SCL 21
|
||||||
|
#define DEFAULT_I2C_BUS 1
|
||||||
|
#else
|
||||||
#define DEFAULT_I2C_BUS_1_SDA 21
|
#define DEFAULT_I2C_BUS_1_SDA 21
|
||||||
#define DEFAULT_I2C_BUS_1_SCL 22
|
#define DEFAULT_I2C_BUS_1_SCL 22
|
||||||
|
#define DEFAULT_I2C_BUS_2_SDA -1
|
||||||
|
#define DEFAULT_I2C_BUS_2_SCL -1
|
||||||
#define DEFAULT_I2C_BUS 1
|
#define DEFAULT_I2C_BUS 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// TSL2561 Defaults
|
// TSL2561 Defaults
|
||||||
#define DEFAULT_TSL2561_I2C_GAIN "auto"
|
#define DEFAULT_TSL2561_I2C_GAIN "auto"
|
||||||
|
|
|
@ -38,9 +38,5 @@ _DECL bool enrolling;
|
||||||
_DECL unsigned long enrollingEndMillis;
|
_DECL unsigned long enrollingEndMillis;
|
||||||
|
|
||||||
// I2C
|
// I2C
|
||||||
_DECL int I2C_Bus_1_SDA;
|
_DECL bool I2C_Bus_1_Started;
|
||||||
_DECL int I2C_Bus_1_SCL;
|
_DECL bool I2C_Bus_2_Started;
|
||||||
_DECL int I2C_Bus_2_SDA;
|
|
||||||
_DECL int I2C_Bus_2_SCL;
|
|
||||||
_DECL bool I2C_Bus_1_Enabled;
|
|
||||||
_DECL bool I2C_Bus_2_Enabled;
|
|
||||||
|
|
10
src/main.cpp
10
src/main.cpp
|
@ -54,6 +54,8 @@ bool sendTelemetry(int totalSeen, int totalFpSeen, int totalFpQueried, int total
|
||||||
&& DHT::SendDiscovery()
|
&& DHT::SendDiscovery()
|
||||||
&& BH1750::SendDiscovery()
|
&& BH1750::SendDiscovery()
|
||||||
&& BME280::SendDiscovery()
|
&& BME280::SendDiscovery()
|
||||||
|
&& BMP180::SendDiscovery()
|
||||||
|
&& BMP280::SendDiscovery()
|
||||||
&& TSL2561::SendDiscovery()
|
&& TSL2561::SendDiscovery()
|
||||||
&& HX711::SendDiscovery()
|
&& HX711::SendDiscovery()
|
||||||
#endif
|
#endif
|
||||||
|
@ -223,6 +225,8 @@ void setupNetwork()
|
||||||
|
|
||||||
BH1750::ConnectToWifi();
|
BH1750::ConnectToWifi();
|
||||||
BME280::ConnectToWifi();
|
BME280::ConnectToWifi();
|
||||||
|
BMP180::ConnectToWifi();
|
||||||
|
BMP280::ConnectToWifi();
|
||||||
TSL2561::ConnectToWifi();
|
TSL2561::ConnectToWifi();
|
||||||
HX711::ConnectToWifi();
|
HX711::ConnectToWifi();
|
||||||
#endif
|
#endif
|
||||||
|
@ -259,6 +263,8 @@ void setupNetwork()
|
||||||
DHT::SerialReport();
|
DHT::SerialReport();
|
||||||
BH1750::SerialReport();
|
BH1750::SerialReport();
|
||||||
BME280::SerialReport();
|
BME280::SerialReport();
|
||||||
|
BMP180::SerialReport();
|
||||||
|
BMP280::SerialReport();
|
||||||
TSL2561::SerialReport();
|
TSL2561::SerialReport();
|
||||||
HX711::SerialReport();
|
HX711::SerialReport();
|
||||||
#endif
|
#endif
|
||||||
|
@ -576,6 +582,8 @@ void setup()
|
||||||
I2C::Setup();
|
I2C::Setup();
|
||||||
BH1750::Setup();
|
BH1750::Setup();
|
||||||
BME280::Setup();
|
BME280::Setup();
|
||||||
|
BMP180::Setup();
|
||||||
|
BMP280::Setup();
|
||||||
TSL2561::Setup();
|
TSL2561::Setup();
|
||||||
HX711::Setup();
|
HX711::Setup();
|
||||||
#endif
|
#endif
|
||||||
|
@ -597,6 +605,8 @@ void loop()
|
||||||
DHT::Loop();
|
DHT::Loop();
|
||||||
BH1750::Loop();
|
BH1750::Loop();
|
||||||
BME280::Loop();
|
BME280::Loop();
|
||||||
|
BMP180::Loop();
|
||||||
|
BMP280::Loop();
|
||||||
TSL2561::Loop();
|
TSL2561::Loop();
|
||||||
HX711::Loop();
|
HX711::Loop();
|
||||||
I2C::Loop();
|
I2C::Loop();
|
||||||
|
|
|
@ -31,8 +31,10 @@
|
||||||
#ifdef SENSORS
|
#ifdef SENSORS
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
#include "BME280Sensor.h"
|
#include "BME280.h"
|
||||||
#include "TSL2561Sensor.h"
|
#include "BMP180.h"
|
||||||
|
#include "BMP280.h"
|
||||||
|
#include "TSL2561.h"
|
||||||
#include "HX711.h"
|
#include "HX711.h"
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
#include "BH1750.h"
|
#include "BH1750.h"
|
||||||
|
|
Loading…
Reference in New Issue