Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By lethe
#32900
shoelessone wrote:I'm going to think about this and read a bit more and bread board the first solution. If that works well and it's not a huge pain to use the GPIO0 pin AND program with it, then I'll probably just go that rought!

It's simple, if you use GPIO0 for one of the LEDs. Just use the GPIO as sink (connect the anode of the LED via a resistor to VCC and the cathode to the I/O, LED will light when GPIO0 is low). This will pull GPIO0 up during reset and allow you to enter upload mode by shorting GPIO0 to GND.
I would not recommend using GPIO0/2 or 15 for the touchpad, since they need to be at a defined level when the ESP boots. A finger on the touchpad might mess with that, leading to random boot issues.

Btw: if you don't need the UART interface, you can also use these pins as additional GPIOs (if you don't need to receive anything, but still like to have debug output, you also can use just the RX pin as GPIO).
User avatar
By Tolipwen
#33002 Just a quick question,
is there any advantage of using a MPR121 (http://www.aliexpress.com/item/New-MPR121-Breakout-V12-Capacitive-Touch-Sensor-Controller-Module-I2C-keyboard/32278609940.html) over using GPIOs of an ESP?
Because I planned on using a MPR121 for my capacitive light switch (controlled by an ESP-12) and didn't know I could just use GPIOs for that purpose. And if i could get rid of the MPR121 without sacrificing accuracy it would help me conserve space within the enclosure.
User avatar
By shoelessone
#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?
User avatar
By lethe
#33059
Tolipwen wrote:Just a quick question,
is there any advantage of using a MPR121 (http://www.aliexpress.com/item/New-MPR121-Breakout-V12-Capacitive-Touch-Sensor-Controller-Module-I2C-keyboard/32278609940.html) over using GPIOs of an ESP?

Using the GPIO means that the CPU has to do the sampling in regular intervals, so it can't sleep. The MPR121 seems to have an interrupt pin, so the ESP only needs to query the sensor when it receives an interrupt.
I do not have any experience with dedicated capacitive touch chips, but since they are specifically designed for this purpose, they probably have better sensitivity.
The GPIO method worked well enough for me and does not add any extra cost, so I used it for my lamp... The actual performance will also depend on the "button" you are using, so ymmv. (I'm just using a bare stainless steel screw, which is actually a rather poor design)

shoelessone wrote:Is this idea/code 100% incompatible with the esp8266? Or are there esp8266 architecture versions of these features I could use?

Since there's no information available on how the ESPs ADC works, I would consider it 100% incompatible. The ESP probably does not have a controllable pull-up resistor (AVRs have these, because the ADC pin can also be used as GPIO) and there's no information on any internal capacitor.