| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- /*****************************************************************************/
- // LowLevelExample.ino
- // Hardware: Grove - 6-Axis Accelerometer&Gyroscope
- // Arduino IDE: Arduino-1.65
- // Author: Lambor
- // Date: Oct,2015
- // Version: v1.0
- //
- // Modified by:
- // Data:
- // Description:
- //
- // by www.seeedstudio.com
- //
- // This library is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Lesser General Public
- // License as published by the Free Software Foundation; either
- // version 2.1 of the License, or (at your option) any later version.
- //
- // This library is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- // Lesser General Public License for more details.
- //
- // You should have received a copy of the GNU Lesser General Public
- // License along with this library; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- //
- /*******************************************************************************/
- #include "SparkFunLSM6DS3.h"
- #include "Wire.h"
- #include "SPI.h"
- uint16_t errorsAndWarnings = 0;
- //Create instance of LSM6DS3Core
- LSM6DS3Core myIMU( I2C_MODE, 0x6A ); //I2C device address 0x6A
- void setup() {
- //Init Serial port
- Serial.begin(9600);
-
- //Call .beginCore() to configure the IMU
- if( myIMU.beginCore() != 0 )
- {
- Serial.print("\nDevice Error.\n");
- }
- else
- {
- Serial.print("\nDevice OK.\n");
- }
-
- uint8_t dataToWrite = 0; //Temporary variable
- //Setup the accelerometer******************************
- dataToWrite = 0; //Start Fresh!
- dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_100Hz;
- dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_8g;
- dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_104Hz;
- //Now, write the patched together data
- errorsAndWarnings += myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
- //Set the ODR bit
- errorsAndWarnings += myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
- dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
- }
- void loop()
- {
- int16_t temp;
- //Get all parameters
- Serial.print("\nAccelerometer Counts:\n");
-
- //Acelerometer axis X
- if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTX_L_XL) != 0 )
- {
- errorsAndWarnings++;
- }
- Serial.print(" X = ");
- Serial.println(temp);
-
- //Acelerometer axis Y
- if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTY_L_XL) != 0 )
- {
- errorsAndWarnings++;
- }
- Serial.print(" Y = ");
- Serial.println(temp);
-
- //Acelerometer axis Z
- if( myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTZ_L_XL) != 0 )
- {
- errorsAndWarnings++;
- }
- Serial.print(" Z = ");
- Serial.println(temp);
-
- Serial.println();
- Serial.print("Total reported Errors and Warnings: ");
- Serial.println(errorsAndWarnings);
-
- delay(1000);
- }
|