Page 1 of 1

Grove 6 axis Accelerometer and Gyroscope with esp32

Posted: Tue Jun 13, 2023 8:27 am
by nnayspy
The error i have :
" Compilation error: 'I2C_MODE' was not declared in this scope" :
/*****************************************************************************/
// Pedometer.ino
// Hardware: Grove - 6-Axis Accelerometer&Gyroscope
// Arduino IDE: Arduino-1.65
// Author: Lambor
// Date: Nov,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
//
/*******************************************************************************/

The code i use :
  1. #include "LSM6DS3.h"
  2. #include "Wire.h"
  3.  
  4. #define CLEAR_STEP      true
  5. #define NOT_CLEAR_STEP  false
  6.  
  7. //Create a instance of class LSM6DS3
  8. LSM6DS3Class pedometer(1, 0x6A);    //I2C device address 0x6A
  9.  
  10. void setup() {
  11.     Serial.begin(9600);
  12.     while (!Serial);
  13.     if (pedometer.begin() != 0) {
  14.         Serial.println("Device error");
  15.     } else {
  16.         Serial.println("Device OK!");
  17.     }
  18.  
  19.     //Configure LSM6DS3 as pedometer
  20.     if (0 != config_pedometer(NOT_CLEAR_STEP)) {
  21.         Serial.println("Configure pedometer fail!");
  22.     }
  23.     Serial.println("Success to Configure pedometer!");
  24. }
  25.  
  26. void loop() {
  27.     uint8_t dataByte = 0;
  28.     uint16_t stepCount = 0;
  29.  
  30.     pedometer.readRegister(&dataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_H);
  31.     stepCount = (dataByte << 8) & 0xFFFF;
  32.  
  33.     pedometer.readRegister(&dataByte, LSM6DS3_ACC_GYRO_STEP_COUNTER_L);
  34.     stepCount |=  dataByte;
  35.  
  36.     Serial.print("Step: ");
  37.     Serial.println(stepCount);
  38.  
  39.     delay(500);
  40. }
  41.  
  42. //Setup pedometer mode
  43. int config_pedometer(bool clearStep) {
  44.     uint8_t errorAccumulator = 0;
  45.     uint8_t dataToWrite = 0;  //Temporary variable
  46.  
  47.     //Setup the accelerometer******************************
  48.     dataToWrite = 0;
  49.  
  50.     //  dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_200Hz;
  51.     dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
  52.     dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_26Hz;
  53.  
  54.  
  55.     // Step 1: Configure ODR-26Hz and FS-2g
  56.     errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
  57.  
  58.     // Step 2: Set bit Zen_G, Yen_G, Xen_G, FUNC_EN, PEDO_RST_STEP(1 or 0)
  59.     if (clearStep) {
  60.         errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3E);
  61.     } else {
  62.         errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_CTRL10_C, 0x3C);
  63.     }
  64.  
  65.     // Step 3:  Enable pedometer algorithm
  66.     errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x40);
  67.  
  68.     //Step 4:   Step Detector interrupt driven to INT1 pin, set bit INT1_FIFO_OVR
  69.     errorAccumulator += pedometer.writeRegister(LSM6DS3_ACC_GYRO_INT1_CTRL, 0x10);
  70.  
  71.     return errorAccumulator;
  72. }