048 - MicroPython TechNotes: Analog Touch Sensor
Introduction
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.
Pinout
This module has 3 pins which are:
- G – for the ground pin.
- V – for the supply voltage.
- S – for the analog touch sensor signal pin.
Bill Of Materials
In order to follow this lesson, you will need the following:
- An ESP32 development board with Micropython firmware.
- A Gorillacell ESP32 shield (this is optional, you can use a breadboard instead and just follow the circuit connection).
- A 3-pin dupont wires.
- And of course the Analog Touch Sensor itself.
- You might also need an 8×8 Dot Matrix display with SPI interface for the example # 3.
Hardware Instruction
- Connect the Analog Touch Sensor G pin to ESP32 GND pin.
- Connect the Analog Touch Sensor V pin to ESP32 3.3V pin.
- Connect the Analog Touch Sensor S pin to ESP32 GPIO 32. MicroPython implements ADC inputs on GPIO 32 to GPIO 39 only.
Video Demonstration
Call To Action
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
Source Code
1. Example # 1, exploring the basics using the REPL:
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())
2. Example # 2, automatic detection of touch sensor key press:
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)
3. Example # 3, control the pixel movement on Dot Matrix Display using the Analog Touch Sensor:
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)
References And Credits
- Purchase your Gorillacell ESP32 development kits from: https://gorillacell.kr/
Posts in this series
- 049 - MicroPython TechNotes: MP3 Player
- 047 - MicroPython TechNotes: E108 GPS
- 046 - MicroPython TechNotes: RF433 Transceivers
- 045 - MicroPython TechNotes: Infrared Transmitter
- 044 - MicroPython TechNotes: Infrared Receiver
- 043 - MicroPython TechNotes: ESP12E WiFi | External WiFi module
- 042 - MicroPython TechNotes: JDY-32 | Bluetooth Low Energy BLE
- 041 - MicroPython TechNotes: Bluetooth HC-06
- 040 - MicroPython TechNotes: Relay
- 039 - MicroPython TechNotes: Electromagnet
- 038 - MicroPython TechNotes: Buzzer
- 037 - MicroPython TechNotes: Servo Motor
- 036 - MicroPython TechNotes: Stepper Motor
- 035 - MicroPython TechNotes: Dual Motor Driver
- 034 - MicroPython TechNotes: DC Motors | Gear Motor and Fan Motor
- 033 - MicroPython TechNotes: TCS34725 RGB Color Sensor
- 032 - MicroPython TechNotes: BMP280 Sensor
- 031 - MicroPython TechNotes: TOF Distance Sensor
- 030 - MicroPython TechNotes: DS3231 RTC
- 029 - MicroPython TechNotes: HC-SR04 Ultrasonic Sensor
- 028 - MicroPython TechNotes: DHT11 Temperature and Humidity Sensor
- 027 - MicroPython TechNotes: Rotary Encoder
- 026 - MicroPython TechNotes: Light Dependent Resistor (LDR)
- 025 - MicroPython TechNotes: Joystick
- 024 - MicroPython TechNotes: Slider Switch
- 023 - MicroPython TechNotes: Continuous Rotation Potentiometer
- 022 - MicroPython TechNotes: Potentiometer | Reading an Analog Input
- 021 - MicroPython TechNotes: Color Touch Sensor
- 020 - MicroPython TechNotes: Touch Sensor
- 019 - MicroPython TechNotes: Switch Module
- 018 - MicroPython TechNotes: Button | Reading an Input
- 017 - MicroPython TechNotes: LASER Module
- 016 - MicroPython TechNotes: RGB LED Matrix
- 015 - MicroPython TechNotes: Neopixel 16
- 014 - MicroPython TechNotes: 8x8 Dot Matrix Display (I2C)
- 013 - MicroPython TechNotes: 8x16 Dot Matrix Display (SPI)
- 012 - MicroPython TechNotes: 8x8 Dot Matrix Display (SPI)
- 011 - MicroPython TechNotes: 1.3 OLED Display
- 010 - MicroPython TechNotes: 0.96 OLED Display
- 009 - MicroPython TechNotes: 7 Segment Display
- 008 - MicroPython TechNotes: 16x2 LCD
- 007 - MicroPython TechNotes: RGB LED
- 006 - MicroPython TechNotes: Traffic Light LED Module
- 005 - MicroPython TechNotes: Gorilla Cell LED | MicroPython Hello World
- 004 - MicroPython TechNotes: Gorilla Cell I/O Devices
- 003 - MicroPython TechNotes: Gorillacell ESP32 Shield
- 002 - MicroPython TechNotes: Introduction for Gorillacell ESP32 Dev Kit
- 001 - MicroPython TechNotes: Get Started with MicroPython
- 000 - MicroPython TechNotes: Unboxing Gorillacell ESP32 Development Kit
No comments yet!