-
Notifications
You must be signed in to change notification settings - Fork 1
/
simpletest.py
51 lines (44 loc) · 1.73 KB
/
simpletest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Simple demo of of the ADXL345 accelerometer library. Will print the X, Y, Z
# axis acceleration values every half second.
# Author: Tony DiCola
# License: Public Domain
import time
# Import the ADXL345 module.
import Adafruit_ADXL345
# Create an ADXL345 instance.
accel = Adafruit_ADXL345.ADXL345()
# Alternatively you can specify the device address and I2C bus with parameters:
#accel = Adafruit_ADXL345.ADXL345(address=0x54, busnum=2)
# You can optionally change the range to one of:
# - ADXL345_RANGE_2_G = +/-2G (default)
# - ADXL345_RANGE_4_G = +/-4G
# - ADXL345_RANGE_8_G = +/-8G
# - ADXL345_RANGE_16_G = +/-16G
# For example to set to +/- 16G:
#accel.set_range(Adafruit_ADXL345.ADXL345_RANGE_16_G)
# Or change the data rate to one of:
# - ADXL345_DATARATE_0_10_HZ = 0.1 hz
# - ADXL345_DATARATE_0_20_HZ = 0.2 hz
# - ADXL345_DATARATE_0_39_HZ = 0.39 hz
# - ADXL345_DATARATE_0_78_HZ = 0.78 hz
# - ADXL345_DATARATE_1_56_HZ = 1.56 hz
# - ADXL345_DATARATE_3_13_HZ = 3.13 hz
# - ADXL345_DATARATE_6_25HZ = 6.25 hz
# - ADXL345_DATARATE_12_5_HZ = 12.5 hz
# - ADXL345_DATARATE_25_HZ = 25 hz
# - ADXL345_DATARATE_50_HZ = 50 hz
# - ADXL345_DATARATE_100_HZ = 100 hz (default)
# - ADXL345_DATARATE_200_HZ = 200 hz
# - ADXL345_DATARATE_400_HZ = 400 hz
# - ADXL345_DATARATE_800_HZ = 800 hz
# - ADXL345_DATARATE_1600_HZ = 1600 hz
# - ADXL345_DATARATE_3200_HZ = 3200 hz
# For example to set to 6.25 hz:
#accel.set_data_rate(Adafruit_ADXL345.ADXL345_DATARATE_6_25HZ)
print('Printing X, Y, Z axis values, press Ctrl-C to quit...')
while True:
# Read the X, Y, Z axis acceleration values and print them.
x, y, z = accel.read()
print('X={0}, Y={1}, Z={2}'.format(x, y, z))
# Wait half a second and repeat.
time.sleep(0.5)