mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
h3lis331dl: Initial implementation
The driver implements support for the Grove 3-Axis Digital Accelerometer(±400g), using the h3lis331dl chip. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
5547d99609
commit
c8d0aee873
76
examples/python/h3lis331dl.py
Normal file
76
examples/python/h3lis331dl.py
Normal file
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_h3lis331dl as upmH3LIS331DL
|
||||
|
||||
# Instantiate an H3LIS331DL on I2C bus 0
|
||||
myDigitalAccelerometer = upmH3LIS331DL.H3LIS331DL(
|
||||
upmH3LIS331DL.H3LIS331DL_I2C_BUS,
|
||||
upmH3LIS331DL.H3LIS331DL_DEFAULT_I2C_ADDR);
|
||||
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit, including functions from myDigitalAccelerometer
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
|
||||
# Initialize the device with default values
|
||||
myDigitalAccelerometer.init()
|
||||
|
||||
x = upmH3LIS331DL.new_intp()
|
||||
y = upmH3LIS331DL.new_intp()
|
||||
z = upmH3LIS331DL.new_intp()
|
||||
|
||||
ax = upmH3LIS331DL.new_floatp()
|
||||
ay = upmH3LIS331DL.new_floatp()
|
||||
az = upmH3LIS331DL.new_floatp()
|
||||
|
||||
while (1):
|
||||
myDigitalAccelerometer.update()
|
||||
myDigitalAccelerometer.getRawXYZ(x, y, z)
|
||||
outputStr = ("Raw: X = {0}"
|
||||
" Y = {1}"
|
||||
" Z = {2}").format(upmH3LIS331DL.intp_value(x),
|
||||
upmH3LIS331DL.intp_value(y),
|
||||
upmH3LIS331DL.intp_value(z))
|
||||
print outputStr
|
||||
|
||||
myDigitalAccelerometer.getAcceleration(ax, ay, az)
|
||||
outputStr = ("Acceleration: AX = {0}"
|
||||
" AY = {1}"
|
||||
" AZ = {2}").format(upmH3LIS331DL.floatp_value(ax),
|
||||
upmH3LIS331DL.floatp_value(ay),
|
||||
upmH3LIS331DL.floatp_value(az))
|
||||
print outputStr
|
||||
time.sleep(.5)
|
Reference in New Issue
Block a user