Simple test

Ensure your device works with this simple test.

examples/msa301_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_msa301

i2c = board.I2C()  # uses board.SCL and board.SDA
msa = adafruit_msa301.MSA301(i2c)

while True:
    print("%f %f %f" % msa.acceleration)
    time.sleep(0.5)

Tap test

Check out the tap capability with this example.

examples/msa301_tap_example.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import adafruit_msa301

i2c = board.I2C()  # uses board.SCL and board.SDA
msa = adafruit_msa301.MSA301(i2c)

msa.enable_tap_detection()

while True:
    if msa.tapped:
        print("Single Tap!")
    time.sleep(0.01)