strange charging curve of RC circuit

I use the simple circuitry shown in the attached fritzing drawing with the code below, obtaining the charging RC curve shown in the attached two plots, respectively for R=10K Ohm and R = 100K Ohm.
It looks like that in parallel with the capacitor is an additional ghost large resistor that after a fraction of the RC time suddenly becomes infinite (or is disconnected).
The ghost resistor Rg should be large because the final tension read on the capacitor in the ghost resistor model should be Rg/(R+Rg) and indeed it turns out to be very near to 1.

/*
http://www.circuitbasics.com/how-to-set-up-an-lcd-display-on-an-arduino/
*/

#define analogPin 0
#define chargePin 13
#define dischargePin 11 // It is in the default input mode
#define resistorValue 10000.0F

#include <LiquidCrystal.h>

unsigned long startTime;
unsigned long elapsedTime;
float microFarads;
float nanoFarads;
float Vcap;

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)

void setup(){
/* “dischargePin” is in the default INPUT mode, so in a high-impedance state.

  • Input pins make extremely small demands on the circuit that they are sampling,
  • equivalent to a series resistor of 100 megohm in front of the pin. This means
  • that it takes very little current to move the input pin from one state to
  • another, and can make the pins useful for such tasks as implementing a capacitive
  • touch sensor, reading an LED as a photodiode, or reading an analog sensor with a
  • scheme such as RCTime.
    */
    pinMode(chargePin, OUTPUT);
    digitalWrite(chargePin, LOW);
    Serial.begin(250000);
    }

void loop(){
digitalWrite(chargePin, HIGH);
startTime = micros();
Vcap = (float(analogRead(analogPin))/1024.0)*5.0;
while(Vcap < 4.995117187){ // 5 time-constants = 0.993 of charging voltage //4.865 <---------------------- NB
Vcap = (float(analogRead(analogPin))/1024.0)*5.0;
Serial.println(Vcap);
}

elapsedTime = micros() - startTime;
microFarads = (((float)elapsedTime / resistorValue) * 1000);
//lcd.print(elapsedTime);
//lcd.print(" usec ");
//lcd.setCursor(3,1); // Sets the location at which subsequent text written to the LCD will be displayed

if (microFarads > 1){
//lcd.print(microFarads);
//lcd.print(" uF");
}
else{
nanoFarads = microFarads * 1000.0;
//lcd.print(nanoFarads);
//lcd.print(" nF");
}

delay(1000);

//lcd.clear();
digitalWrite(chargePin, LOW);
pinMode(dischargePin, OUTPUT);
digitalWrite(dischargePin, LOW);
while(analogRead(analogPin) > 0) {}

pinMode(dischargePin, INPUT);
}

USE CODE TAGS ! (</> toolbutton)

/*
http://www.circuitbasics.com/how-to-set-up-an-lcd-display-on-an-arduino/
*/


#define analogPin      0         
#define chargePin      13       
#define dischargePin   11       // It is in the default input mode
#define resistorValue  10000.0F 

#include <LiquidCrystal.h>

unsigned long startTime;
unsigned long elapsedTime;
float microFarads;               
float nanoFarads;
float Vcap;


LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)

void setup(){
  /* "dischargePin" is in the default INPUT mode, so in a high-impedance state.
   *  Input pins make extremely small demands on the circuit that they are sampling,
   *  equivalent to a series resistor of 100 megohm in front of the pin. This means
   *  that it takes very little current to move the input pin from one state to
   *  another, and can make the pins useful for such tasks as implementing a capacitive
   *  touch sensor, reading an LED as a photodiode, or reading an analog sensor with a
   *  scheme such as RCTime.
   */
  pinMode(chargePin, OUTPUT);     
  digitalWrite(chargePin, LOW);
  Serial.begin(250000);
}

void loop(){
  digitalWrite(chargePin, HIGH); 
  startTime = micros();
  Vcap = (float(analogRead(analogPin))/1024.0)*5.0; 
  while(Vcap < 4.995117187){      // 5 time-constants = 0.993 of charging voltage  //4.865 <---------------------- NB
    Vcap = (float(analogRead(analogPin))/1024.0)*5.0;
    Serial.println(Vcap);
  }   

  elapsedTime = micros() - startTime;
  microFarads = (((float)elapsedTime / resistorValue) * 1000);
  //lcd.print(elapsedTime);       
  //lcd.print(" usec ");
  //lcd.setCursor(3,1); // Sets the location at which subsequent text written to the LCD will be displayed   

  if (microFarads > 1){   
    //lcd.print(microFarads);       
    //lcd.print(" uF");     
  }
  else{
    nanoFarads = microFarads * 1000.0;   
    //lcd.print(nanoFarads);         
    //lcd.print(" nF");       
  }
 
  delay(1000);

  //lcd.clear();
  digitalWrite(chargePin, LOW);           
  pinMode(dischargePin, OUTPUT);           
  digitalWrite(dischargePin, LOW);         
  while(analogRead(analogPin) > 0) {}

  pinMode(dischargePin, INPUT);     
}

Your timebase depends on the number of characters printed to the serial line each time round the loop. When the values change the number of digits needed to represent them your rate of sampling changes.

You need to sample at regular time periods, not at the whim of the baud rate in use.

analogRead() takes about 110µs, each character output takes 44µs.

If you print 3 digits and CRLF per sample that's a total of 330µs (3030Hz sampling rate)
If you print 4 digits and CRLF per sample that's 374µs (2674Hz sampling rate)

Code to do that sampling at regular time periods? Thank you!

Use the technique from BlinkWithoutDelay example sketch perhaps?

OK, Thanks!