0

STMPE610 and Python3
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

STMPE610 and Python3

by destockwell on Mon Nov 02, 2020 12:47 pm

I have been working with the resistive touchscreen on 2.8" display, and after trying to get it to make sense with MCP3008, have switched to STMPE610, first under SPI. Found that it never could retrieve a valid version number (returned -1). Since my SPI setup works well with the display, I think it is wired correctly.

So, decided to switch to I2C to see if I might have better luck, and find that the initialization DEMANDS a I2C address as it parameter

from adafruit_stmpe610 import Adafruit_STMPE610_I2C
st = Adafruit_STMPE610_I2C() ## demands a parameter

st = Adafruit_STMPE610_I2C(0x41) ## runs to this point, but fails with a message that the 'int' object does not have a 'try_lock' attribute

So, exactly what is the setup for stmpe610 under python3 for the i2c variant.

Another question: is this module compatible with python3? Or do I have to switch back and use python2?

DS

destockwell
 
Posts: 27
Joined: Sun Sep 06, 2020 6:37 pm

Re: STMPE610 and Python3

by adafruit_support_carter on Mon Nov 02, 2020 1:03 pm

The first parameter, which is required, is the I2C bus, not the address. The address would be the second parameter:
https://circuitpython.readthedocs.io/pr ... MPE610_I2C

Python 3 is the *only* thing that is supported. Python 2 is end of life.

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: STMPE610 and Python3

by Aniruddha_Dongare on Thu Dec 24, 2020 2:02 am

"NEED URGENT RESPONSE FOR BELOW POST"
I also have same issue for STMPE610 on spi interface. I have successfully install "https://github.com/adafruit/Adafruit_CircuitPython_STMPE610" library for python3. I have verified the waveforms of spi. My spi interface works fine for adafruit 3.5" 480x320 display. when i tried to communicate with STMPE610 via spi it throws "Failed to find STMPE610! Chip Version 0x0" error. I have verified the connections with arduino uno. it works fine on arduino uno. But when i tried it from Nvidia Jetson nano development kit via SPI interface and same wired connections, it was not able to read the version id correctly. I have tried all the Modes of SPI to communicate with STMPE610.

So i tried the I2C interface to communicate with STMPE610 but I won't get positive ack for 0x41 address mentioned in datasheet.
STMPE610 not detected on I2C lines.

I want to drive it on SPI interface.

Aniruddha_Dongare
 
Posts: 12
Joined: Thu Dec 24, 2020 1:33 am

Re: STMPE610 and Python3

by destockwell on Thu Dec 24, 2020 11:24 am

Aniruddha,

Please share a code snippet. It is very hard to see what might be going on there.
610
One thought...how do you create your STMPE object? In Python3, I create using:

import busio
import board
import time
import digitalio

from adafruit_stmpe610 import Adafruit_STMPE610_SPI

st = Adafruit_STMPE610_SPI( board.SPI(), digitalio.DigitalInOut(board.CE1) )

The first parameter is the setup for the SPI bus, as an object. The second is an object pointing to the line you are using for Chip Select for this device. board.CE0 is default.

Hope this helps...

destockwell
 
Posts: 27
Joined: Sun Sep 06, 2020 6:37 pm

Re: STMPE610 and Python3

by Aniruddha_Dongare on Mon Dec 28, 2020 12:40 am

Hi,

Here is my python3 example code
import busio
import board
import digitalio
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
import time


def init_touch():
st = None
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.CE0)
st = Adafruit_STMPE610_SPI(spi, cs)
return st

def display_image_get_touch(st):
while True:
if not st.buffer_empty:
print(st.read_data())

if __name__ == '__main__':
st = init_touch()
display_image_get_touch(st)

I am using SPI0 and CS0 Pin on Jetson Nano.
I have tried your example code too. But results are same.

Result is:
version 0x0
version 0x0
Traceback (most recent call last):
File "touchscreen_display.py", line 21, in <module>
st = init_touch()
File "touchscreen_display.py", line 12, in init_touch
st = Adafruit_STMPE610_SPI(board.SPI(), cs)
File "/usr/local/lib/python3.6/dist-packages/adafruit_stmpe610.py", line 304, in __init__
"Failed to find STMPE610! Chip Version 0x%x" % version
RuntimeError: Failed to find STMPE610! Chip Version 0x0
Exiting...
Cleaning up pins
Object Clean

