Asset Tracker: Wake Up upon position change?

This probably should be possible, but it didn’t seem to work quite right for me either.

Using the AssetTrackerRK library:


#include "Particle.h"

#include "LIS3DH.h"

// System threading is required for this project
SYSTEM_THREAD(ENABLED);

// This example doesn't use cellular so it's turned off to save data. Position wake-up
// works fine with cellular on as well.
SYSTEM_MODE(MANUAL);

// Global objects
LIS3DHSPI accel(SPI, A2, WKP);

const unsigned SLEEP_TIME_SEC = 3600;
const uint8_t movementThreshold = 32;

bool hasAccel = false;
bool positionChanged = false;

void setup() {
	Serial.begin(9600);

	Serial.println("resetting accelerometer");

	LIS3DHConfig config;
	config.setLowPowerWakeMode(movementThreshold);

	// For position detection instead of motion detection, enable these:
	// AOI-6D = '01' is movement recognition. An interrupt is generate when orientation move from unknown zone to known zone.
	// The interrupt signal stay for a duration ODR.
	// Not set: LIS3DH::INT1_CFG_AOI
	config.int1_cfg |= LIS3DH::INT1_CFG_6D;

	hasAccel = accel.setup(config);
	if (!hasAccel) {
		Serial.println("accelerometer not found");
	}

}


void loop() {

	if (!hasAccel) {
		return;
	}

	// Wait for Electron to stop moving for 2 seconds so we can recalibrate the accelerometer
	accel.calibrateFilter(2000);

	Serial.println("going to sleep");

	// Sleep
	System.sleep(WKP, RISING, SLEEP_TIME_SEC);

	// This delay should not be necessary, but sometimes things don't seem to work right
	// immediately coming out of sleep.
	delay(500);

	positionChanged = ((accel.clearInterrupt() & LIS3DH::INT1_SRC_IA) != 0);
	Serial.printlnf("positionChanged=%d", positionChanged);
}

Setting the 6D bit in INT1_CFG should enable position detection, according the LIS3DH app node AN3308. I’m not positive it’s actually working, however. It seems to trigger with sufficient movement without an orientation change for me. I’m not sure why.

1 Like