Skip to content

Commit 8d7fb22

Browse files
Fix battery voltage read problem
1 parent b8b0f9d commit 8d7fb22

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

examples/ESP32/ADC_Read_Voltage/Battery_power/Battery_power.ino

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
* - WIFI Kit series V1 don't have Vext control function;
1313
*
1414
* HelTec AutoMation, Chengdu, China.
15-
* �ɶ��������Զ����Ƽ����޹�˾
16-
* www.heltec.cn
15+
* 成都惠利特自动化科技有限公司
16+
* https://heltec.org
1717
1818
*
1919
* this project also release in GitHub:
@@ -24,24 +24,15 @@
2424
#include <Wire.h>
2525
#include "heltec.h"
2626

27-
//#define Vext 21
28-
//
29-
//#define SDA 4 //OLED SDA pin
30-
//#define SCL 15 //OLED SCL pin
31-
//#define RST 16 //OLED nRST pin
3227
#define Fbattery 3700 //The default battery is 3700mv when the battery is fully charged.
3328

3429
float XS = 0.00225; //The returned reading is multiplied by this XS to get the battery voltage.
3530
uint16_t MUL = 1000;
3631
uint16_t MMUL = 100;
37-
//SSD1306 display(0x3c, SDA, SCL, RST);
3832

3933
void setup()
4034
{
41-
// pinMode(Vext, OUTPUT);
42-
// digitalWrite(Vext, LOW);
43-
// delay(1000);
44-
Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial Enable*/);
35+
Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial Enable*/);
4536

4637
Heltec.display->init();
4738
Heltec.display->flipScreenVertically();
@@ -59,18 +50,20 @@ Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial
5950

6051
void loop()
6152
{
62-
uint16_t c = analogRead(13)*XS*MUL;
63-
//uint16_t d = (analogRead(13)*XS*MUL*MMUL)/Fbattery;
64-
Serial.println(analogRead(13));
65-
//Serial.println((String)d);
66-
// Serial.printf("%x",analogRead(13));
53+
//WiFi LoRa 32 -- hardare versrion ≥ 2.3
54+
//WiFi Kit 32 -- hardare versrion ≥ 2
55+
//Wireless Stick -- hardare versrion ≥ 2.3
56+
//Wireless Stick Lite -- hardare versrion ≥ 2.3
57+
//Battery voltage read pin changed from GPIO13 to GPI37
58+
uint16_t c = analogRead(37)*XS*MUL;
59+
Serial.println(analogRead(37));
60+
// uint16_t c = analogRead(13)*XS*MUL;
61+
// Serial.println(analogRead(13));
62+
6763
Heltec.display->drawString(0, 0, "Remaining battery still has:");
6864
Heltec.display->drawString(0, 10, "VBAT:");
6965
Heltec.display->drawString(35, 10, (String)c);
7066
Heltec.display->drawString(60, 10, "(mV)");
71-
// Heltec.display->drawString(90, 10, (String)d);
72-
// Heltec.display->drawString(98, 10, ".";
73-
// Heltec.display->drawString(107, 10, "%");
7467
Heltec.display->display();
7568
delay(2000);
7669
Heltec.display->clear();

src/heltec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Heltec_ESP32::~Heltec_ESP32(){
2121

2222
void Heltec_ESP32::begin(bool DisplayEnable, bool LoRaEnable, bool SerialEnable, bool PABOOST, long BAND) {
2323

24-
#if defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick ) || defined( Wireless_Stick_Lite )
24+
#if defined( WIFI_LoRa_32_V2 ) || defined( Wireless_Stick ) || defined( Wireless_Stick_Lite ) || defined(WIFI_Kit_32)
2525

2626
VextON();
2727
#endif

0 commit comments

Comments
 (0)