Aniruddha_Dongare
 
Posts: 12
Joined: Thu Dec 24, 2020 1:33 am

Re: STMPE610 and Python3

by destockwell on Mon Dec 28, 2020 12:19 pm

Just a thought: sounds like the STMPE works with the Arduino Nano, but not the Jetson Nano.

While the Jetson Nano looks a lot like a Raspberry Pi, it also seems like they have bolted a lot onto that RPi to support the AI functionality. While I do not have a Nano (interesting device...maybe I will get one for fun), I think maybe they are using CE0 for some other function.

I suggest moving your CS function to another pin and see what happens.

destockwell
 
Posts: 27
Joined: Sun Sep 06, 2020 6:37 pm

Re: STMPE610 and Python3

by destockwell on Mon Dec 28, 2020 4:59 pm

Duh (on me)... I think I just figured it out:

The problem is that you are probably using the CS line (CE0) for both the display and for the STMPE610. This cannot work. While multiple SPI devices can share the CLK, MOSI, and MISO lines, they cannot share the same CS line, since this is how the processor selects which device it is talking to.

While the Display and the resistive touchpad are bolted together, to the RPi they are really two separate devices.

So, use CE0 to talk to the display, and CE1 to talk to the STMPE610 (which interprets the resistive touch pad) and you should be good-to-go.

All the best to you.

DS

destockwell
 
Posts: 27
Joined: Sun Sep 06, 2020 6:37 pm

Re: STMPE610 and Python3

by Aniruddha_Dongare on Tue Dec 29, 2020 1:45 am

Hello,

Right now i have not interfaced Display with Jetson Nano. I have only interface STMPE610 touch driver Module on SPI lines. Jetson Nano has 2 SPI ports and 4 CS pins. I have tried both the SPI ports and all CS pins, But Result is same.

Once i get correct Chip Id of STMPE610 touch driver on SPI then I will interface it with my display.

Aniruddha_Dongare
 
Posts: 12
Joined: Thu Dec 24, 2020 1:33 am

Re: STMPE610 and Python3

by Aniruddha_Dongare on Wed Dec 30, 2020 9:15 am

Hello,

I have one doubt regarding STMPE610 python3 library. Suppose i bypass the version id and directly try to read touch co-ordinate register. Does that data is valid or not?

Aniruddha_Dongare
 
Posts: 12
Joined: Thu Dec 24, 2020 1:33 am

Re: STMPE610 and Python3

by destockwell on Wed Dec 30, 2020 10:59 am

If you cannot read the version, the data will probably not be good.

I am away from my home office and do not have access to my full setup. Will be back next week. In the meantime, I suggest you verify your connections to the board, including power and ground. Also suggest you connect the leads to X+, Y+, X-, Y- on the resistive touch panel.

Good luck.

destockwell
 
Posts: 27
Joined: Sun Sep 06, 2020 6:37 pm

Re: STMPE610 and Python3

by Aniruddha_Dongare on Thu Dec 31, 2020 9:29 am

Hi Destockwell,

I have verified all the connection including power and ground connections. I have check all the voltage levels including "MODE" Pin too.
I have interface LCD on SPI0 and STMPE610 on SPI1. Integrate both codes. My LCD works fine,but STMPE610 gives the same error.

I tried to bypass the version id and read the data from register but it also not worked as per you said.

Aniruddha_Dongare
 
Posts: 12
Joined: Thu Dec 24, 2020 1:33 am

Re: STMPE610 and Python3

by adafruit_support_carter on Mon Jan 04, 2021 2:52 pm

@Aniruddha_Dongare Please start a new thread for your issue and post photos of your setup.

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: STMPE610 and Python3

by destockwell on Mon Jan 04, 2021 4:20 pm

Thanks, Admin Carter

destockwell
 
Posts: 27
Joined: Sun Sep 06, 2020 6:37 pm

Re: STMPE610 and Python3

by Aniruddha_Dongare on Tue Jan 05, 2021 1:24 am

Hi,

I have created new thread for my issue..... Thanks Destockwell for your support....

Aniruddha_Dongare
 
Posts: 12
Joined: Thu Dec 24, 2020 1:33 am

Please be positive and constructive with your questions and comments.