firmware - v0.1.1, offer different I2C addresses for BME280, SHT31.
its done quick and dirty and some Typos got fixed
This commit is contained in:
parent
2098445202
commit
0a2c56cd7b
5 changed files with 102 additions and 46 deletions
|
@ -6,10 +6,10 @@
|
||||||
|
|
||||||
// set CANGROW_VER and CANGROW_BUILD if not already done as Compiler Flag
|
// set CANGROW_VER and CANGROW_BUILD if not already done as Compiler Flag
|
||||||
#ifndef CANGROW_VER
|
#ifndef CANGROW_VER
|
||||||
#define CANGROW_VER "v0.1.0-dev"
|
#define CANGROW_VER "v0.1.1-dev"
|
||||||
#endif
|
#endif
|
||||||
#ifndef CANGROW_BUILD
|
#ifndef CANGROW_BUILD
|
||||||
#define CANGROW_BUILD "1a2b3c4f"
|
#define CANGROW_BUILD "1a2b3c4f-001"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -136,25 +136,39 @@ void setup() {
|
||||||
// dht.begin(); //TODO: Do only, when configured
|
// dht.begin(); //TODO: Do only, when configured
|
||||||
|
|
||||||
// initialise BME280
|
// 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
|
// ToDo: let the user configure somewhere the ID of the BME280 sensor
|
||||||
if(!bme.begin(0x76)) {
|
if(!bme_0x76.begin(0x76)) {
|
||||||
Serial.println("!! Cannot find BME280 on I2C bus. Please check connection or ID");
|
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
|
// initialise SHT31
|
||||||
Serial.println(":: initialise SHT31 sensor ::");
|
Serial.println(":: initialise SHT31 sensor, address 0x44 ::");
|
||||||
if (! sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
|
if (! sht31_0x44.begin(0x44)) { // Set to 0x45 for alternate i2c addr
|
||||||
Serial.println("Couldn't find SHT31");
|
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: ");
|
Serial.print(":: SHT31 (0x44) heater enable state ::");
|
||||||
if (sht31.isHeaterEnabled())
|
if (sht31_0x44.isHeaterEnabled())
|
||||||
Serial.println("ENABLED");
|
Serial.println("ENABLED");
|
||||||
else
|
else
|
||||||
Serial.println("DISABLED");
|
Serial.println("DISABLED");
|
||||||
|
|
||||||
|
Serial.print(":: SHT31 (0x45) heater enable state ::");
|
||||||
|
if (sht31_0x45.isHeaterEnabled())
|
||||||
|
Serial.println("ENABLED");
|
||||||
|
else
|
||||||
|
Serial.println("DISABLED");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,16 +12,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
#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
|
* SHT30/31 Stuff
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool enableHeater = false;
|
Adafruit_SHT31 sht31_0x44 = Adafruit_SHT31();
|
||||||
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
Adafruit_SHT31 sht31_0x45 = Adafruit_SHT31();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Chirp functions
|
* Chirp functions
|
||||||
|
@ -103,9 +104,11 @@ float getTemperature(byte tempSensor) {
|
||||||
/*
|
/*
|
||||||
* tempSensor
|
* tempSensor
|
||||||
* ==========
|
* ==========
|
||||||
* 1 : DHT11 temp sensor
|
* 1 : BME280 0x76 temp sensor
|
||||||
* 2 : chirp I2C temp sensor
|
* 2 : BME280 0x77 temp sensor
|
||||||
* 3 : SHT31
|
* 3 : SHT31 0x44 temp sensor
|
||||||
|
* 4 : SHT31 0x45 temp sensor
|
||||||
|
* 5 : Chirp I2C 0x20 temp sensor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float temperature = 0;
|
float temperature = 0;
|
||||||
|
@ -113,18 +116,23 @@ float getTemperature(byte tempSensor) {
|
||||||
switch(tempSensor) {
|
switch(tempSensor) {
|
||||||
case 1:
|
case 1:
|
||||||
// read temperature from BME280
|
// read temperature from BME280
|
||||||
temperature = bme.readTemperature();
|
temperature = bme_0x76.readTemperature();
|
||||||
// read temperature from DHT11
|
|
||||||
// dht support dropped
|
|
||||||
// temperature = dht.readTemperature();
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// read temperature from chrip I2C
|
// read temperature from BME280
|
||||||
temperature = readI2CRegister16bit(0x20, 5) * 0.10 ;
|
temperature = bme_0x77.readTemperature();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// read temp from SHT31
|
// 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;
|
break;
|
||||||
default:
|
default:
|
||||||
// if sensor type is not recognized, return 99
|
// if sensor type is not recognized, return 99
|
||||||
|
@ -138,18 +146,26 @@ float getHumidity(byte HumSensor) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sensors:
|
* sensors:
|
||||||
* 1: BME280
|
* 1 : BME280 0x76 humidity sensor
|
||||||
* 2: SHT31
|
* 2 : BME280 0x77 humidity sensor
|
||||||
|
* 3 : SHT31 0x44 humidity sensor
|
||||||
|
* 4 : SHT31 0x45 humidity sensor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
float humidity;
|
float humidity;
|
||||||
|
|
||||||
switch(HumSensor) {
|
switch(HumSensor) {
|
||||||
case 1:
|
case 1:
|
||||||
humidity = bme.readHumidity();
|
humidity = bme_0x76.readHumidity();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
humidity = sht31.readHumidity();
|
humidity = bme_0x77.readHumidity();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
humidity = sht31_0x44.readHumidity();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
humidity = sht31_0x45.readHumidity();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
humidity = 0.0;
|
humidity = 0.0;
|
||||||
|
|
|
@ -114,7 +114,7 @@ bool loadEEPROM() {
|
||||||
* 249 HumiditySensor_Type (1 byte)
|
* 249 HumiditySensor_Type (1 byte)
|
||||||
* 250 PWMFrequency (2 byte)
|
* 250 PWMFrequency (2 byte)
|
||||||
* 252 DisplayScreenDuration (1 byte)
|
* 252 DisplayScreenDuration (1 byte)
|
||||||
* 253
|
* 253 ...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -629,7 +629,7 @@ void WEBsystemSettings() {
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
// UseFANrelais bool
|
// UseFANrelais bool
|
||||||
body += "Use relais for FAN (disable PWM): <select id='UseFANrelais' name='UseFANrelais' required>\n";
|
body += "Use relais for FAN1 (disable PWM): <select id='UseFANrelais' name='UseFANrelais' required>\n";
|
||||||
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
if(configured == false){body += "<option disabled value='' selected hidden>---</option>\n";}
|
||||||
body += "<option value='1'" + returnStrSelected(UseFANrelais, 1) + ">Yes</option>\n";
|
body += "<option value='1'" + returnStrSelected(UseFANrelais, 1) + ">Yes</option>\n";
|
||||||
body += "<option value='0'" + returnStrSelected(UseFANrelais, 0) + ">No</option>\n";
|
body += "<option value='0'" + returnStrSelected(UseFANrelais, 0) + ">No</option>\n";
|
||||||
|
@ -647,7 +647,7 @@ void WEBsystemSettings() {
|
||||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||||
}
|
}
|
||||||
body += "<option value='1'" + returnStrSelected(MoistureSensor_Type, 1) + ">Analog capacitive</option>\n";
|
body += "<option value='1'" + returnStrSelected(MoistureSensor_Type, 1) + ">Analog capacitive</option>\n";
|
||||||
body += "<option value='2'" + returnStrSelected(MoistureSensor_Type, 2) + ">I2C Chirp</option>\n";
|
body += "<option value='2'" + returnStrSelected(MoistureSensor_Type, 2) + ">I2C Chirp (0x20)</option>\n";
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
// SoilmoistureLow byte
|
// SoilmoistureLow byte
|
||||||
|
@ -679,9 +679,11 @@ void WEBsystemSettings() {
|
||||||
if(configured == false) {
|
if(configured == false) {
|
||||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||||
}
|
}
|
||||||
body += "<option value='1'" + returnStrSelected(TemperatureSensor_Type, 1) + ">I2C BME280</option>\n";
|
body += "<option value='1'" + returnStrSelected(TemperatureSensor_Type, 1) + ">I2C BME280 (0x76)</option>\n";
|
||||||
body += "<option value='2'" + returnStrSelected(TemperatureSensor_Type, 2) + ">I2C Chirp</option>\n";
|
body += "<option value='2'" + returnStrSelected(TemperatureSensor_Type, 2) + ">I2C BME280 (0x77)</option>\n";
|
||||||
body += "<option value='3'" + returnStrSelected(TemperatureSensor_Type, 3) + ">I2C SHT31</option>\n";
|
body += "<option value='3'" + returnStrSelected(TemperatureSensor_Type, 3) + ">I2C SHT31 (0x44)</option>\n";
|
||||||
|
body += "<option value='4'" + returnStrSelected(TemperatureSensor_Type, 4) + ">I2C SHT31 (0x45)</option>\n";
|
||||||
|
body += "<option value='5'" + returnStrSelected(TemperatureSensor_Type, 5) + ">I2C Chirp (0x20)</option>\n";
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
// HumiditySensor_Type byte
|
// HumiditySensor_Type byte
|
||||||
|
@ -689,8 +691,10 @@ void WEBsystemSettings() {
|
||||||
if(configured == false) {
|
if(configured == false) {
|
||||||
body += "<option disabled value='' selected hidden>---</option>\n";
|
body += "<option disabled value='' selected hidden>---</option>\n";
|
||||||
}
|
}
|
||||||
body += "<option value='1'" + returnStrSelected(HumiditySensor_Type, 1) + ">I2C BME280</option>\n";
|
body += "<option value='1'" + returnStrSelected(HumiditySensor_Type, 1) + ">I2C BME280 (0x76)</option>\n";
|
||||||
body += "<option value='2'" + returnStrSelected(HumiditySensor_Type, 2) + ">I2C SHT31</option>\n";
|
body += "<option value='2'" + returnStrSelected(HumiditySensor_Type, 2) + ">I2C BME280 (0x77)</option>\n";
|
||||||
|
body += "<option value='3'" + returnStrSelected(HumiditySensor_Type, 3) + ">I2C SHT31 (0x44)</option>\n";
|
||||||
|
body += "<option value='4'" + returnStrSelected(HumiditySensor_Type, 4) + ">I2C SHT31 (0x45)</option>\n";
|
||||||
body += "</select><br>\n";
|
body += "</select><br>\n";
|
||||||
|
|
||||||
// NtpOffset int
|
// NtpOffset int
|
||||||
|
@ -710,7 +714,7 @@ void WEBsystemSettings() {
|
||||||
// DisplayScreenDuration byte
|
// DisplayScreenDuration byte
|
||||||
body += "Display rotation interval: <input class='inputShort' type='number' name='DisplayScreenDuration' min='0' max='255' value='";
|
body += "Display rotation interval: <input class='inputShort' type='number' name='DisplayScreenDuration' min='0' max='255' value='";
|
||||||
body += DisplayScreenDuration;
|
body += DisplayScreenDuration;
|
||||||
body += "' required> s<br>\n";
|
body += "' required> Seconds<br>\n";
|
||||||
body += "<p class='helpbox'><b>0</b> will always show sensor value screen</p>";
|
body += "<p class='helpbox'><b>0</b> will always show sensor value screen</p>";
|
||||||
|
|
||||||
body += "ESP32-Cam IP (optional): <input type='text' name='Esp32CamIP' maxlength='16' value='";
|
body += "ESP32-Cam IP (optional): <input type='text' name='Esp32CamIP' maxlength='16' value='";
|
||||||
|
@ -1191,6 +1195,12 @@ void APIgetDebug() {
|
||||||
objSystem["MaintenanceDuration"] = MaintenanceDuration;
|
objSystem["MaintenanceDuration"] = MaintenanceDuration;
|
||||||
objSystem["PumpOnTime"] = PumpOnTime;
|
objSystem["PumpOnTime"] = PumpOnTime;
|
||||||
objSystem["PumpLastOn"] = PumpLastOn;
|
objSystem["PumpLastOn"] = PumpLastOn;
|
||||||
|
objSystem["OutputInvert"] = OutputInvert;
|
||||||
|
objSystem["SoilmoistureWet"] = SoilmoistureWet;
|
||||||
|
objSystem["SoilmoistureDry"] = SoilmoistureDry;
|
||||||
|
objSystem["HumiditySensor_Type"] = HumiditySensor_Type;
|
||||||
|
objSystem["PWMFrequency"] = PWMFrequency;
|
||||||
|
objSystem["DisplayScreenDuration"] = DisplayScreenDuration;
|
||||||
|
|
||||||
// Grow
|
// Grow
|
||||||
JsonObject objGrow = jsonDebug["grow"].add<JsonObject>();
|
JsonObject objGrow = jsonDebug["grow"].add<JsonObject>();
|
||||||
|
@ -1210,22 +1220,38 @@ void APIgetDebug() {
|
||||||
objGrow["DayOfGrow"] = DayOfGrow;
|
objGrow["DayOfGrow"] = DayOfGrow;
|
||||||
objGrow["PumpIntervalVeg"] = PumpIntervalVeg;
|
objGrow["PumpIntervalVeg"] = PumpIntervalVeg;
|
||||||
objGrow["PumpIntervalBloom"] = PumpIntervalBloom;
|
objGrow["PumpIntervalBloom"] = PumpIntervalBloom;
|
||||||
|
objSystem["PinFAN2PWM"] = PinFAN2PWM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
JsonObject objSensors = jsonDebug["sensors"].add<JsonObject>();
|
JsonObject objSensors = jsonDebug["sensors"].add<JsonObject>();
|
||||||
|
|
||||||
// Chirp
|
// Chirp
|
||||||
objSensors["chirp"]["temperature"] = getTemperature(2);
|
objSensors["chirp"]["temperature"] = getTemperature(5);
|
||||||
objSensors["chirp"]["soilmoisture"] = getSoilmoisture(2);
|
objSensors["chirp"]["soilmoisture"] = getSoilmoisture(2);
|
||||||
objSensors["chirp"]["soilmoistureRAW"] = getSoilmoisture(2, true);
|
objSensors["chirp"]["soilmoistureRAW"] = getSoilmoisture(2, true);
|
||||||
objSensors["chirp"]["light"] = getLightchirp();
|
objSensors["chirp"]["light"] = getLightchirp();
|
||||||
|
|
||||||
// BME280
|
// BME280 0x76
|
||||||
objSensors["bme280"]["temperature"] = getTemperature(1);
|
objSensors["bme280_0x76"]["temperature"] = getTemperature(1);
|
||||||
objSensors["bme280"]["humidity"] = getHumidity(1);
|
objSensors["bme280_0x76"]["humidity"] = getHumidity(1);
|
||||||
objSensors["bme280"]["preassure"] = bme.readPressure() / 100.0F;
|
//objSensors["bme280_0x76"]["preassure"] = bme.readPressure() / 100.0F;
|
||||||
objSensors["bme280"]["appAltitude"] = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
//objSensors["bme280_0x76"]["appAltitude"] = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
||||||
|
|
||||||
|
// BME280 0x77
|
||||||
|
objSensors["bme280_0x77"]["temperature"] = getTemperature(2);
|
||||||
|
objSensors["bme280_0x77"]["humidity"] = getHumidity(2);
|
||||||
|
//objSensors["bme280_0x77"]["preassure"] = bme.readPressure() / 100.0F;
|
||||||
|
//objSensors["bme280_0x77"]["appAltitude"] = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
||||||
|
|
||||||
|
// SHT31 0x44
|
||||||
|
objSensors["sht31_0x44"]["temperature"] = getTemperature(3);
|
||||||
|
objSensors["sht31_0x44"]["humidity"] = getHumidity(3);
|
||||||
|
|
||||||
|
// SHT31 0x45
|
||||||
|
objSensors["sht31_0x45"]["temperature"] = getTemperature(4);
|
||||||
|
objSensors["sht31_0x45"]["humidity"] = getHumidity(4);
|
||||||
|
|
||||||
// Analog
|
// Analog
|
||||||
objSensors["analog"]["soilmoisture"] = getSoilmoisture(1);
|
objSensors["analog"]["soilmoisture"] = getSoilmoisture(1);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
test -z $TTY && TTY="/dev/ttyUSB0"
|
test -z $TTY && TTY="/dev/ttyUSB0"
|
||||||
test -z $IP && IP="192.168.4.20"
|
test -z $IP && IP="192.168.4.20"
|
||||||
test -z $VER && VER="0.1.0"
|
test -z $VER && VER="0.1.1"
|
||||||
BUILD="$(git rev-parse --short HEAD)-$(date '+%Y%m%d%H%M%S')"
|
BUILD="$(git rev-parse --short HEAD)-$(date '+%Y%m%d%H%M%S')"
|
||||||
|
|
||||||
ACLI="$HOME/.local/bin/arduino-cli"
|
ACLI="$HOME/.local/bin/arduino-cli"
|
||||||
|
|
Loading…
Reference in a new issue