Example 4: Low Power Mode

examples/ex4_qwiic_adxl313_low_power_mode.py
  1#!/usr/bin/env python
  2#-----------------------------------------------------------------------------
  3# ex4_qwiic_adxl313_low_power_mode.py
  4#
  5#   Shows how to use Low Power feature. 
  6#   In addition to turning on low power mode, you will also want to consider
  7#   bandwidth rate. This will affect your results in low power land.
  8#   In this example, we will turn on low power mode and set BW to 12.5Hz.
  9#   Then we will only take samples at or above 12.5Hz (so we don't miss samples)
 10#
 11#------------------------------------------------------------------------
 12#
 13# Written by  SparkFun Electronics, October 2020
 14# 
 15# This python library supports the SparkFun Electroncis qwiic 
 16# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
 17# board computers. 
 18#
 19# More information on qwiic is at https://www.sparkfun.com/qwiic
 20#
 21# Do you like this library? Help support SparkFun. Buy a board!
 22#
 23#==================================================================================
 24# Copyright (c) 2019 SparkFun Electronics
 25#
 26# Permission is hereby granted, free of charge, to any person obtaining a copy 
 27# of this software and associated documentation files (the "Software"), to deal 
 28# in the Software without restriction, including without limitation the rights 
 29# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 30# copies of the Software, and to permit persons to whom the Software is 
 31# furnished to do so, subject to the following conditions:
 32#
 33# The above copyright notice and this permission notice shall be included in all 
 34# copies or substantial portions of the Software.
 35#
 36# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 37# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 38# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 39# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 40# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 41# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
 42# SOFTWARE.
 43#==================================================================================
 44# Example 4
 45#
 46
 47from __future__ import print_function
 48import qwiic_adxl313
 49import time
 50import sys
 51
 52def runExample():
 53
 54	print("\nSparkFun Adxl313  Example 4 - Low power mode ON with 12.5Hz bandwidth.\n")
 55	myAdxl = qwiic_adxl313.QwiicAdxl313()
 56
 57	if myAdxl.connected == False:
 58		print("The Qwiic ADXL313 device isn't connected to the system. Please check your connection", \
 59			file=sys.stderr)
 60		return
 61	else:
 62		print("Device connected successfully.")        
 63  
 64	myAdxl.standby()	# Must be in standby before changing settings.
 65						# This is here just in case we already had sensor powered and/or
 66						# configured from a previous setup.
 67
 68	myAdxl.lowPowerOn()
 69	#also try:
 70	#myAdxl.lowPower = True
 71
 72	myAdxl.setBandwidth(myAdxl.ADXL313_BW_12_5)
 73	#also try:
 74	#myAdxl.bandwidth = myAdxl.ADXL313_BW_12_5
 75	
 76	#12.5Hz is the best power savings.
 77	#Other options possible are the following.
 78	#Note, bandwidths not listed below do not cause power savings.
 79	#ADXL313_BW_200		    (115uA in low power)
 80	#ADXL313_BW_100		    (82uA in low power)
 81	#ADXL313_BW_50		    (64uA in low power)
 82	#ADXL313_BW_25		    (57uA in low power)
 83	#ADXL313_BW_12_5	    (50uA in low power)
 84	#ADXL313_BW_6_25		  (43uA in low power)
 85
 86	myAdxl.measureModeOn()
 87
 88	while True:
 89		myAdxl.updateIntSourceStatuses(); # this will update all INTSOURCE statuses.
 90
 91		if myAdxl.ADXL313_INTSOURCE_DATAREADY:
 92			myAdxl.readAccel() # read all axis from sensor, note this also updates all instance variables
 93			print(\
 94			 '{: 06d}'.format(myAdxl.x)\
 95			, '\t', '{: 06d}'.format(myAdxl.y)\
 96			, '\t', '{: 06d}'.format(myAdxl.z)\
 97			)
 98		else:
 99			print("Waiting for data.")
100		time.sleep(0.08)
101
102if __name__ == '__main__':
103	try:
104		runExample()
105	except (KeyboardInterrupt, SystemExit) as exErr:
106		print("\nEnding Example 4")
107		sys.exit(0)