Skip to content

Instantly share code, notes, and snippets.

@ketan
Created September 21, 2024 13:19
Show Gist options
  • Save ketan/4d68e7beda95df0163e42e5a7d44c485 to your computer and use it in GitHub Desktop.
Save ketan/4d68e7beda95df0163e42e5a7d44c485 to your computer and use it in GitHub Desktop.
Patch file for meshtastic firmware to support a lifepo4 battery and sense the voltage on it using a voltage divider. Patch created on tag `v2.4.2.5b45303` of meshtastic firmware.
diff --git a/platformio.ini b/platformio.ini
index e60f0d7b..dba29771 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -2,8 +2,9 @@
; https://docs.platformio.org/page/projectconf.html
[platformio]
-default_envs = tbeam
-;default_envs = pico
+default_envs = rp2040-lora
+; default_envs = tbeam
+; default_envs = pico
;default_envs = tbeam-s3-core
;default_envs = tbeam0.7
;default_envs = heltec-v1
@@ -153,6 +154,6 @@ lib_deps =
https://github.com/KodinLanewave/INA3221@^1.0.0
lewisxhe/SensorLib@^0.2.0
mprograms/QMC5883LCompass@^1.2.0
-
+
https://github.com/meshtastic/DFRobot_LarkWeatherStation#dee914270dc7cb3e43fbf034edd85a63a16a12ee
diff --git a/variants/rp2040-lora/variant.h b/variants/rp2040-lora/variant.h
index 1f42c4db..bbcee556 100644
--- a/variants/rp2040-lora/variant.h
+++ b/variants/rp2040-lora/variant.h
@@ -19,10 +19,11 @@
#define LED_PIN PIN_LED
-// #define BATTERY_PIN 26
-// ratio of voltage divider = 3.0 (R17=200k, R18=100k)
-// #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic
-
+#define BATTERY_PIN 27
+// ratio of voltage divider = 3.0 (R1=R2=47K)
+#define ADC_MULTIPLIER 2.1 // 3.0 + a bit for being optimistic
+#define BATTERY_SENSE_RESOLUTION_BITS ADC_RESOLUTION
+#define CELL_TYPE_LIFEPO4
#define USE_SX1262
#undef LORA_SCK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment