Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
foorschtbar committed Sep 21, 2023
1 parent 4e117ea commit 4f55d12
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 33 deletions.
129 changes: 106 additions & 23 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
40 changes: 30 additions & 10 deletions src/PixelIt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1811,8 +1825,7 @@ String GetSensor()

if (VBAT_PIN > 0)
{
getBatteryVoltage();
root["battery"] = batteryLevelPct;
root["battery"] = batteryLevel;
}
else
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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++)
{
Expand Down

0 comments on commit 4f55d12

Please sign in to comment.