Unable to use STMPE610 on 2.4TFT Featherwing with Feather M4

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kenrickj84
 
Posts: 5
Joined: Wed Mar 15, 2017 3:46 am

Unable to use STMPE610 on 2.4TFT Featherwing with Feather M4

Post by kenrickj84 »

I haven't been able to initialize the STMPE610 on my 2.4 TFT Featherwing using a Feather M4. I have two feather M4s and have tried resoldering one, and then using the other, but neither one is able to communicate with the STMPE610. Trying to run the simpletest.py example from GitHub I get a runtime error
Traceback (most recent call last):
File "main.py", line 8, in <module>
File "adafruit_stmpe610.py", line 287, in __init__
File "adafruit_stmpe610.py", line 142, in __init__
RuntimeError: Failed to find STMPE610! Chip Version 0x8081
It is only a problem with my new M4s, I was able to initialize and use the STMPE610 module with my M0 adalogger.

Since I have enough RAM on the M4 I've tried using the .py code off of GitHub instead of the .mpy from the library bundle. uncommenting the print statement in the _read_register function with the working M0 adalogger outputs:
main.py output:
$80 => ['0x8']
$81 => ['0x11']
Go Ahead - Touch the Screen - Make My Day!
When I do the same thing with both M4s it outputs:
main.py output:
$80 => ['0x80']
$81 => ['0x81']
Traceback (most recent call last):
File "main.py", line 8, in <module>
File "/lib/my_stmpe610.py", line 285, in __init__
File "/lib/my_stmpe610.py", line 140, in __init__
RuntimeError: Failed to find STMPE610! Chip Version 0x8081
I'm not sure, but I would think it returns the same version number, but the M4 is reading it incorrectly.

I was able to use the M4 board to talk to the TFTs ILI934 chip using SPI, but not the STMPE610.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

Can you try increasing the baudrate for the SPI interface to the STMPE610
try raising it to 1MHz

Code: Select all

st=Adafruit_STMPE610_SPI(spi,cs,baudrate=1000000)
I ran into this problem on the nrf52 boards and it may be an issue for the M4 as well.

see https://github.com/adafruit/circuitpython/issues/1005

User avatar
kenrickj84
 
Posts: 5
Joined: Wed Mar 15, 2017 3:46 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by kenrickj84 »

Unfortunately I'm still getting the same behavior. I had suspected a baud rate issue, but any changes I've made to that haven't seemed to help. The thing I found interesting is that the _read_byte function is returning the number of the registers "$80 => 0x80" and "$81 =>0x81". Not sure if that's significant, but it always returns the same values.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

Thanks for trying that. I’ll set up a test to see if I can reproduce this tonight or tomorrow. There is another known issue with this driver https://github.com/adafruit/Adafruit_Ci ... 0/issues/3 . Usually, if this is the problem, it works ok sometimes and fails sometimes. Possibly, the M4 is more prone to this than the M0.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

I just connected a feather m4 express to my 2.4 inch tft featherwing and ran the stmpe610_simpletest

Code: Select all

import busio
import board
import digitalio
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
spi=busio.SPI(board.SCK,board.MOSI,board.MISO)
cs = digitalio.DigitalInOut(board.D6)
st=Adafruit_STMPE610_SPI(spi,cs)
print("Go Ahead - Touch the Screen - Make My Day!")
while True:
    if not st.buffer_empty:
        print(st.read_data())
without any problem.

I am also able to run the "paint" demo

Code: Select all

"""
Simple painting demo that draws on an Adafruit capacitive touch shield with
ILI9341 display and STMPE610 resistive touch driver
"""

import busio
import board
import digitalio
import adafruit_stmpe610
from adafruit_rgb_display import ili9341, color565

# Create library object using our Bus I2C & SPI port
i2c = busio.I2C(board.SCL, board.SDA)
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Adafruit Metro M0 + 2.8" Capacitive touch shield
cs_pin = digitalio.DigitalInOut(board.D9)
dc_pin = digitalio.DigitalInOut(board.D10)

# Initialize display
display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin)
# Fill with black!
display.fill(color565(0, 0, 0))

st_cs_pin = digitalio.DigitalInOut(board.D6)
st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi,st_cs_pin)

while True:
    if st.touched:
        while not st.buffer_empty:
            ts = st.touches
            for point in ts:
                # perform transformation to get into display coordinate system!
                y = point['y']
                x = 4096 - point['x']
                x = 2 * x // 30
                y = 8 * y // 90
                display.fill_rectangle(x-2, y-2, 4, 4, color565(255, 0, 0))
both work OK even at 100Khz baudrate.

I will go ahead and try to fix the known issue with the SPI mode but I'm not sure if that isi what you are seeing or not. For me it only happens infrequently and I have not seen it yet on the M4.

Edited to add - I am using the recently released 3.0.0 version of CircuitPython. https://github.com/adafruit/circuitpyth ... /tag/3.0.0

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

