Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By torntrousers
#19012 The ESP can read the supply voltage itself. For that to work the ADC pin must not be connected to anything. There is also a bug currently where it causes intermitent wdt reset crashes if the esp is in station mode.
Code: Select all#include <ESP8266WiFi.h>
extern "C" {
  uint16 readvdd33(void);
}

void setup() {
  WiFi.mode(WIFI_AP_STA); // readvdd33 doesn't work currently in WIFI_STA mode
  Serial.begin(115200);
  Serial.println();
}

void loop() {
  float vdd = readvdd33() / 1000.0;
  Serial.print("Vdd: ");
  Serial.println(vdd);
  delay(1000);
}
User avatar
By gr0b
#19013 Attached is some working example code for using readvdd33() to get an idea of the battery voltage.


Code: Select all//used samples from http://www.esp8266.com/viewtopic.php?f=33&t=2485
//Use a silicone diode to drop the voltage from the Lithium battery to within a safe range for the ESP module (should be between 2.5-3.6v)
//readvdd33() does not return correct values if anything is connect to the ADC pin

extern "C" {
uint16 readvdd33(void);
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println();
  Serial.println();

  Serial.print("VCC:");
  Serial.println(readvdd33());      //this is the raw reading in mV, should something like 3300 if powered by 3.3volts

  Serial.print("Battery:");
  Serial.println(readvdd33()+600);  //here we add the voltage drop from the diode back to give us an idea of the battery voltage
}


void loop() {
  // put your main code here, to run repeatedly:
}