GithubHelp home page GithubHelp logo

adafruit / adafruit_circuitpython_stmpe610 Goto Github PK

View Code? Open in Web Editor NEW
1.0 20.0 11.0 159 KB

Adafruit CircuitPython driver for the STMPE610 resistive touchscreen controller

License: MIT License

Python 100.00%
hacktoberfest

adafruit_circuitpython_stmpe610's Introduction

Introduction

Documentation Status Discord Build Status Code Style: Black

Adafruit CircuitPython module for the STMPE610 Resistive Touch Screen Controller

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.

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-stmpe610

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

sudo pip3 install adafruit-circuitpython-stmpe610

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-stmpe610

Usage Example

See examples in github repository: https://github.com/adafruit/Adafruit_CircuitPython_STMPE610/tree/master/examples

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_stmpe610's People

Contributors

brennen avatar cedargrovestudios avatar dhalbert avatar evaherrada avatar foamyguy avatar jerryneedell avatar jpecor avatar kattni avatar ladyada avatar makermelissa avatar prcutler avatar rtwfroody avatar siddacious avatar sommersoft avatar tannewt avatar tcfranks avatar tekktrik avatar

Stargazers

 avatar

Watchers

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

adafruit_circuitpython_stmpe610's Issues

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_stmpe610.py:162
  • adafruit_stmpe610.py:166
  • adafruit_stmpe610.py:172
  • adafruit_stmpe610.py:229
  • adafruit_stmpe610.py:243
  • adafruit_stmpe610.py:252
  • adafruit_stmpe610.py:264
  • adafruit_stmpe610.py:289
  • adafruit_stmpe610.py:299

Device reset during initialization causes trouble

It seems that there is an "unlucky" period during and shortly after the initialization of this driver. If the device resets during this period the touch chip seems to get "locked up" into a state where it will always cause this error:

Traceback (most recent call last):
  File "code.py", line 32, in <module>
  File "adafruit_stmpe610.py", line 281, in __init__
RuntimeError: Failed to find STMPE610! Chip Version 0x8

I am using:

Adafruit CircuitPython 6.2.0-beta.4 on 2021-03-18; Adafruit Feather RP2040 with rp2040

With a 3.5" FeatherWing. and the following test code:

import board
import time
import digitalio
import displayio
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
from adafruit_hx8357 import HX8357

COUNTDOWN = 5
for i in range(COUNTDOWN):
    print("waiting {}".format(COUNTDOWN-i))
    time.sleep(0.7)


displayio.release_displays()
spi = board.SPI()
cs = board.D9
dc = board.D10

ts_cs = board.D6
sd_cs = board.D5

ts_cs = digitalio.DigitalInOut(ts_cs)

_display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)

display = HX8357(_display_bus, width=480, height=320)

st = Adafruit_STMPE610_SPI(spi, ts_cs)

print("Go Ahead - Touch the Screen - Make My Day!")
while True:
    if not st.buffer_empty:
        print(st.read_data())

I am able to enter the state reliably with this set up. Here are the series of events I see:

  1. Plug in device to PC
  2. Device immediately boots and begins running code.py
  3. If I am quick I can see "detected new device" in Mu and open the serial console
  4. I can see the last few numbers from the countdown get printed
  5. The screen gets initialized and I see "Go Ahead - Touch the Screen - Make My Day!" printed briefly.
  6. CIRCUITPY drive appears to my OS
  7. The device resets again. I suspect the OS may have written something automatically to cause it. But I am not certain.
  8. Device reconnects. I see "detected new device" in Mu again and can open the serial console.
  9. Countdown finishes normally. Display turns on and shows the "Failed to find" Runtime error.
  10. at this point I can CTRL-C then CTRL-D over and over and reliably get the same error every time. To get back to a working state I can use the reset button on the device, or unplug / replug. But if nothing else changes it will end up right back in this state again.

I could record a video of this sequence if it would be helpful.

The Chip Version {} number that it that it prints is not always the same.

If the time of the countdown is increased it makes it more likely that the device wont hit his "unlucky" period during the initialization. With a high enough countdown it will reliably boot and work correctly every time because it's never having a chance to try setting up the touch screen before the "extra" reset happens.

If my hunch about the OS writing something to trigger the "extra" reset is correct then I suppose that is really at fault here. However I am left wondering if there is something we could within the driver to try to be more resilient to badly timed resets. Or if there would be some way to more safely catch this error and recover back to a working state without needing the reset or unplug/replug.

Another way I see it get triggered sometimes is with scripts that don't have a wait time built in, when pasting multiple files onto the device (i.e. a module or several image assets) the device resets several times as the different files get finished writing.

Adding enough wait time before doing anything seems to be a reliable solution, but means that you have to wait several seconds before being able to do anything each time it runs.

Does this work with STMPE811?

I would like to use this library with an Adafruit 3.5" Pi TFT Display on my raspberry pi.

As shown in the picture, this product uses an STMPE811 even though the silkscreen on the board says is has an STMPE610.
image

Will this library still work? I am not sure how much variation there is between the STMPE ICs.

SPI mode sometimes wrong - CHIP ID check fails

There is a known issue with the way the STMPE610 is initialized for SPI. Occasionally, it syncs to the wrong clock edge (SPI Mode 1 instead of SPI Mode 0). The Arduino version detects and corrects for this by switching the SPI Mode. https://github.com/adafruit/Adafruit_STMPE610/blob/master/Adafruit_STMPE610.cpp#L103

This driver has not yet implemented this and it results in a failure to detect the CHIP ID correctly. Usually retrying the initialization or power cycling the board gets it come up in the right state.

