From 0a2c56cd7bed1c7aa0151946a8764228e8caaf01 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 10 Dec 2024 15:20:06 +0100 Subject: [PATCH] firmware - v0.1.1, offer different I2C addresses for BME280, SHT31. its done quick and dirty and some Typos got fixed --- Arduino/CanGrow/CanGrow.ino | 36 ++++++++++++----- Arduino/CanGrow/CanGrow_Sensors.h | 52 +++++++++++++++--------- Arduino/CanGrow/CanGrow_SysFunctions.h | 2 +- Arduino/CanGrow/CanGrow_WebFunctions.h | 56 +++++++++++++++++++------- cangrow.sh | 2 +- 5 files changed, 102 insertions(+), 46 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 95e2a32..3465730 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -6,10 +6,10 @@ // set CANGROW_VER and CANGROW_BUILD if not already done as Compiler Flag #ifndef CANGROW_VER - #define CANGROW_VER "v0.1.0-dev" + #define CANGROW_VER "v0.1.1-dev" #endif #ifndef CANGROW_BUILD - #define CANGROW_BUILD "1a2b3c4f" + #define CANGROW_BUILD "1a2b3c4f-001" #endif /* @@ -136,25 +136,39 @@ void setup() { // dht.begin(); //TODO: Do only, when configured // initialise BME280 - Serial.println(":: initialise BME280 sensor ::"); + // dirty way of supporting multiple addresses, DRY? :p + Serial.println(":: initialise BME280 sensor, address 0x76 ::"); // ToDo: let the user configure somewhere the ID of the BME280 sensor - if(!bme.begin(0x76)) { - Serial.println("!! Cannot find BME280 on I2C bus. Please check connection or ID"); + if(!bme_0x76.begin(0x76)) { + Serial.println("!! Cannot find BME280 on I2C bus at address 0x76. Please check connection or ID"); + } + Serial.println(":: initialise BME280 sensor, address 0x77 ::"); + // ToDo: let the user configure somewhere the ID of the BME280 sensor + if(!bme_0x77.begin(0x77)) { + Serial.println("!! Cannot find BME280 on I2C bus at address 0x77. Please check connection or ID"); } // initialise SHT31 - Serial.println(":: initialise SHT31 sensor ::"); - if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr - Serial.println("Couldn't find SHT31"); + Serial.println(":: initialise SHT31 sensor, address 0x44 ::"); + if (! sht31_0x44.begin(0x44)) { // Set to 0x45 for alternate i2c addr + Serial.println("!! Cannot find SHT31 on I2C bus at address 0x45. Please check connection or ID"); + } + Serial.println(":: initialise SHT31 sensor, address 0x45 ::"); + if (! sht31_0x45.begin(0x45)) { // Set to 0x45 for alternate i2c addr + Serial.println("!! Cannot find SHT31 on I2C bus at address 0x45. Please check connection or ID"); } - Serial.print("SHT31 Heater Enabled State: "); - if (sht31.isHeaterEnabled()) + Serial.print(":: SHT31 (0x44) heater enable state ::"); + if (sht31_0x44.isHeaterEnabled()) Serial.println("ENABLED"); else Serial.println("DISABLED"); - + Serial.print(":: SHT31 (0x45) heater enable state ::"); + if (sht31_0x45.isHeaterEnabled()) + Serial.println("ENABLED"); + else + Serial.println("DISABLED"); diff --git a/Arduino/CanGrow/CanGrow_Sensors.h b/Arduino/CanGrow/CanGrow_Sensors.h index 05d3034..0b5e001 100644 --- a/Arduino/CanGrow/CanGrow_Sensors.h +++ b/Arduino/CanGrow/CanGrow_Sensors.h @@ -12,16 +12,17 @@ */ #define SEALEVELPRESSURE_HPA (1013.25) -Adafruit_BME280 bme; +// dirty way of having multiple addresses configurable +Adafruit_BME280 bme_0x76; +Adafruit_BME280 bme_0x77; /* * SHT30/31 Stuff * */ - bool enableHeater = false; - Adafruit_SHT31 sht31 = Adafruit_SHT31(); - +Adafruit_SHT31 sht31_0x44 = Adafruit_SHT31(); +Adafruit_SHT31 sht31_0x45 = Adafruit_SHT31(); /* * Chirp functions @@ -103,9 +104,11 @@ float getTemperature(byte tempSensor) { /* * tempSensor * ========== - * 1 : DHT11 temp sensor - * 2 : chirp I2C temp sensor - * 3 : SHT31 + * 1 : BME280 0x76 temp sensor + * 2 : BME280 0x77 temp sensor + * 3 : SHT31 0x44 temp sensor + * 4 : SHT31 0x45 temp sensor + * 5 : Chirp I2C 0x20 temp sensor */ float temperature = 0; @@ -113,18 +116,23 @@ float getTemperature(byte tempSensor) { switch(tempSensor) { case 1: // read temperature from BME280 - temperature = bme.readTemperature(); - // read temperature from DHT11 - // dht support dropped - // temperature = dht.readTemperature(); + temperature = bme_0x76.readTemperature(); break; case 2: - // read temperature from chrip I2C - temperature = readI2CRegister16bit(0x20, 5) * 0.10 ; + // read temperature from BME280 + temperature = bme_0x77.readTemperature(); break; case 3: // read temp from SHT31 - temperature = sht31.readTemperature(); + temperature = sht31_0x44.readTemperature(); + break; + case 4: + // read temp from SHT31 + temperature = sht31_0x45.readTemperature(); + break; + case 5: + // read temperature from chrip I2C + temperature = readI2CRegister16bit(0x20, 5) * 0.10 ; break; default: // if sensor type is not recognized, return 99 @@ -138,18 +146,26 @@ float getHumidity(byte HumSensor) { /* * sensors: - * 1: BME280 - * 2: SHT31 + * 1 : BME280 0x76 humidity sensor + * 2 : BME280 0x77 humidity sensor + * 3 : SHT31 0x44 humidity sensor + * 4 : SHT31 0x45 humidity sensor * */ float humidity; switch(HumSensor) { case 1: - humidity = bme.readHumidity(); + humidity = bme_0x76.readHumidity(); break; case 2: - humidity = sht31.readHumidity(); + humidity = bme_0x77.readHumidity(); + break; + case 3: + humidity = sht31_0x44.readHumidity(); + break; + case 4: + humidity = sht31_0x45.readHumidity(); break; default: humidity = 0.0; diff --git a/Arduino/CanGrow/CanGrow_SysFunctions.h b/Arduino/CanGrow/CanGrow_SysFunctions.h index 369bf60..3cbee87 100644 --- a/Arduino/CanGrow/CanGrow_SysFunctions.h +++ b/Arduino/CanGrow/CanGrow_SysFunctions.h @@ -114,7 +114,7 @@ bool loadEEPROM() { * 249 HumiditySensor_Type (1 byte) * 250 PWMFrequency (2 byte) * 252 DisplayScreenDuration (1 byte) - * 253 + * 253 ... * */ diff --git a/Arduino/CanGrow/CanGrow_WebFunctions.h b/Arduino/CanGrow/CanGrow_WebFunctions.h index 4ead04c..d9a31cd 100644 --- a/Arduino/CanGrow/CanGrow_WebFunctions.h +++ b/Arduino/CanGrow/CanGrow_WebFunctions.h @@ -629,7 +629,7 @@ void WEBsystemSettings() { body += "
\n"; // UseFANrelais bool - body += "Use relais for FAN (disable PWM): \n"; if(configured == false){body += "\n";} body += "\n"; body += "\n"; @@ -647,7 +647,7 @@ void WEBsystemSettings() { body += "\n"; } body += "\n"; - body += "\n"; + body += "\n"; body += "
\n"; // SoilmoistureLow byte @@ -679,9 +679,11 @@ void WEBsystemSettings() { if(configured == false) { body += "\n"; } - body += "\n"; - body += "\n"; - body += "\n"; + body += "\n"; + body += "\n"; + body += "\n"; + body += "\n"; + body += "\n"; body += "
\n"; // HumiditySensor_Type byte @@ -689,8 +691,10 @@ void WEBsystemSettings() { if(configured == false) { body += "\n"; } - body += "\n"; - body += "\n"; + body += "\n"; + body += "\n"; + body += "\n"; + body += "\n"; body += "
\n"; // NtpOffset int @@ -710,7 +714,7 @@ void WEBsystemSettings() { // DisplayScreenDuration byte body += "Display rotation interval: s
\n"; + body += "' required> Seconds
\n"; body += "

0 will always show sensor value screen

"; body += "ESP32-Cam IP (optional):