Experiment #9: Testing the EXP32’s built in touch sensor pins
Ever since it came to my notice that the ESP32 microcontroller has eight or nine built in touch pins (depending on the board), it struck me that I should check these pins out before committing to using the CapacitiveSensor library for the electro tongue drum.
This experiment tests a single touch sensor connected to a single ESP32 touch sensor pin.
Methodology
Sensor #9G, a vinyl covered, grounded, sensor was connected directly to an ESP32 touch sensor pin and the readings were graphed on a serial plotter. The output of the serial plotter was captured in screen shots.
The output from the touch pin was first recorded without touching the sensor and then after tapping the sensor three times slowly and then three times quickly. The experiment was repeated with the sensor grounded and ungrounded.
Circuit
The ESP32’s touch pin 0 was used. This is found on GPIO pin #4 on my development board. Therefore GPIO pin #4 was connected to the sensor's output pin. Additionally the ESP32’s GND pin was connected to sensor’s ground pin.
Code
Firstly, the ESP32 boards were installed into the Arduino IDE’s Boards Manager as explained in the “Getting started with ESP32” article on the DroneBot Workshop website.
Then a new sketch was written to read the input from the ESP32’s touch sensor #0 and to write the readings to the serial port. This sketch is ESP32SingleSensorRawDataLogger.ino
.
The script was based on one found on the “Getting started with ESP32” article mentioned above.
Results
It should be noted that the results obtained from the EPS32 touch pin are the inverse of those obtained with the CapacitiveSensor library. With the ESP32, a high value is returned when the sensor is not touched and the value drops when it is touched.
The results of not touching the sensor, both with and without grounding, are shown in the following carousel. As can be seen, in both cases, the sensor reading was level.
However, re-running the “Untouched” tests revealed some apparent interference, as can be seen in the following image carousel:
Finally, the graphs for tapping the sensor are shown below. Again the results for the grounded and ungrounded circuits are shown in a carousel:
Conclusions
The high readings for the ungrounded sensor are greater than those for the grounded sensor and the gap between lower and higher values is greater for the ungrounded sensor.
The situation when the sensor is untouched is strange. Multiple runs were undertaken. In some runs the “flat-line” results shown in the 1st image carousel were found while in others the “interference” observed in the second carousel was apparent.
Some of the spikes in values detected when interference is present and the sensor is not touched are large enough to mean that false positive readings could easily be registered. As a consequence some means of “debouncing” in software would be required in order to ignore such anomalies.
Using the ESP32 instead of an Arduino and the CapacitiveSensor library would greatly simplify code and wiring.
While the simplicity the ESP32 would bring to circuit and code design is attractive, the potential for interference to cause false tongue hits to be registered means that the CapacitiveSensor library will continue to be used, regardless of the chosen microcontroller.