Error initializing `Adafruit_STMPE610_SPI`

Hardware:

We are getting this error when we try to run the “simple test” code:

Traceback (most recent call last):
  File "../Adafruit_CircuitPython_STMPE610/examples/stmpe610_simpletest.py", line 12, in <module>
    st = Adafruit_STMPE610_SPI(spi, cs)
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/adafruit_stmpe610.py", line 278, in __init__
    version = self.get_version
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/adafruit_stmpe610.py", line 193, in get_version
    v_1 = self._read_byte(0)
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/adafruit_stmpe610.py", line 164, in _read_byte
    return self._read_register(register, 1)[0]
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/adafruit_stmpe610.py", line 291, in _read_register
    spi.write(bytearray([register]))
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/busio.py", line 317, in write
    return self._spi.write(buf, start, end)
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 81, in write
    self._spi.mode = self.mode
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/Adafruit_PureIO/spi.py", line 355, in mode
    self._ioctl(SPI._IOC_WR_MODE, mode)
  File "/home/alex/mtm-chess/env/lib/python3.8/site-packages/Adafruit_PureIO/spi.py", line 224, in _ioctl
    ioctl(self.handle, ioctl_bytes, arg)
OSError: [Errno 22] Invalid argument

We tried:

  • Replacing GPIO wires
  • Using a new touch controller
  • Using a new touch overlay
  • Flipping connection to touch controller

Can you please help? :)

Add a `touch_point` parameter to `adafruit_stmpe610` for use with `adafruit_button`

I have a slightly revised version of adafruit_stmpe610 that is working nicely with adafruit_button. Without changing the existing parameters and kwargs, I added a touch_point parameter and instantiation kwargs for display size and touch calibration (duplicating how adafruit_touchscreen works) as well as a new argument for display rotation. Defining the rotation at instantiation greatly simplifies usage particularly with on-screen buttons, something I'm planning to suggest for adafruit_touchscreen as well.

The current round of tests are being conducted using the 2.4" (#3315) and 3.5" (#3651) TFT wings with a Feather M4 Express running v7.1.1. The touchscreen's x-axis is reversed on the 3.5" TFT, so I'm planning to add another kwarg to flip the minimum/maximum touch axis values to accommodate the wiring difference.

Before proceeding with a PR, I need to know if the 2.4" and 3.5" TFT wings are the only Adafruit products using the STMPE610 controller. I wasn't able to find any others, but wanted to be certain before adding the touch axis flip kwarg.

@jerryneedell and @FoamyGuy : can you help?

Thanks!

new instantiation example without the proposed axis flip kwarg:

ts = adafruit_stmpe610.Adafruit_STMPE610_SPI(
            spi, ts_cs_pin, calibration=((357, 3812), (390, 3555)),
            size=(display.width, display.height), display_rotation=display.rotation,
        )

OSError: [Errno 22] Invalid argument - on Buster

Hello!

I have set up the STMPE610 on a pi zero WH running the latest version or Raspbian (buster release 10). I have installed the latest pip dependencies (Adafruit CircuitPython, Bus Device, Register). I have enabled SPI in the boot config.

Running the simpletest with sudo python3 connected to a beautiful, new Adafruit touchscreen overlay gives me the following error:

(env) pi@raspberrypi:~/Adafruit_CircuitPython_STMPE610 $ sudo python3 examples/stmpe610_simpletest.py 
Traceback (most recent call last):
  File "examples/stmpe610_simpletest.py", line 12, in <module>
    st = Adafruit_STMPE610_SPI(spi, cs)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 278, in __init__
    version = self.get_version
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 193, in get_version
    v_1 = self._read_byte(0)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 164, in _read_byte
    return self._read_register(register, 1)[0]
  File "/usr/local/lib/python3.7/dist-packages/adafruit_stmpe610.py", line 291, in _read_register
    spi.write(bytearray([register]))
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 325, in write
    return self._spi.write(buf, start, end)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 81, in write
    self._spi.mode = self.mode
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 355, in mode
    self._ioctl(SPI._IOC_WR_MODE, mode)
  File "/usr/local/lib/python3.7/dist-packages/Adafruit_PureIO/spi.py", line 224, in _ioctl
    ioctl(self.handle, ioctl_bytes, arg)
OSError: [Errno 22] Invalid argument

Things I have tried:

  • Verified wires/connections/soldering
  • Restarted the pi
  • Successfully ran the blinka test

Can't wait to get my touchscreen to make my day and get my project rolling!! Any other ideas for troubleshooting this error? Happy to provide more info. Much appreciated.

Should I2C support be removed

Does anyone use the I2C mode? It is available on the now discontinued and unavailable breakout board but it is not used on any of the tft displays that have the stpme chips built in. They all use SPI.

In addition, the I2C implementation can be flaky and I wonder if it is worthwhile troubleshooting it.

When using the stmpe610 breakout in I2C mode, there are occasional errors

>>> import stmpe610_simpletest_i2c
Go Ahead - Touch the Screen - Make My Day!
(1266, 2298, 130)
(1247, 2296, 18)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "stmpe610_simpletest_i2c.py", line 14, in <module>
  File "adafruit_stmpe610.py", line 213, in buffer_empty
  File "adafruit_stmpe610.py", line 164, in _read_byte
  File "adafruit_stmpe610.py", line 246, in _read_register
OSError: [Errno 5] Input/output error
>>> 

This was on a GrandCentral M4 running the simpletest in I2C mode.
I have also seen "Error 19 - Unsupported Operations) errors on a QTPY esp32s2

I don't think this is new. I think I saw this in the past but did not open an issue.

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.