- Wed Nov 04, 2015 3:18 pm
#33052
Hey all, just wanted to beat a dead horse a bit!
So, I was looking around and found a library for Arduino (not esp8266 arduino) that uses a single ADC pin + the "internal capacitor" to do simple capacitive on/off touch. The library is here:
http://playground.arduino.cc/Code/ADCTouch The copy/pasted explination he uses is as follows:
1. charge the test pin to 5V via pullup resistor (not directly to prevent short circuits)
2. discharge the internal ~14pF capacitor
3. set the pin to tristate
4. connect the 14pF capacitor with the pin so that charge distributes evenly
5. measure the voltage of the internal cap with analogRead()
6. If the pin has a low capacitance, the stored charge will be small as will the resulting voltage, if the external capacitance is equal to 14pF, the volatage should be ~2.5V. Even higher capacitances will result in volatges > 2.5V. The chip and arduino board already have stray capacitances that will produce an output of ~390 and just a single external wire can boost that up to 500, so you really need offset compensation.
Now the code he uses to do this is super simple:
Code: Select allint ADCTouchClass::read(byte ADCChannel, int samples)
{
long _value = 0;
for(int _counter = 0; _counter < samples; _counter ++)
{
pinMode(ADCChannel, INPUT_PULLUP);
//
ADMUX |= 0b11111;
ADCSRA |= (1<<ADSC); //start conversion
while(!(ADCSRA & (1<<ADIF))); //wait for conversion to finish
ADCSRA |= (1<<ADIF); //reset the flag
pinMode(ADCChannel, INPUT);
_value += analogRead(ADCChannel);
}
return _value / samples;
}
Now, I'm GUESSING that this isn't something I can "port" over to the esp266? I'm guessing somebody would have mentioned this already. Code wise, ADMUX, ADSC, ADCSRA, ADIF are not defined within the esp8266 world world, so simply using the library is not possible.
Is this idea/code 100% incompatible with the esp8266? Or are there esp8266 architecture versions of these features I could use?