From 4f55d124e90cdc6f6ab3cfa3d2b49f558e7f43f5 Mon Sep 17 00:00:00 2001 From: foorschtbar Date: Thu, 21 Sep 2023 22:48:06 +0200 Subject: [PATCH] WIP --- platformio.ini | 129 +++++++++++++++++++++++++++++++++++++++--------- src/PixelIt.ino | 40 +++++++++++---- 2 files changed, 136 insertions(+), 33 deletions(-) diff --git a/platformio.ini b/platformio.ini index 4f797f0..7ff1a20 100644 --- a/platformio.ini +++ b/platformio.ini @@ -35,28 +35,39 @@ lib_deps = bakercp/CRC32 @ 2.0.0 [env:wemos_d1_mini32] - platform = espressif32 - board = wemos_d1_mini32 - framework = ${common.framework} - board_build.f_cpu = 80000000L - monitor_speed = ${common.monitor_speed} - extra_scripts = ${common.extra_scripts} - upload_speed = ${common.upload_speed} - build_flags = ${common.build_flags} - platform_packages = +platform = espressif32 +board = wemos_d1_mini32 +framework = ${common.framework} +board_build.f_cpu = 80000000L +monitor_speed = ${common.monitor_speed} +extra_scripts = ${common.extra_scripts} +upload_speed = ${common.upload_speed} +build_flags = + ${common.build_flags} + -DLDR_PIN=A0 + -DMATRIX_PIN=27 + -DDEFAULT_PIN_SCL="Pin_D1" + -DDEFAULT_PIN_SDA="Pin_D3" + -DDEFAULT_PIN_DFPRX="Pin_D7" + -DDEFAULT_PIN_DFPTX="Pin_D8" + -DDEFAULT_PIN_ONEWIRE="Pin_D1" + -DDEFAULT_MATRIX_TYPE=1 + -DDEFAULT_LDR=GL5516 + -DVBAT_PIN=0 +platform_packages = framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git toolchain-xtensa32@~2.80400.0 - lib_deps = - ${common.lib_deps} - WiFiManager = https://github.com/tzapu/WiFiManager.git#v2.0.15-rc.1 - plerup/EspSoftwareSerial@^6.11.4 - fastled/FastLED@^3.5.0 - adafruit/Adafruit BME680 Library@^2.0.1 - adafruit/Adafruit BMP280 Library@^2.6.1 - claws/BH1750@^1.2.0 - robtillaart/Max44009@^0.5.2 - arduino-libraries/ArduinoHttpClient@^0.4.0 - Hash = https://github.com/bbx10/Hash_tng.git +lib_deps = + ${common.lib_deps} + WiFiManager = https://github.com/tzapu/WiFiManager.git#v2.0.15-rc.1 + plerup/EspSoftwareSerial@^6.11.4 + fastled/FastLED@^3.5.0 + adafruit/Adafruit BME680 Library@^2.0.1 + adafruit/Adafruit BMP280 Library@^2.6.1 + claws/BH1750@^1.2.0 + robtillaart/Max44009@^0.5.2 + arduino-libraries/ArduinoHttpClient@^0.4.0 + Hash = https://github.com/bbx10/Hash_tng.git [env:ESP8266] platform = espressif8266@2.6.3 @@ -66,7 +77,18 @@ board_build.filesystem = littlefs monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} upload_speed = ${common.upload_speed} -build_flags = ${common.build_flags} +build_flags = + ${common.build_flags} + -DLDR_PIN=A0 + -DMATRIX_PIN=D2 + -DDEFAULT_PIN_SCL="Pin_D1" + -DDEFAULT_PIN_SDA="Pin_D3" + -DDEFAULT_PIN_DFPRX="Pin_D7" + -DDEFAULT_PIN_DFPTX="Pin_D8" + -DDEFAULT_PIN_ONEWIRE="Pin_D1" + -DDEFAULT_MATRIX_TYPE=1 + -DDEFAULT_LDR=GL5516 + -DVBAT_PIN=0 lib_deps = ${common.lib_deps} tzapu/WiFiManager@^0.16.0 @@ -86,7 +108,18 @@ board_build.filesystem = littlefs monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} upload_speed = ${common.upload_speed} -build_flags = ${common.build_flags} +build_flags = + ${common.build_flags} + -DLDR_PIN=A0 + -DMATRIX_PIN=D2 + -DDEFAULT_PIN_SCL="Pin_D1" + -DDEFAULT_PIN_SDA="Pin_D3" + -DDEFAULT_PIN_DFPRX="Pin_D7" + -DDEFAULT_PIN_DFPTX="Pin_D8" + -DDEFAULT_PIN_ONEWIRE="Pin_D1" + -DDEFAULT_MATRIX_TYPE=1 + -DDEFAULT_LDR=GL5516 + -DVBAT_PIN=0 lib_deps = ${common.lib_deps} tzapu/WiFiManager@^0.16.0 @@ -105,7 +138,18 @@ board_build.filesystem = littlefs monitor_speed = ${common.monitor_speed} extra_scripts = ${common.extra_scripts} upload_speed = ${common.upload_speed} -build_flags = ${common.build_flags} +build_flags = + ${common.build_flags} + -DLDR_PIN=A0 + -DMATRIX_PIN=D2 + -DDEFAULT_PIN_SCL="Pin_D1" + -DDEFAULT_PIN_SDA="Pin_D3" + -DDEFAULT_PIN_DFPRX="Pin_D7" + -DDEFAULT_PIN_DFPTX="Pin_D8" + -DDEFAULT_PIN_ONEWIRE="Pin_D1" + -DDEFAULT_MATRIX_TYPE=1 + -DDEFAULT_LDR=GL5516 + -DVBAT_PIN=0 lib_deps = ${common.lib_deps} tzapu/WiFiManager@^0.16.0 @@ -115,3 +159,42 @@ lib_deps = robtillaart/Max44009@^0.5.2 arduino-libraries/ArduinoHttpClient@^0.4.0 mr-glt/SHA-1 Hash@^1.1.0 + +[env:Ulanzi] +platform = espressif32 +board = esp32dev +framework = ${common.framework} +board_build.f_cpu = 80000000L +monitor_speed = ${common.monitor_speed} +extra_scripts = ${common.extra_scripts} +upload_speed = ${common.upload_speed} +platform_packages = + framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git + toolchain-xtensa32@~2.80400.0 +build_flags = + ${common.build_flags} + -DLDR_PIN=A7 + -DMATRIX_PIN=32 + -DULANZI + -DVBAT_PIN=GPIO_NUM_34 + -DDEFAULT_PIN_SCL=GPIO_NUM_22 + -DDEFAULT_PIN_SDA=GPIO_NUM_21 + -DDEFAULT_PIN_DFPRX=SPI_CLK_GPIO_NUM + -DDEFAULT_PIN_DFPTX=SPI_CS0_GPIO_NUM + -DDEFAULT_PIN_ONEWIRE=GPIO_NUM_22 + -DDEFAULT_MATRIX_TYPE=2 + -DDEFAULT_LDR=GL5516 + -DMIN_BATTERY=475 + -DMAX_BATTERY=665 +lib_deps = + ${common.lib_deps} + WiFiManager = https://github.com/tzapu/WiFiManager.git#v2.0.15-rc.1 + fastled/FastLED@^3.5.0 + arduino-libraries/ArduinoHttpClient@^0.4.0 + adafruit/Adafruit SHT31 Library @ 2.2.0 + Hash = https://github.com/bbx10/Hash_tng.git + plerup/EspSoftwareSerial@^6.11.4 + adafruit/Adafruit BME680 Library@^2.0.1 + adafruit/Adafruit BMP280 Library@^2.6.1 + claws/BH1750@^1.2.0 + robtillaart/Max44009@^0.5.2 \ No newline at end of file diff --git a/src/PixelIt.ino b/src/PixelIt.ino index 1ab984a..17239a6 100644 --- a/src/PixelIt.ino +++ b/src/PixelIt.ino @@ -93,7 +93,11 @@ String SDAPin = STR(DEFAULT_PIN_SDA); String ldrDevice = STR(DEFAULT_LDR); unsigned long ldrPulldown = 10000; // 10k pulldown-resistor unsigned int ldrSmoothing = 0; -float batteryLevelPct = 0; + +// Bettery stuff +float batteryLevel = 0; +unsigned long batteryLevelPrevMillis = 0; +const int BATTERY_LEVEL_INTERVAL = 30 * 1000; // Telemetry API #define TELEMETRY_SERVER_HOST "pixelit.bastelbunker.de" @@ -363,16 +367,26 @@ String ResetReason() void getBatteryVoltage() { - batteryLevelPct = map(analogRead(VBAT_PIN), 510, 660, 0, 100); - if (batteryLevelPct >= 100) + uint16_t value = 0; + uint8_t numReadings = 5; + + for (uint8_t i = 0; i < numReadings; i++) + { + value = value + analogRead(VBAT_PIN); + + // 1ms pause adds more stability between reads. + delay(1); + } + + batteryLevel = map(value / numReadings, MIN_BATTERY, MAX_BATTERY, 0, 100); + if (batteryLevel >= 100) { - batteryLevelPct = 100; + batteryLevel = 100; } - if (batteryLevelPct <= 0) + if (batteryLevel <= 0) { - batteryLevelPct = 1; + batteryLevel = 1; } - String strBV = String(batteryLevelPct, 0) + " %"; } void SetCurrentMatrixBrightness(float newBrightness) @@ -1811,8 +1825,7 @@ String GetSensor() if (VBAT_PIN > 0) { - getBatteryVoltage(); - root["battery"] = batteryLevelPct; + root["battery"] = batteryLevel; } else { @@ -3008,7 +3021,7 @@ void ShowBatteryScreen() getBatteryVoltage(); matrix->clear(); DrawSingleBitmap(root["bitmap"]); - DrawTextHelper(String(batteryLevelPct, 0) + "%", false, true, false, false, false, 255, 255, 255, 9, 1); + DrawTextHelper(String(batteryLevel, 0) + "%", false, true, false, false, false, 255, 255, 255, 9, 1); matrix->show(); delay(1000); } @@ -3629,6 +3642,13 @@ void loop() server.handleClient(); webSocket.loop(); + // Update Battery level + if (millis() - batteryLevelPrevMillis >= BATTERY_LEVEL_INTERVAL) + { + batteryLevelPrevMillis = millis(); + getBatteryVoltage(); + } + // Reset GPIO based on the array, as far as something is present in the array. for (int i = 0; i < SET_GPIO_SIZE; i++) {