0
\$\begingroup\$

I'm trying to re-implement the Arduino Capacitive Sensing Library. In the process, I need to read one GPIO's state with another GPIO. The board I'm using is a ESP-01S with the ESP8266 microcontroller. For the capacitive touch sensing I had hooked up GPIO1 (TX pin) and GPIO3 (RX pin) with a 1 MΩ resistor in between:

enter image description here

Source: https://www.circuit-diagram.org/circuits/3772f77eea784f95905e7fb9187fcb32

But I saw lots of wrong readings. To test it further, I didn't use the GPIO as the signal source, but connected +3.3V and GND directly:

enter image description here

Source: https://www.circuit-diagram.org/circuits/d593fce7198b4bd9950dbbabcc972f38

enter image description here

Source: https://www.circuit-diagram.org/circuits/812adaa58b004c89afa61a88a8cd4b23

And I still saw erroneous readings. I'm using MicroPython:

>>> pin = machine.Pin(3, mode=machine.Pin.IN, pull=None)
>>> # connected to GND
>>> [pin.value() for _ in range(1000)].count(0)
974
>>> # connected to +3.3V
>>> [pin.value() for _ in range(1000)].count(1)
949

So instead of 1000 in both cases, I get up to about 5% wrong readings.

Is that normal? Is there anything I can do about this?

\$\endgroup\$
8
  • 1
    \$\begingroup\$ What happens if you use 1 kilohm instead? You need to isolate the problem to either the hardware or the software. \$\endgroup\$ Oct 12, 2021 at 15:12
  • \$\begingroup\$ @ElliotAlderson Yes, I'm sorry, maybe I should have explicitly mentioned that. If I'm using a 10 kΩ resistor, the issue disappears. That's why I put the part about the 1 MΩ resistor in the title. Sorry for the confusion. \$\endgroup\$
    – finefoot
    Oct 12, 2021 at 15:15
  • 1
    \$\begingroup\$ What is the maximum leakage current specification for a GPIO pin configured as an input? What voltage will be produced if this current flows through 1 megohm? \$\endgroup\$ Oct 12, 2021 at 15:22
  • \$\begingroup\$ @ElliotAlderson Thank you very much for your reply. However, I'm afraid I don't know how to answer your questions. Is that something I can look up somewhere? Or can I measure it? My equipment is very limited though. I only have a very basic digital multimeter. \$\endgroup\$
    – finefoot
    Oct 12, 2021 at 15:26
  • 1
    \$\begingroup\$ forum.arduino.cc/t/esp8266-and-capacitive-sensoring/444198 "The esp pins seem to have a much lower impedance than the atmega pins. With a 1MOhm resistor, my Wemos D1 mini board was not able to pull up the receiver pin. With a 470kOhm resistor, it worked." \$\endgroup\$ Oct 12, 2021 at 21:09

1 Answer 1

4
\$\begingroup\$

This is perfectly normal.

The ESP8266EX microcontroller on your module does not have ideal and perfect I/O pin circuits, no logic IC has. When your I/O pin is configured as an input, it will sink (take in) or source (drive out) a small current to whatever's driving it. This current is called the input leakage current, often IIL (I Input Leakage).

The ESP8266EX datasheet I have does not define the leakage current but other comparable logic IC technologies have typical figures of +/-3 uA, +/-10 uA max.

This means that when your TX output pin is driving LOW, for example, the RX input pin has a current of, say, up to 10 uA flowing out of RX, through the 1M resistor and into TX. The voltages at either end of the resistor are not large enough to push all 10 uA through the resistor but the resistor will still have a large voltage drop across it.

This stops RX being pulled to its required logic LOW voltage of (0.25 x VIO) <0.8 V approx. A similar problem happens when TX is logic high and RX is drawing an input leakage current through the resistor.

In fact, the voltage on RX will sit in the 'indeterminate' voltage range for the logic input pin: not low enough for a solid logic LOW, not high enough for a solid logic HIGH. Hence the shaky logic values on RX.

When you drop the resistor to 10K, even the 10 uA max. leakage current produces a drop of only 0.1 V across the resistor so your problem goes away: RX is pulled to a solid HIGH or LOW.

By the way, if you try to measure the voltage across the 1M resistor with a multimeter or oscilloscope, the input resistance of that equipment will draw relatively high currents from this circuit and you'll get wrong measurements.

In short: you can't use such a high resistor as 1M to link a logic output pin to a logic input pin.

If the ESP8266EX supports it, you can reduce the false triggering by configuring the RX input pin as a Schmitt trigger input.

\$\endgroup\$
7
  • \$\begingroup\$ That makes a lot of sense. Thank you very much for your explanations :) But... does that mean the ESP8266 cannot be used in this way? Is the leakage current for the Arduino chips so different? playground.arduino.cc/Main/CapacitiveSensor Because they even talk about using 40 MΩ resistors in this tutorial. \$\endgroup\$
    – finefoot
    Oct 12, 2021 at 19:02
  • \$\begingroup\$ @rattlesnake, if this application note was your intention all along then your question should be rewritten with this new information edited into it, not posted as a comment. (Please edit it logically into the text, don't dump it at the end under an 'Edit' banner.) The capacitor mentioned in that appnote has a marked effect on the circuit i.e. RC is a lot different to just R. \$\endgroup\$
    – TonyM
    Oct 12, 2021 at 22:02
  • \$\begingroup\$ Hmm, I'm sorry? I'm not sure I understand what you mean. :( I already mentioned the relation of my question to the Arduino Capacitive Sensing Library in my original question text. I didn't omit anything. I was only connecting the pins and was confused by the wrong values. Which your answer has helped a lot with and cleared up most of my questions. So you're saying my follow-up question in the comment doesn't make sense? I was just surprised to see that you say it's normal to get jumbled up readings with 1 MΩ resistors when I didn't even use the maximum that was mentioned in another context. \$\endgroup\$
    – finefoot
    Oct 12, 2021 at 22:12
  • \$\begingroup\$ @rattlesnake, glad it helped, pleasure. Afraid you've skipped the crucial sentence "The capacitor mentioned in that appnote has a marked effect on the circuit i.e. RC is a lot different to just R." and it's all in that. You only show R between I/Os and readers naturally won't follow links to investigate other circuits using RC across I/Os if you've drawn one with just R. Its all those diagrams that have to change. Again, RC is a lot different to just R. \$\endgroup\$
    – TonyM
    Oct 12, 2021 at 22:36
  • \$\begingroup\$ So you're saying the resistor and leakage current will behave totally different as soon as a capacitance is added to the circuit and it won't affect the readings in the same sense? Anyway, it doesn't change the fact that I wasn't able to explain my findings with this current (intermediate) setup which your answer helped clearing up. ;) My circuit for this question was set up exactly as described in the question text. I didn't expect anyone to follow any links. It was just for additional context. \$\endgroup\$
    – finefoot
    Oct 12, 2021 at 22:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.