@@ -135,11 +135,7 @@ class Adafruit_STMPE610:
135
135
A driver for the STMPE610 Resistive Touch sensor.
136
136
"""
137
137
def __init__ (self ):
138
- """Check the STMPE610 was found"""
139
- # Check device version.
140
- version = self .get_version
141
- if _STMPE_VERSION != version :
142
- raise RuntimeError ('Failed to find STMPE610! Chip Version 0x%x' % version )
138
+ """Reset the controller"""
143
139
self ._write_register_byte (_STMPE_SYS_CTRL1 , _STMPE_SYS_CTRL1_RESET )
144
140
time .sleep (.001 )
145
141
@@ -257,6 +253,10 @@ def __init__(self, i2c, address=_STMPE_ADDR):
257
253
"""
258
254
import adafruit_bus_device .i2c_device as i2c_device
259
255
self ._i2c = i2c_device .I2CDevice (i2c , address )
256
+ # Check device version.
257
+ version = self .get_version
258
+ if _STMPE_VERSION != version :
259
+ raise RuntimeError ('Failed to find STMPE610! Chip Version 0x%x' % version )
260
260
super ().__init__ ()
261
261
262
262
def _read_register (self , register , length ):
@@ -278,12 +278,20 @@ class Adafruit_STMPE610_SPI(Adafruit_STMPE610):
278
278
"""
279
279
SPI driver for the STMPE610 Resistive Touch sensor.
280
280
"""
281
- def __init__ (self , spi , cs , baudrate = 100000 ):
281
+ def __init__ (self , spi , cs , baudrate = 1000000 ):
282
282
"""
283
- Check the STMPE610 was found,Default clock rate is 100000 but can be changed with 'baudrate'
283
+ Check the STMPE610 was found,Default clock rate 1000000 - can be changed with 'baudrate'
284
284
"""
285
285
import adafruit_bus_device .spi_device as spi_device
286
286
self ._spi = spi_device .SPIDevice (spi , cs , baudrate = baudrate )
287
+ # Check device version.
288
+ version = self .get_version
289
+ if _STMPE_VERSION != version :
290
+ # if it fails try SPI MODE 1 -- that is what Arduino does
291
+ self ._spi = spi_device .SPIDevice (spi , cs , baudrate = baudrate , polarity = 0 , phase = 1 )
292
+ version = self .get_version
293
+ if _STMPE_VERSION != version :
294
+ raise RuntimeError ('Failed to find STMPE610! Chip Version 0x%x' % version )
287
295
super ().__init__ ()
288
296
289
297
def _read_register (self , register , length ):
0 commit comments