Giter VIP home page Giter VIP logo

adafruit_circuitpython_tt21100's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Basic driver for TT21100 touchscreen drivers. The ESP32-S3 Box dev board uses it.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-tt21100

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-tt21100

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-tt21100

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install tt21100

Or the following command to update an existing version:

circup update

Usage Example

import time
import busio
import board
import adafruit_tt21100

# Create library object (named "tt") using a Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)

tt = adafruit_tt21100.TT21100(i2c)

while True:
    # if the screen is being touched print the touches
    if tt.touched:
        print(tt.touches)

    time.sleep(0.15)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_tt21100's People

Contributors

evaherrada avatar foamyguy avatar kattni avatar tannewt avatar tekktrik avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

tannewt

adafruit_circuitpython_tt21100's Issues

esp32-s3-box touch functionality locks up after touching red circle (home) button

CircuitPython version

Adafruit CircuitPython 8.1.0-beta.2 on 2023-04-26; ESP32-S3-Box-2.5 with ESP32S3

Code/REPL

# SPDX-FileCopyrightText: 2022 Paulus Schulinck
#
# SPDX-License-Identifier: MIT
##############################
# 2022-10-22. Last update: 2023-07-26
# by @PaulskPt
#
# touch test results on an Espressif ESP32-S3-BOX
#
#        319        X          0
#         |                    |
#      ---+--------------------+--- 0
#         |                    |
#         |                    |
#         |                    |
#   Y     |                    |             Middle: x: 159, y: 119
#         |                    |
#         |                    |
#         |                    |
#      ---+--------------------+--- 239
#         |                    |
#
# Conclusion: instead of having 0,0 as the top-left corner
#             the top-right corner is 0,0
#             and the lower-left is 319,239
# NOTE: touching the "red" button on the middle of the lower part of the display
#       causes the touch functionality to halt. Only a reset can restart the
#       touch test again. This problem I will discuss with the Adafruit Circuitpython team.
#
"""
    Example output (part):
        Circuitpython ESP32-S3-Box touch test.
        Please touch the screen,
        except the bottom line with the red button dot.
        main():
        Waiting for your touches...

        ck_touch(): nr of touches= 1
        ck_touched(): screen touched at: (319,0). Pressure: 13
        main(): Added touch data: id= 0, at x,y = 319,0. Pressure= 13
        [...]
        There are 10 records in the touch dictionary:
        dict_keys([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
        key:  0, x,y =   0,  0. id:   0. pressure: 0
        key:  1, x,y = 221,129. id:   0. pressure: 26
        key:  2, x,y = 221,129. id:   0. pressure: 34
        key:  3, x,y = 152, 94. id:   0. pressure: 32
        key:  4, x,y = 238, 36. id:   0. pressure: 26
        key:  5, x,y = 280, 56. id:   0. pressure: 30
        key:  6, x,y = 179, 95. id:   0. pressure: 47
        key:  7, x,y =  25,191. id:   0. pressure: 25
        key:  8, x,y =  57, 45. id:   0. pressure: 25
        key:  9, x,y = 319,  0. id:   0. pressure: 13
        Done!
"""
####
import time
import sys

touch_dict = {0: {'x':0,
                'y': 0,
                'id': 0,
                'pressure': 0}}

import board
import busio
import adafruit_tt21100

my_debug = False

i2c = busio.I2C(board.SCL, board.SDA)

# Create library object (named "tt") using a Bus I2C port
# Note: GPIO3 is connected to board.CPT_INT
#       See schematic -> Strapping
tt = adafruit_tt21100.TT21100(i2c) # , irq_pin=3)
# print(f"dir(tt)= {dir(tt)}")
if tt:
    if my_debug:
        print(f"\ndir(tt)= {dir(tt)}")
    print(f"Global: tt._i2c= {tt._i2c}, irq_pin= {tt._irq_pin}")

touch_x = 0
touch_y = 0
touch_id = 0  # this is used in case of multi-touch
touch_pr = 0

def clr_touch():
    global touch_x, touch_y, touch_id, touch_pr, tt
    touch_x = 0
    touch_y = 0
    touch_id = 0
    touch_pr = 0

    # Clear the touch buffer
    TAG="clr_touch(): "
    cnt = 0
    ts = []
    while True:
        ts = tt.touches
        if my_debug:
            print(TAG+f"ts= {ts}, type(ts)= {type(ts)}")
        if isinstance(ts, list):
            if len(ts) == 0:
                break
        if cnt == 0:
            time.sleep(0.2)
        cnt += 1
        if cnt >= 10:
            if not my_debug:
                print(TAG+f"touch buffer read {cnt} times.")
            break

