adxl345: Grove 3-Axis Accelerometer

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu
2014-12-16 16:29:40 -08:00
committed by Propanu
parent 6aef5868af
commit a4e590ae3a
10 changed files with 447 additions and 0 deletions

View File

@ -77,6 +77,7 @@ add_executable (biss0001-example biss0001.cxx)
add_executable (my9221-example my9221.cxx)
add_executable (grove_mcfled-example grove_mcfled.cxx)
add_executable (rotaryencoder-example rotaryencoder.cxx)
add_executable (adxl345-example adxl345.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -140,6 +141,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/rfr359f)
include_directories (${PROJECT_SOURCE_DIR}/src/biss0001)
include_directories (${PROJECT_SOURCE_DIR}/src/my9221)
include_directories (${PROJECT_SOURCE_DIR}/src/rotaryencoder)
include_directories (${PROJECT_SOURCE_DIR}/src/adxl345)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -220,3 +222,4 @@ target_link_libraries (biss0001-example biss0001 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (my9221-example my9221 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grove_mcfled-example grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (rotaryencoder-example rotaryencoder ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (adxl345-example adxl345 ${CMAKE_THREAD_LIBS_INIT})

51
examples/adxl345.cxx Normal file
View File

@ -0,0 +1,51 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Copyright (c) 2014 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.
*/
#include <unistd.h>
#include "adxl345.h"
int
main(int argc, char **argv)
{
//! [Interesting]
int16_t *raw;
float *acc;
// Note: Sensor only works at 3.3V on the Intel Edison with Arduino breakout
upm::Adxl345* accel = new upm::Adxl345(0);
while(true){
accel->update(); // Update the data
raw = accel->getRawValues(); // Read raw sensor data
acc = accel->getAcceleration(); // Read acceleration (g)
fprintf(stdout, "Current scale: 0x%2xg\n", accel->getScale());
fprintf(stdout, "Raw: %6d %6d %6d\n", raw[0], raw[1], raw[2]);
fprintf(stdout, "AccX: %5.2f g\n", acc[0]);
fprintf(stdout, "AccY: %5.2f g\n", acc[1]);
fprintf(stdout, "AccZ: %5.2f g\n", acc[2]);
sleep(1);
}
//! [Interesting]
return 0;
}

View File

@ -0,0 +1,41 @@
/*
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.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.
*/
// Load accelerometer
var adxl345 = require('jsupm_adxl345');
// Instantiate on I2C bus
var adxl = new adxl345.Adxl345(0);
setInterval(function()
{
adxl.update(); // Update the data
var raw = adxl.getRawValues(); // Read raw sensor data
var force = adxl.getAcceleration(); // Read acceleration force (g)
var rawvalues = raw.getitem(0) + " " + raw.getitem(1) + " " + raw.getitem(2);
console.log("Raw Values: " + rawvalues);
console.log("ForceX: " + force.getitem(0).toFixed(2) + " g");
console.log("ForceY: " + force.getitem(1).toFixed(2) + " g");
console.log("ForceZ: " + force.getitem(2).toFixed(2) + " g");
}, 1000);

View File

@ -0,0 +1,41 @@
# Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
# Copyright (c) 2014 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.
from time import sleep
import pyupm_adxl345 as adxl345
# Create an I2C accelerometer object
adxl = adxl345.Adxl345(0)
# Loop indefinitely
while True:
adxl.update() # Update the data
raw = adxl.getRawValues() # Read raw sensor data
force = adxl.getAcceleration() # Read acceleration force (g)
print "Raw: %6d %6d %6d" % (raw[0], raw[1], raw[2])
print "ForceX: %5.2f g" % (force[0])
print "ForceY: %5.2f g" % (force[1])
print "ForceZ: %5.2f g\n" % (force[2])
# Sleep for 1 s
sleep(1)