pinMode(pin, INPUT); appears to be broken...
Posted: Tue Jul 14, 2015 11:57 am
I'm trying to create a rudimentary capacitance meter using the ESP8266 and the arduino shell. It's pretty simplistic now. I'm charging a capacitor up through a 1M resistor and counting the time it takes to trigger another IO pin going high. In the following schematic I have pin 14 tied to the V+ side, and pin 12 tied to "output to voltmeter". The problem is that when pin 12 is connected, in INPUT mode, the voltage at that pin never goes above .8V - as if it's sinking to ground. If I remove the connection to pin 12, the capacitor charges up to 3V as I would expect. It's as if pinMode INPUT isn't high impedance.
Am I doing something wrong? Code is below the schematic...
Am I doing something wrong? Code is below the schematic...
Code: Select all
const int chargePin = 14;
const int drainPin = 12;
unsigned long chargeTime = 0;
void setup() {
pinMode(chargePin, OUTPUT);
pinMode(drainPin, INPUT);
digitalWrite(chargePin, LOW);
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
unsigned long cycleStart = 0;
// drain cap first
pinMode(drainPin, OUTPUT);
digitalWrite(drainPin, LOW);
digitalWrite(chargePin, HIGH);
Serial.print(micros()); Serial.print(" - ");
Serial.println("Discharging...");
delay(9000);
cycleStart = micros();
Serial.print(micros()); Serial.print(" - "); Serial.println("Charging!!!");
pinMode(drainPin, INPUT);
digitalWrite(chargePin, LOW);
Serial.println(digitalRead(drainPin));
while (digitalRead(drainPin) == 0) {yield();};
chargeTime = micros() - cycleStart;
Serial.print(micros()); Serial.print(" - "); Serial.print("Done...");
Serial.print(chargeTime);
Serial.println("ms");
delay(1000);
}