ME 305 Group 6 Documentation
Classes | Variables
touchPanel.py File Reference

Driver for a 4-wire resistive touch panel. More...

Classes

class  touchPanel.TouchPanel
 A driver class for a 4-wire resistive touch panel. More...
 

Variables

 touchPanel.IN_CONST = micropython.const(pyb.Pin.IN)
 Pinmode IN. More...
 
 touchPanel.ANALOG_CONST = micropython.const(pyb.Pin.ANALOG)
 Pinmode ANALOG. More...
 
 touchPanel.OUT_PP_CONST = micropython.const(pyb.Pin.OUT_PP)
 Pinmode OUT_PP. More...
 

Detailed Description

Driver for a 4-wire resistive touch panel.

This driver contains a method for scanning and calibrating the pad. Calibration corrects for scale, shift, rotation, and shear, outputing the corrected values in mm. The calibration relies on the user touching points (-80, -40), (-80, 40), (0, 0), (80, -40), (80, 40), in that order during calibration. These points are processed against the ADC readings using the least squares method to develop a correlation.

A 4-wire resistive touch panel has two lengths of wire criss-crossing the surface. When pressure is applied, these two sets circuits contact each other. The scan method works by first setting a pin on each wire to high and low respectively. Current flows from one circuit to another, and the voltage at the connection point is proportional to the position along the touch panel. This voltage is read by an ADC connected to one of the other pins. It is important to note that the other pin must be 'floated', or disconnected to ensure that there is not voltage drop across the resistor leading to the ADC.

The scan method is somewhat optimized to run quickly. The first way this is done is by scanning in the X, Z, then Y, as pictured below. This minimizes the number of pin reassignments.

Scanning diagram

To minimize error, the ADC 'oversamples' each reading using the ADC.read_timed() method, taking 5 readings and averaging them before moving on to the next scan. These readings are triggered by a timer are surprisingly faster than using the ADC.read() method for a single reading! Currently, the timer frequency is set to 80 KHz, and while it does appear to be able to read faster, we decided to keep it at this speed to prevent speed errors.

Another speed-increasing feature is the use of micropython.const() objects. These hold the pin assignments and can be accessed faster than the pin assignments themselves. All of these features mean that a single scan takes only 630 μs.

Scanning speed

Author
Caleb Savard
Chris Linthacum
Date
March 18, 2022

Variable Documentation

◆ ANALOG_CONST

touchPanel.ANALOG_CONST = micropython.const(pyb.Pin.ANALOG)

Pinmode ANALOG.

A quicker way to reference the analog pinmode. I think this is actually unused.

◆ IN_CONST

touchPanel.IN_CONST = micropython.const(pyb.Pin.IN)

Pinmode IN.

A quicker way to reference the input (or float) pinmode

◆ OUT_PP_CONST

touchPanel.OUT_PP_CONST = micropython.const(pyb.Pin.OUT_PP)

Pinmode OUT_PP.

A quicker way to reference the output push-pull pinmode