I am building a simple resistor / capacitor in series (RC) circuit to measure resistance with my RPi A+.
RC Design
This design is similar to the one used in this tutorial as suggest on this post. This circuit works by measuring the resistance of R1 by measuring the time required to charge C1. I do understand that Python is not a great language for precision timing, but this doesn't need to be very precise. It's mostly a project to learn circuit analysis with the Raspberry Pi. My Python script I am using for this math is the following:
# time how long it takes for C1 to charge thru R1
GPIO.setup (8, GPIO.IN);GPIO.output (10, 1)
start = time.time ()
while GPIO.input (8) == 0: False
end = time.time ()
# divide duration by capacitance to get resistance
capacitance = 0.47 * 0.000001 # 0.47 uF
duration = end - start
resistance = duration / capacitance
resistance *= 1.85938 # <===== THE HORRIBLE MYSTERY COEFFICIENT
print ('resistance =', round (resistance), 'ohms')
Math Error - Mystery Coeficcient
The above setup outputs (mostly) accurate numbers for the value of R1. The problem is the unexplained coefficient ~1.85938
. Some possible error sources I've considered include:
- internal resistance from the GPIO itself (with the 3.3V, 16mA max output per pin),
- problems due to inaccuracies in my components themselves (the resistors have tolerances of 5%),
- a flaw in the universe of the kind that make
1 = 2
and never-ending chocolate possible, - or some combination of the above.
Does any circuit analysis / Raspberry Pi expert why RC circuits built with the GPIO would be off by a factor of ~1.85938
?