From 35e12347984f1911c8d4767e28c6e188b6426648 Mon Sep 17 00:00:00 2001 From: klaute Date: Thu, 20 Feb 2020 19:49:44 +0100 Subject: [PATCH] Added battery pin configuration --- firmware/config.h | 6 ++++++ firmware/config_user.h.example | 1 + firmware/firmware.ino | 10 ++++++++-- firmware/sensor_battery.ino | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/firmware/config.h b/firmware/config.h index 5ace793..09ffc77 100755 --- a/firmware/config.h +++ b/firmware/config.h @@ -32,8 +32,14 @@ #define STATUS_LED_PIN LED_BUILTIN #define ANEMOMETER_PIN D7 + +#ifndef BAT_PINS_D34 #define BAT_CHARGED_PIN D6 #define BAT_CHARGING_PIN D5 +#else +#define BAT_CHARGED_PIN D3 +#define BAT_CHARGING_PIN D4 +#endif #define BME_SCK 13 #define BME_MISO 12 diff --git a/firmware/config_user.h.example b/firmware/config_user.h.example index d5e2ad3..4383af4 100644 --- a/firmware/config_user.h.example +++ b/firmware/config_user.h.example @@ -17,6 +17,7 @@ //#define SENSOR_APDS9930 #define SENSOR_BME280 #define SENSOR_BATTERY +//#define BAT_PINS_D34 const float HUMIDITY_FACTOR = 1.0; const float LIGHT_FACTOR = 1.0; diff --git a/firmware/firmware.ino b/firmware/firmware.ino index ff52e6a..5918152 100755 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -45,14 +45,20 @@ void setup() { #endif // Pin settings - pinMode(BAT_CHARGED_PIN, INPUT_PULLUP); - pinMode(BAT_CHARGING_PIN, INPUT_PULLUP); + pinMode(BAT_CHARGED_PIN, INPUT); + pinMode(BAT_CHARGING_PIN, INPUT); pinMode(STATUS_LED_PIN, OUTPUT); pinMode(ANEMOMETER_PIN, INPUT_PULLUP); pinMode(A0, INPUT); digitalWrite(STATUS_LED_PIN, LOW); +#ifndef BAT_PINS_D34 + debug("D5 D6 used as battery pins"); +#else + debug("D3 D4 used as battery pins"); +#endif + #ifdef BATTERY_POWERED criticalBatCheck(); #endif diff --git a/firmware/sensor_battery.ino b/firmware/sensor_battery.ino index 5d41d81..4cba750 100755 --- a/firmware/sensor_battery.ino +++ b/firmware/sensor_battery.ino @@ -13,6 +13,9 @@ float battery_voltage() { } float battery_charging() { + //debug("charging pin=" + String(digitalRead(BAT_CHARGING_PIN))); + //debug("charged pin=" + String(digitalRead(BAT_CHARGED_PIN))); + if (LOW == digitalRead(BAT_CHARGING_PIN)) { return BAT_CHARGE_STATE_CHARGING; } else if (LOW == digitalRead(BAT_CHARGED_PIN)) {