diff --git a/platformio.ini b/platformio.ini index 2c373ab00..d54a06d3e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -132,3 +132,4 @@ lib_deps = adafruit/Adafruit MPU6050@^2.2.4 adafruit/Adafruit LIS3DH@^1.2.4 https://github.com/lewisxhe/SensorLib#27fd0f721e20cd09e1f81383f0ba58a54fe84a17 + adafruit/Adafruit LSM6DS@^4.7.2 \ No newline at end of file diff --git a/src/AccelerometerThread.h b/src/AccelerometerThread.h index 6827908b7..fa5acdaae 100644 --- a/src/AccelerometerThread.h +++ b/src/AccelerometerThread.h @@ -5,6 +5,7 @@ #include "power.h" #include +#include #include #include #include @@ -108,6 +109,15 @@ class AccelerometerThread : public concurrency::OSThread bmaSensor.enableTiltIRQ(); // It corresponds to isDoubleClick interrupt bmaSensor.enableWakeupIRQ(); + } else if (acceleremoter_type == ScanI2C::DeviceType::LSM6DS3 && lsm.begin_I2C(accelerometer_found.address)) { + LOG_DEBUG("LSM6DS3 initializing\n"); + // Default threshold of 2G, less sensitive options are 4, 8 or 16G + lsm.setAccelRange(LSM6DS_ACCEL_RANGE_2_G); +#ifndef LSM6DS3_WAKE_THRESH +#define LSM6DS3_WAKE_THRESH 20 +#endif + lsm.enableWakeup(config.display.wake_on_tap_or_motion, 1, LSM6DS3_WAKE_THRESH); + // Duration is number of occurances needed to trigger, higher threshold is less sensitive } } @@ -133,6 +143,9 @@ class AccelerometerThread : public concurrency::OSThread wakeScreen(); return 500; } + } else if (acceleremoter_type == ScanI2C::DeviceType::LSM6DS3 && lsm.shake()) { + wakeScreen(); + return 500; } return ACCELEROMETER_CHECK_INTERVAL_MS; @@ -156,6 +169,7 @@ class AccelerometerThread : public concurrency::OSThread ScanI2C::DeviceType acceleremoter_type; Adafruit_MPU6050 mpu; Adafruit_LIS3DH lis; + Adafruit_LSM6DS3TRC lsm; }; -} // namespace concurrency +} // namespace concurrency \ No newline at end of file diff --git a/src/configuration.h b/src/configuration.h index 7ce1a0b8b..66ec607ff 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -128,6 +128,7 @@ along with this program. If not, see . #define MPU6050_ADDR 0x68 #define LIS3DH_ADR 0x18 #define BMA423_ADDR 0x19 +#define LSM6DS3_ADDR 0x6A // ----------------------------------------------------------------------------- // LED @@ -280,4 +281,4 @@ along with this program. If not, see . #ifdef MESHTASTIC_EXCLUDE_SCREEN #undef HAS_SCREEN #define HAS_SCREEN 0 -#endif +#endif \ No newline at end of file diff --git a/src/detect/ScanI2C.cpp b/src/detect/ScanI2C.cpp index bf206c190..149bb95f0 100644 --- a/src/detect/ScanI2C.cpp +++ b/src/detect/ScanI2C.cpp @@ -36,8 +36,8 @@ ScanI2C::FoundDevice ScanI2C::firstKeyboard() const ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const { - ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423}; - return firstOfOrNONE(3, types); + ScanI2C::DeviceType types[] = {MPU6050, LIS3DH, BMA423, LSM6DS3}; + return firstOfOrNONE(4, types); } ScanI2C::FoundDevice ScanI2C::find(ScanI2C::DeviceType) const diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index ecb6db225..e87ede0a4 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -39,6 +39,7 @@ class ScanI2C LIS3DH, BMA423, BQ24295, + LSM6DS3, #ifdef HAS_NCP5623 NCP5623, #endif diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index ea6e692df..335892131 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -310,6 +310,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) SCAN_SIMPLE_CASE(PMSA0031_ADDR, PMSA0031, "PMSA0031 air quality sensor found\n") SCAN_SIMPLE_CASE(MPU6050_ADDR, MPU6050, "MPU6050 accelerometer found\n"); SCAN_SIMPLE_CASE(BMA423_ADDR, BMA423, "BMA423 accelerometer found\n"); + SCAN_SIMPLE_CASE(LSM6DS3_ADDR, LSM6DS3, "LSM6DS3 accelerometer found\n"); default: LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address); diff --git a/variants/unphone/variant.h b/variants/unphone/variant.h index dff03b8d5..9306537f2 100644 --- a/variants/unphone/variant.h +++ b/variants/unphone/variant.h @@ -53,6 +53,8 @@ #define I2C_SDA 3 // I2C pins for this board #define I2C_SCL 4 +#define LSM6DS3_WAKE_THRESH 5 // higher values reduce the sensitivity of the wake threshold + // ratio of voltage divider = 3.20 (R1=100k, R2=220k) // #define ADC_MULTIPLIER 3.2