WIP
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
This project lets you control a couple of LEDs with a potentiometer and a capacitive touch sensor, while reading out the values of the Analog to Digital Converter (ADC) from the potentiometer.
|
||||
This project lets you control a couple of LEDs with a potentiometer and a capacitive touch sensor, using the potentiometer through the analog to digital converter as a dimmer for the green LED vi PWM, and using the capacitive touch sensor as an on/off switch for the red LED.
|
||||
|
||||
The wire coming off pin 14 in the breadboard is just a bare wire hanging off the side for capacitive touch sensing.
|
||||
|
||||
@@ -38,9 +38,7 @@ The ESP32 GPIO pins understand `HIGH` and `LOW`. So if we want to say "How wide
|
||||
|
||||
An ADC measures the voltage on an input and returns a digital value as an integer having precision P in bits. So if an ADC returns a reading with a precision of 12 bits, the reading can range from 0 (being 0v) to 4095 (being 100% of the possible input voltage). An ADC is a collection of circuits that perform this job as a single package, whether integrated on the chip, or as a separate discrete component. There's a bunch of different ways this can be done, but the general theory is that the ADC is a circuit that takes an input voltage and expresses it as an integer representing a quantity between 0 and 100% of the potential maximum.
|
||||
|
||||
One of the simplest ADCs to implement is called a Flash ADC, and that one is simple enough we can build it on a breadboard. I can't build this one yet - I need to come back to this when some components arrive in the mail.
|
||||
|
||||
- Need to come back and build a flash ADC when my components get here
|
||||
One of the simplest ADCs to implement is called a Flash ADC, and that one is simple enough we can build it on a breadboard. I'll build one of these at some point and document it, but for right now I want to get through this lesson and move on to the next one. I am drowning in ADC knowledge and must now vomit it out.
|
||||
|
||||
## How the ESP32-S3 ADC works
|
||||
|
||||
@@ -246,5 +244,24 @@ Aaaaaand I'm spent.
|
||||
|
||||
The TRM has a ton of information on these peripherals, but I'll be honest, if you're not used to reading TRMs, this can get thick quick. I needed a couple days of digging through the manuals to make sense of it all. But I'm glad I did.
|
||||
|
||||
## Measuring Capacitance
|
||||
## Understanding capacitance and touch sensors
|
||||
|
||||
The last thing I wanted to understand here was ... How does the ESP32-S3 know when I'm touching that wire attached to the touch sensor?
|
||||
|
||||
The average touch sensor consists of a conductive surface connected to a GPIO dedicated to reading touch. But "touch" is not really measurable in an electronic sense. Touch sensors are really just measuring the capacitance of a given pathway.
|
||||
|
||||
Capacitance is a property of any two conductors separated by an insulator. We're probably used to thinking of capacitors as electronic components that have an anode and a cathode (`+` and `-`) that cross a pair of plates with some kind of material between them (usually foil or an electrolyte). These devices work by storing charge as an electric field between the two plates, and they have the ability to discharge that current with great rapidity. Capacitance is a measure of how much charge can be stored in a particular pair of objects - whether that is a pair of plates, or your finger and a bare wire.
|
||||
|
||||
Consider the old trick of rubbing a balloon against your head, and then pulling it away. Your hair is attracted to the balloon because of static electricity. What you're actually seeing is that the balloon is charged one way, and your hair is charged another way. Specifically there is a *difference* in charge between your hair and the balloon. The hair loses electrons, while the balloon gains electrons. Because of this difference, charge exists; measurable voltage exists; and electric fields exist. But there is no significant current flowing (there may be electrons jumping here and there but it's not significant). When you move the balloon away and the hair rises to meet it, that isn't because of current, it's because the electric field generated exerts a force on the charges in the hair.
|
||||
|
||||
The balloon is essentially the same as how a capacitor works; there is a difference in the electrical charge between the two plates, and that creates an electrical field between them. Eventually the charge difference becomes great enough, and the electrical field strong enough, that lots of electrons jump all at once. It's a lot like how lightning works - the charge builds up so much that eventually the air breaks down, and ZAP, lightning.
|
||||
|
||||
But a capacitive touch sensor isn't exactly the same as a capacitor. All it is doing is acting as a sensor for electrical fields. The touch sensor itself is just some kind of conductive object that's connected to a circuit with some capacitors that have a known amount of capacitance. To read the sensor, the ESP32-S3 just discharges the capacitor and then detects how long before the capacitor is fully charged again. By doing this over and over, it can detect changes in the electrical field on the touch sensor, because the test capacitor will charge more or less slowly.
|
||||
|
||||
Why don't we need some special kind of touch sensor for this to work? I've spent a lot of time using "capacitive touch screens" and was given the impression this technology was something special. Just grabbing onto a bare wire seems ... cheap.
|
||||
|
||||

|
||||
|
||||
Since the touch sensor is just detecting changes in the rate of charge of a capacitor, all we need is something that will allow us to transmit electrons from one store (our bodies) to the other (the testing capacitor). This can be done by just getting the store (our fingertip) close enough to the wire to form the electrical field that's due to the charge imbalance; this will create a detectable change in the rate of charge of the capacitor. It doesn't even matter if we're grounded or not, because it isn't about completing a circuit with the sensor, it's about getting two charged objects near each other to induce that electrical field that induces detectable change in the capacitor.
|
||||
|
||||
Now obviously it doesn't ONLY work through the interaction of charged objects through the airgap via an electric field. It still works once we make real physical contact. When I look at the demonstration code running, I saw values around 52k from the touch sensor at idle with no contact. Lightly brushing the wire went up to around 63k. Firmly squeezing the wire brought it up to about 220k. Obviously physically attaching to the circuit will allow the charge variance to create actual current, which will much more rapidly change the rate at which the capacitor recharges after discharging, which will give us a stronger "touch" signal.
|
||||
|
||||
Reference in New Issue
Block a user