1#!/usr/bin/env python
2#-----------------------------------------------------------------------------
3# ex5_qwiic_adxl313_standby.py
4#
5# Simple Example for the Qwiic ADXL313 DeviceSet that Shows how to switch the sensor
6# between stanby mode and measure mode.
7# This example will put the device in measure mode and print 100 readings to terminal,
8# Then enter standby mode for 5 seconds.
9# Then loop.
10# Note, the typical current required in each mode is as follows:
11# Standby: 0.1uA
12# Measure: 55-170uA
13#------------------------------------------------------------------------
14#
15# Written by SparkFun Electronics, October 2020
16#
17# This python library supports the SparkFun Electroncis qwiic
18# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
19# board computers.
20#
21# More information on qwiic is at https://www.sparkfun.com/qwiic
22#
23# Do you like this library? Help support SparkFun. Buy a board!
24#
25#==================================================================================
26# Copyright (c) 2019 SparkFun Electronics
27#
28# Permission is hereby granted, free of charge, to any person obtaining a copy
29# of this software and associated documentation files (the "Software"), to deal
30# in the Software without restriction, including without limitation the rights
31# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32# copies of the Software, and to permit persons to whom the Software is
33# furnished to do so, subject to the following conditions:
34#
35# The above copyright notice and this permission notice shall be included in all
36# copies or substantial portions of the Software.
37#
38# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44# SOFTWARE.
45#==================================================================================
46# Example 5
47#
48
49from __future__ import print_function
50import qwiic_adxl313
51import time
52import sys
53
54def runExample():
55
56 print("\nSparkFun Adxl313 Example 5 - Standby mode and measure mode.\n")
57 myAdxl = qwiic_adxl313.QwiicAdxl313()
58
59 if myAdxl.connected == False:
60 print("The Qwiic ADXL313 device isn't connected to the system. Please check your connection", \
61 file=sys.stderr)
62 return
63 else:
64 print("Device connected successfully.")
65
66 while True:
67 # enter measure mode
68 print("Entering measure mode.")
69 myAdxl.measureModeOn()
70 for i in range(100):
71
72 myAdxl.updateIntSourceStatuses(); # this will update all INTSOURCE statuses.
73
74 if myAdxl.ADXL313_INTSOURCE_DATAREADY:
75 myAdxl.readAccel() # read all axis from sensor, note this also updates all instance variables
76 print(\
77 '{: 06d}'.format(myAdxl.x)\
78 , '\t', '{: 06d}'.format(myAdxl.y)\
79 , '\t', '{: 06d}'.format(myAdxl.z)\
80 )
81 else:
82 print("Waiting for data.")
83 time.sleep(0.05)
84 print("Endering Standby Mode")
85 myAdxl.standby()
86 time.sleep(5) # 5 seconds of standby... really saving power during this time (0.1uA)
87
88
89if __name__ == '__main__':
90 try:
91 runExample()
92 except (KeyboardInterrupt, SystemExit) as exErr:
93 print("\nEnding Example 1")
94 sys.exit(0)
95
96