048 - MicroPython TechNotes: Analog Touch Sensor

In this article, I will discussed how to use an Analog Touch Sensor module which is interface to ESP32 with MicroPython programming language. Analog Touch Sensor module of Gorillacell ESP32 development kit provides a 4 touch sensor input in a single pin. This is achieve because the module provides a different analog value differently for each touch input.

This module has 3 pins which are:

  1. G – for the ground pin.
  2. V – for the supply voltage.
  3. S – for the analog touch sensor signal pin.

In order to follow this lesson, you will need the following:

  1. An ESP32 development board with Micropython firmware.
  2. A Gorillacell ESP32 shield (this is optional, you can use a breadboard instead and just follow the circuit connection).
  3. A 3-pin dupont wires.
  4. And of course the Analog Touch Sensor itself.
  5. You might also need an 8×8 Dot Matrix display with SPI interface for the example # 3.
  1. Connect the Analog Touch Sensor G pin to ESP32 GND pin.
  2. Connect the Analog Touch Sensor V pin to ESP32 3.3V pin.
  3. Connect the Analog Touch Sensor S pin to ESP32 GPIO 32. MicroPython implements ADC inputs on GPIO 32 to GPIO 39 only.

If you have any concern regarding this lesson, be sure to write your message in the comment section. You might also like to consider supporting my journey on Youtube by Subscribing. Click this to Subscribe to TechToTinker YT channel.

Thank you, – George Bantique | tech.to.tinker@gmail.com

 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin
 5from machine import ADC
 6
 7p32 = Pin(32, Pin.IN)
 8ats = ADC(p32)
 9ats.atten(ADC.ATTN_11DB)
10
11print(ats.read())
...
py
 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin, ADC
 5from time import sleep
 6
 7p32 = Pin(32, Pin.IN)
 8ats = ADC(p32)
 9ats.atten(ADC.ATTN_11DB)
10
11while True:
12    adc_value = ats.read()
13    
14    if (adc_value>638) and (adc_value<698):
15        print('You pressed # 1.')
16    elif (adc_value>1483) and (adc_value<1543):
17        print('You pressed # 2.')
18    elif (adc_value>2303) and (adc_value<2363):
19        print('You pressed # 3.')
20    elif (adc_value>3169) and (adc_value<3229):
21        print('You pressed # 4.')
22        
23    sleep(0.3)
...
py
 1# More details can be found in TechToTinker.blogspot.com 
 2# George Bantique | tech.to.tinker@gmail.com
 3
 4from machine import Pin
 5from machine import ADC
 6from machine import SPI
 7from time import sleep
 8from max7219 import Max7219
 9
10spi = SPI(1,
11          baudrate=10000000,
12          polarity=1,
13          phase=0,
14          sck=Pin(19),
15          mosi=Pin(23))
16cs = Pin(18, Pin.OUT)
17dot = Max7219(8, 8, spi, cs, True)
18dot.brightness(15)
19
20p32 = Pin(32, Pin.IN)
21ats = ADC(p32)
22ats.atten(ADC.ATTN_11DB)
23
24col = 0
25row = 0
26
27while True:
28    analog_value = ats.read()
29    
30    if (analog_value>640) and (analog_value<700):
31        if col > 0:
32            col = col - 1
33    elif (analog_value>1470) and (analog_value<1530):
34        if col < 7:
35            col = col + 1
36    elif (analog_value>2310) and (analog_value<2370):
37        if row > 0:
38            row = row - 1
39    elif (analog_value>3170) and (analog_value<3230):
40        if row < 7:
41            row = row + 1
42
43    dot.fill(0)
44    dot.pixel(col, row, 1)
45    dot.show()
46    
47    sleep(0.1)
...
py
  1. Purchase your Gorillacell ESP32 development kits from: https://gorillacell.kr/


Posts in this series



GitHub-flavored Markdown & a sane subset of HTML is supported.