From fd8277b70297f69f63dab662f583ff0477abe6d9 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 12 Dec 2021 16:00:45 +0100 Subject: [PATCH 1/5] Don't manipulate the green LED during runtime, as it is the powersource for the I2C sensor --- src/main.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6d0b74a..3b58099 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ #define PM1006_BIT_RATE 9600 #define PM1006_MQTT_UPDATE 5000 /**< Check the sensor every 10 seconds; New measurement is done every 20seconds by the sensor */ +#define I2C_MAX_INIT 10 #define SEALEVELPRESSURE_HPA (1013.25) @@ -353,7 +354,7 @@ bool ledHandler(const HomieRange& range, const String& value) { *****************************************************************************/ void setup() -{ +{ SPIFFS.begin(); Serial.begin(115200); Serial.setTimeout(2000); @@ -407,8 +408,6 @@ void setup() if (mConfigured) { if (i2cEnable.get()) { - strip.fill(strip.Color(0,128,0)); - strip.show(); #ifdef BME680 printf("Wait 1 second...\r\n"); delay(1000); @@ -416,6 +415,8 @@ void setup() /* Extracted from library's example */ mFailedI2Cinitialization = !bmx.begin(); if (!mFailedI2Cinitialization) { + strip.fill(strip.Color(0,64,0)); + strip.show(); #ifdef BME680 bmx.setTemperatureOversampling(BME680_OS_8X); bmx.setHumidityOversampling(BME680_OS_2X); @@ -443,7 +444,6 @@ void setup() digitalWrite(WITTY_RGB_B, HIGH); } else { digitalWrite(WITTY_RGB_R, HIGH); - digitalWrite(WITTY_RGB_G, LOW); strip.fill(strip.Color(128,0,0)); for (int i=0;i < (PIXEL_COUNT / 2); i++) { strip.setPixelColor(0, strip.Color(0,0,128)); @@ -462,7 +462,6 @@ void loop() } if (mButtonPressed > BUTTON_MIN_ACTION_CYCLE) { digitalWrite(WITTY_RGB_R, HIGH); - digitalWrite(WITTY_RGB_G, LOW); digitalWrite(WITTY_RGB_B, LOW); strip.fill(strip.Color(0,0,0)); strip.setPixelColor(0, strip.Color((mButtonPressed % 100),0,0)); From e3fe70dff2c776d4c65593e0cb934acdefcee0a8 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 12 Dec 2021 16:28:53 +0100 Subject: [PATCH 2/5] Removed unnecessary DEFINE --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3b58099..63bcc1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,7 +47,6 @@ #define PM1006_BIT_RATE 9600 #define PM1006_MQTT_UPDATE 5000 /**< Check the sensor every 10 seconds; New measurement is done every 20seconds by the sensor */ -#define I2C_MAX_INIT 10 #define SEALEVELPRESSURE_HPA (1013.25) From 6af6a6ac76f21e9d044ffeb923865a8375640b62 Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 12 Dec 2021 16:47:40 +0100 Subject: [PATCH 3/5] Use red led to visualize button presses --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 63bcc1d..4075751 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -209,6 +209,7 @@ void onHomieEvent(const HomieEvent &event) digitalWrite(WITTY_RGB_R, LOW); if (!i2cEnable.get()) { /** keep green LED activated to power I2C sensor */ digitalWrite(WITTY_RGB_G, LOW); + log(MQTT_LEVEL_INFO, F("I2C powersupply deactivated"), MQTT_LOG_I2CINIT); } digitalWrite(WITTY_RGB_B, LOW); strip.fill(strip.Color(0,0,128)); @@ -227,6 +228,9 @@ void onHomieEvent(const HomieEvent &event) case HomieEventType::OTA_SUCCESSFUL: ESP.restart(); break; + case HomieEventType::WIFI_CONNECTED: + digitalWrite(WITTY_RGB_B, HIGH); + break; default: break; } @@ -440,7 +444,6 @@ void setup() strip.setPixelColor(0, strip.Color(0,0,128)); } strip.show(); - digitalWrite(WITTY_RGB_B, HIGH); } else { digitalWrite(WITTY_RGB_R, HIGH); strip.fill(strip.Color(128,0,0)); @@ -470,6 +473,7 @@ void loop() } } else { mButtonPressed=0U; + digitalWrite(WITTY_RGB_R, LOW); } if (mButtonPressed > BUTTON_MAX_CYCLE) { From 5ece74b0e659607330be1786bc0bfb41df9270ae Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 12 Dec 2021 17:07:20 +0100 Subject: [PATCH 4/5] Activate I2C after powering the sensor --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4075751..c8ab44e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -403,8 +403,6 @@ void setup() .setDatatype("integer"); strip.begin(); - /* activate I2C for BOSCH sensor */ - Wire.begin(SENSOR_I2C_SDI, SENSOR_I2C_SCK); mConfigured = Homie.isConfigured(); digitalWrite(WITTY_RGB_G, HIGH); @@ -415,6 +413,10 @@ void setup() printf("Wait 1 second...\r\n"); delay(1000); #endif + /* activate I2C for BOSCH sensor */ + Wire.begin(SENSOR_I2C_SDI, SENSOR_I2C_SCK); + printf("Wait 50 milliseconds...\r\n"); + delay(50); /* Extracted from library's example */ mFailedI2Cinitialization = !bmx.begin(); if (!mFailedI2Cinitialization) { From dadee863b8f9fb77eac41334fd5fa9263a7aae9f Mon Sep 17 00:00:00 2001 From: Ollo Date: Sun, 12 Dec 2021 17:45:45 +0100 Subject: [PATCH 5/5] GPIO and Arduino-Pins are never the same --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c8ab44e..d5bb3bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,8 +42,8 @@ #define PM1006_MQTT_UPDATE 5000 /**< Check the sensor every 10 seconds; New measurement is done every 20seconds by the sensor */ #define PIXEL_COUNT 3 #define GPIO_BUTTON SENSOR_PM1006_RX /**< Button and software serial share one pin on Witty board */ -#define SENSOR_I2C_SCK D1 /**< GPIO14 - I2C clock pin */ -#define SENSOR_I2C_SDI D5 /**< GPIO5 - I2C data pin */ +#define SENSOR_I2C_SCK D5 /**< GPIO14 - I2C clock pin */ +#define SENSOR_I2C_SDI D1 /**< GPIO5 - I2C data pin */ #define PM1006_BIT_RATE 9600 #define PM1006_MQTT_UPDATE 5000 /**< Check the sensor every 10 seconds; New measurement is done every 20seconds by the sensor */