def ck_touch():
    TAG = "ck_touch(): "
    # if the screen is being touched print the touches
    ts = None
    n = tt.touched
    if n > 0:
        print(TAG+f"nr of touches= {n}")
        ts = tt.touches
        if my_debug:
            print(f"type(ts)= {type(ts)}")
        print(f"ck_touched(): screen touched at: ({ts[0]['x']},{ts[0]['y']}). Pressure: {ts[0]['pressure']}")
    return ts

def main():
    global touch_x, touch_y, touch_id, touch_pr
    TAG = "main(): "
    cnt = 0  # index to touch_dict
    ts = None
    print("\nCircuitpython ESP32-S3-Box touch test.")
    print("Please touch the screen,")
    print("except the bottom line with the red button dot.")
    print(TAG+"\nWaiting for your touches...\n")
    clr_touch()
    while True:
        try:
            while ts is None:
                ts = ck_touch()  # added just for trial
                if ts is None:
                    time.sleep(1)
            t = type(ts)
            if isinstance(ts, list):
                ts_dict = ts[0]
                t = type(ts_dict)
                # print(TAG+f"type(ts_dict)= {t}")
                if isinstance(ts_dict, dict):
                    touch_y = ts_dict['y']
                    touch_x = ts_dict['x']
                    touch_id = ts_dict['id']
                    touch_pr = ts_dict['pressure']
                    if cnt in touch_dict.keys():
                        cnt += 1  # we don't want overwrite existing touch data
                    touch_dict[cnt] = {'x': touch_x, 'y': touch_y, 'id': touch_id, 'pressure': touch_pr}
                    print(TAG+f"Added touch data: id= {touch_id}, at x,y = {touch_x},{touch_y}. Pressure= {touch_pr}")
                    # cleanup for next round
                    clr_touch()
                    ts = None
                    # increase dict key index
                    cnt += 1
                else:
                    print(TAG+f"expected type dict but received type: {t}")
                    raise TypeError
            else:
                print(TAG+f"expected type list but received type: {t}")
                raise TypeError

        except KeyboardInterrupt:
            print("User interrupted. Exiting...")
            break

        time.sleep(1)
        if cnt >= 10:
            break

    le = len(touch_dict)
    if le > 0:
        print(f"\nThere are {le} records in the touch dictionary:")
        print(touch_dict.keys())
        try:
            for k,v in touch_dict.items():
                print("key: {:2d}, x,y = {:3d},{:3d}. id: {:3d}. pressure: {}".format(k, v['x'],
                    v['y'], v['id'], v['pressure']))
        except IndexError as e:
            print(f"IndexError occurred at key= {k}")
    else:
        print("touch dictionary is empty")
    print("Done!\n")
    sys.exit()


if __name__ == '__main__':
    main()


REPL output of board:
>>> import board
>>> dir(board)
['__class__', '__name__', 'BOOT', 'CLK', 'CS', 'CTP_INT', 'DISPLAY', 'G10', 'G11', 'G12', 'G13', 'G14', 'G21', 'G38', 'G39', 'G40', 'G41', 'G42', 'G43', 'G44', 'G9', 'I2S_ADC_SDOUT', 'I2S_CODEC_DSDIN', 'I2S_LRCK', 'I2S_MCLK', 'I2S_SCLK', 'LCD_CS', 'LCD_CTRL', 'LCD_DC', 'LCD_MOSI', 'LCD_RST', 'LCD_SCK', 'MISO', 'MOSI', 'MUTE_STATUS', 'PA_CTRL', 'SCL', 'SCL2', 'SDA', 'SDA2', 'U0RXD', 'U0TXD', 'board_id']

Behavior

The script above runs fine until the "red" circle button in the middle on the bottom of the frame around the display is touched (see image in ´Additional information´ below.
Only a reset of the device can restore the touch functionality.

Description

See also the closed issue adafruit/circuitpython#7095.

Additional information

Adafruit product: https://www.adafruit.com/product/5290

In documation of Espressif the "red" button is referred as "home" button.
The Espressif demo firmware makes use of the "red" circle button.

On the ESPHome website (https://esphome.io/components/touchscreen/tt21100.html),
there is a paragraph named "Binary Sensor". The text is as follows:
"Binary Sensor
In addition to touch areas on the screen configured through the Touchscreen component, the TT21100 supports up to four buttons located outside of the normal touchscreen area. On the ESP32-S3-BOX and the ESP32-S3-Korvo-2-LCD, the red circle below the display is such a button. A binary sensor can be configured to react to touching these buttons."

In circuitpython 8.1.0-beta.2 in the board module there is no "board.HOME" button defined.

Question:

Is there a way to program the "red" circle button for use within Circuitpython,
and to resolve the locking up of touch functionality after touching the "red" circle button?

2023-07-26_ESP32-S3-Box_CPY_script_home_button_problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.