Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By schufti
#23660 for the "pullup" method check this code
Code: Select all#include <stdint.h>

#define CPIN 4

void setup() {
  pinMode(CPIN, INPUT);
  Serial.begin(115200);
  delay(10);

  Serial.println("start");
 }

void loop() {

  unsigned long cycleStart, cycleStop, chargeTime;

  // drain cap first
  pinMode(CPIN, OUTPUT);
  digitalWrite(CPIN, LOW);

  Serial.print(micros()); Serial.print(" - ");
  Serial.println("Discharging...");
  delay(5000);

  pinMode(CPIN, INPUT_PULLUP);        // now start charging via pullup
  Serial.print(micros()); Serial.println(" - Charging!!!");
  cycleStart = micros();
  while (digitalRead(CPIN) == 0) {yield();};
  cycleStop = micros();
  chargeTime = cycleStop - cycleStart;

  Serial.print(cycleStop); Serial.print(" - Done...");
  Serial.print(chargeTime);
  Serial.println("ms");
  delay(1000);

}


I got your sketch working with 100k resistor and this code:
Code: Select all#include <stdint.h>

#define CPIN 4
#define DPIN 5

void setup() {
  pinMode(CPIN, INPUT);
  pinMode(DPIN, INPUT);
  Serial.begin(115200);
  delay(10);

  Serial.println("start");
 }

void loop() {

  unsigned long cycleStart, cycleStop, chargeTime;

  // drain cap first                best via both pins
  pinMode(DPIN, OUTPUT);
  pinMode(CPIN, OUTPUT);
  digitalWrite(DPIN, LOW);
  digitalWrite(CPIN, LOW);

  Serial.print(micros()); Serial.print(" - ");
  Serial.println("Discharging...");
  delay(5000);

  digitalWrite(CPIN, HIGH);   // prepare charging yet not possible because drainPin still low
  pinMode(DPIN, INPUT);        // now start really by tristating drainPin
  Serial.print(micros()); Serial.println(" - Charging!!!");
  cycleStart = micros();
  while (digitalRead(DPIN) == 0) {yield();};
  cycleStop = micros();
  chargeTime = cycleStop - cycleStart;

  Serial.print(cycleStop); Serial.print(" - Done...");
  Serial.print(chargeTime);
  Serial.println("ms");
  delay(1000);

}


pick whatever you like. if you are after small C's you'll need the one with the charging resistor
User avatar
By Daemach
#23853 Thanks. The caps I'm testing are very small so the pullup method doesn't seem to be working. I was able to make it work with a 300K resistor, but it would sure be great to get the granularity that I would with a 1M resistor. Hopefully someone will chime in on why that isn't working.