can you post your code ? I'm not sure what is producing the output you show
main.py output:
$80 => ['0x8'] <<< what produces this line and the next?
$81 => ['0x11']
Go Ahead - Touch the Screen - Make My Day!

User avatar
kenrickj84
 
Posts: 5
Joined: Wed Mar 15, 2017 3:46 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by kenrickj84 »

OK, I'll try to post everything I know about what I'm seeing.

First off, what I'm using
Adafruit CircuitPython 3.0.0-rc.0 on 2018-06-18; Adafruit Feather M4 Express with samd51j19
If I run the exact same code you posted (simpletest,py with the adafruit_stmpe610.mpy module) I get the following output:
main.py output:
Traceback (most recent call last):
File "main.py", line 7, in <module>
File "adafruit_stmpe610.py", line 287, in __init__
File "adafruit_stmpe610.py", line 142, in __init__
RuntimeError: Failed to find STMPE610! Chip Version 0x8081
If I then change the code to switch from the frozen module to the driver code from (https://github.com/adafruit/Adafruit_Ci ... tmpe610.py) and go in an edit the _read_register function uncommenting the print statement

Code: Select all

    def _read_register(self, register, length):
        """Low level register reading over SPI, returns a list of values"""
        register = (register | 0x80) & 0xFF  # Read single, bit 7 high.
        with self._spi as spi:
            spi.write(bytearray([register]))
            result = bytearray(length)
            spi.readinto(result)
            print("$%02X => %s" % (register, [hex(i) for i in result]))
            return result
I get the following output:
main.py output:
$80 => ['0x80']
$81 => ['0x81']
version 0x8081
Traceback (most recent call last):
File "main.py", line 7, in <module>
File "/lib/my_stmpe610.py", line 285, in __init__
File "/lib/my_stmpe610.py", line 140, in __init__
RuntimeError: Failed to find STMPE610! Chip Version 0x8081
I'm gonna try reinstalling circuitpython and see what happens.

Edit: The specific output you asked about was on my adalogger. I essentially did the same thing, I used the driver from github, and stripped out all of the I2C protocol to save space, uncommented the _read_register print statement and removed the loop from the main.py (to keep from continually printing register values, since the code works) so I have:

Code: Select all

import busio
import board
import digitalio
from my_stmpe610 import Adafruit_STMPE610_SPI
spi=busio.SPI(board.SCK,board.MOSI,board.MISO)
cs = digitalio.DigitalInOut(board.D6)
st=Adafruit_STMPE610_SPI(spi,cs)
print("Go Ahead - Touch the Screen - Make My Day!")
Last edited by kenrickj84 on Fri Jul 13, 2018 1:30 pm, edited 1 time in total.

User avatar
kenrickj84
 
Posts: 5
Joined: Wed Mar 15, 2017 3:46 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by kenrickj84 »

Updating to
Adafruit CircuitPython 3.0.0 on 2018-07-09; Adafruit Feather M4 Express with samd51j19
didn't change anything, I'm still getting the same behavior.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

hmm - gotta love this kind of bug.... I'll keep poking at it and try to reproduce this and determine if what you are seeing is the known issue - Hopefully fixing that will take care of it.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

So far, I have not been able to reproduce this. I did occasionally have the known SPI mode issue appear when using a feather52832 (nrf52) board but the erroneous Chip Id reported was not failing in the same way you have reported. I think I have a fix for this issue and it s under review -- the "pull request" for the update is here if you wan to t try it. https://github.com/adafruit/Adafruit_Ci ... 610/pull/4

User avatar
kenrickj84
 
Posts: 5
Joined: Wed Mar 15, 2017 3:46 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by kenrickj84 »

Hey, it works now! As a sanity check I added a print statement after it switches modes:

Code: Select all

class Adafruit_STMPE610_SPI(Adafruit_STMPE610):
    """
    SPI driver for the STMPE610 Resistive Touch sensor.
    """
    def __init__(self, spi, cs, baudrate=1000000):
        """
        Check the STMPE610 was found,Default clock rate 1000000 - can be changed with 'baudrate'
        """
        import adafruit_bus_device.spi_device as spi_device
        self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate)
        # Check device version.
        version = self.get_version
        if _STMPE_VERSION != version:
            print("I'm switching mode!")
            # if it fails try SPI MODE 1  -- that is what Arduino does
            self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate, polarity=0, phase=1)
            version = self.get_version
            if _STMPE_VERSION != version:
                raise RuntimeError('Failed to find STMPE610! Chip Version 0x%x' % version)
        super().__init__()
and I see that it does in fact have to switch modes to work:
main.py output:
I'm switching mode!
Go Ahead - Touch the Screen - Make My Day!
Thanks for the help, not sure why, but both of my boards want to communicate with this chip in mode 1. Back up and running!

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »

Great news! Glad it is working. There should be a new release of the driver with this implemented coming out in the next few days.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: Unable to use STMPE610 on 2.4TFT Featherwing with Feathe

Post by jerryn »


Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”