diff --git a/.pylintrc b/.pylintrc index 946d694..cb8d23d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -155,7 +155,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local # (useful for modules/projects where namespaces are manipulated during runtime # and thus existing member attributes cannot be deduced by static analysis. It # supports qualified module names, as well as Unix pattern matching. -ignored-modules= +ignored-modules=board # Show a hint with possible names when a member name was not found. The aspect # of finding the hint is based on edit distance. diff --git a/examples/lis3dh_simpletest.py b/examples/lis3dh_simpletest.py index 6bd36ef..a4a863f 100644 --- a/examples/lis3dh_simpletest.py +++ b/examples/lis3dh_simpletest.py @@ -1,35 +1,24 @@ -# Accelerometer example. -# Reads the accelerometer x, y, z values and prints them every tenth of a second. -# Open the serial port after running to see the output printed. -# Author: Tony DiCola import time import board +import digitalio import busio import adafruit_lis3dh - -# Uncomment _one_ of the hardware setups below depending on your wiring: - # Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available; # otherwise check I2C pins. -# pylint: disable=no-member if hasattr(board, 'ACCELEROMETER_SCL'): i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) - lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19) + int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) + lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) else: i2c = busio.I2C(board.SCL, board.SDA) - lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c) - -# Software I2C setup: -#import bitbangio -#i2c = bitbangio.I2C(board.SCL, board.SDA) -#lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c) + int1 = digitalio.DigitalInOut(board.D9) # Set this to the correct pin for the interrupt! + lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) # Hardware SPI setup: -#import busio -#spi = busio.SPI(board.SCK, board.MOSI, board.MISO) -#cs = busio.DigitalInOut(board.D6) # Set to appropriate CS pin! -#lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs) +# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) +# cs = digitalio.DigitalInOut(board.D9) # Set to appropriate CS pin! +# lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs) # Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G). @@ -40,6 +29,6 @@ # Read accelerometer values (in m / s ^ 2). Returns a 3-tuple of x, y, # z axis values. Divide them by 9.806 to convert to Gs. x, y, z = [value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration] - print('x = {}G, y = {}G, z = {}G'.format(x, y, z)) + print("x = %0.3f G, y = %0.3f G, z = %0.3f G" % (x, y, z)) # Small delay to keep things responsive but give time for interrupt processing. time.sleep(0.1) diff --git a/examples/tap.py b/examples/tap.py index 2ee96f3..8078db4 100644 --- a/examples/tap.py +++ b/examples/tap.py @@ -1,38 +1,20 @@ -# Tap detection example. -# Will loop forever printing when a single or double click is detected. -# Open the serial port after running to see the output printed. -# Author: Tony DiCola +import time import board import busio import digitalio import adafruit_lis3dh - -# Uncomment _one_ of the hardware setups below depending on your wiring: - # Hardware I2C setup. Use the CircuitPlayground built-in accelerometer if available; # otherwise check I2C pins. -# pylint: disable=no-member if hasattr(board, 'ACCELEROMETER_SCL'): i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA) int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT) lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, address=0x19, int1=int1) else: i2c = busio.I2C(board.SCL, board.SDA) - int1 = digitalio.DigitalInOut(board.D10) # Set this to the correct pin for the interrupt! + int1 = digitalio.DigitalInOut(board.D9) # Set this to the correct pin for the interrupt! lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1) -# Software I2C setup: -# import bitbangio -# i2c = bitbangio.I2C(board.SCL, board.SDA) -# lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c) - -# Hardware SPI setup: -# import busio -# spi = busio.SPI(board.SCK, board.MOSI, board.MISO) -# cs = busio.DigitalInOut(board.D6) # Set to appropriate CS pin! -# lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs) - # Set range of accelerometer (can be RANGE_2_G, RANGE_4_G, RANGE_8_G or RANGE_16_G). lis3dh.range = adafruit_lis3dh.RANGE_8_G @@ -52,3 +34,4 @@ while True: if lis3dh.tapped: print('Tapped!') + time.sleep(0.01)