## EEBookshelf: Resistive Touch Screen Calibration

While 4-wire resistive touchs are starting to feel definitively 1990s, they’re still by far the most accessible and affordable way to add interactivity to your LCD-based projects, and that’s unlikely to change any time soon.

Technically all you need to read data from a touch screen is three ADC pins, and a fourth GPIO (digital I/O) pin.  In reality, things are a bit more complicated.  You also need to map that data to the individual pixels on the LCD screen beneath the touch screen, and you can have variation from one touch screen to another due to manufacturing differences, rotation or offset of the touch screen, etc.

So how do you accurately and consistently map data from your touch screen to an underlying X/Y pixel?  Read on to find out more in the latest installment of EE Bookshelf!

While working on a project a while back with a TFT LCD screen and a built in resistive touch screen, I naively wrote my own touch screen calibration code measuring the four corners of the display, calculating the offest between top and bottom and then dividing some values to guess the location.  It sort of worked, but was off by up to 10 pixels or so because the screen response wasn’t linear.

Being a bit ashamed of the results, I starting wondering how other people calibrate resistive touch screens, and came across a couple really helpful appnotes from Cypress and TI:

Don’t get too scared away by all the calculations, but both of these app note explain the way that most systems correlate touch screen values to underlying pixels: linear algebra and matrix multiplication.  (If you can’t remember how that works, I’ll sneak in a real book in this review that has a good refresher on this and just about everything else you’ve forgotten since high school or university: K.A. Stroud, Engineering Mathematics 6th Edition, ISBN 0831133279).

Basically, the formula described in these app notes will take into account the rotation of the screen, and variation in sensitivity between the top and bottom of the resistive panel, etc., and deliver a reliable translation between the touch screen and the underlying display.  In my own case, using the methods described in the app notes above, I went from being off by as much as 10 pixels or more to being within 1-2 pixels or where I was touching.

As a compliment to the above app notes, Carlos E. Vidales wrote an article way back when that includes some source code to get the matrix multiplication out of the way.  The accompanying article also explains the same concept if the app notes were a bit hard to digest, but you’ll definately want to have a look at the source code available in a link here: EE Times – How to Calibrate Touch Screens.

If you just want to see some code quickly (based on the work from Carlos Vidales and the app notes above), you can see how I used this to improve my own touch screen results here.

Adafruit publishes a wide range of writing and video content, including interviews and reporting on the maker market and the wider technology world. Our standards page is intended as a guide to best practices that Adafruit uses, as well as an outline of the ethical standards Adafruit aspires to. While Adafruit is not an independent journalistic institution, Adafruit strives to be a fair, informative, and positive voice within the community – check it out here: adafruit.com/editorialstandards

Adafruit is on Mastodon, join in! adafruit.com/mastodon

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Join over 36,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org

Maker Business — “Packaging” chips in the US

Wearables — Enclosures help fight body humidity in costumes

Electronics — Transformers: More than meets the eye!

Python for Microcontrollers — Python on Microcontrollers Newsletter: Silicon Labs introduces CircuitPython support, and more! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

Adafruit IoT Monthly — Guardian Robot, Weather-wise Umbrella Stand, and more!

Microsoft MakeCode — MakeCode Thank You!

EYE on NPI — Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — #NewProds 7/19/23 Feat. Adafruit Matrix Portal S3 CircuitPython Powered Internet Display!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !