Xiao Sense Accelerometer Examples and Low Power

lower serial com speed to 19200

in code… Find

Serial.begin(115200);

Take the 15 out and replace with 9… like this

Serial.begin(19200);

Make sure all the sketches you want to autoboot are edited like this

2 Likes

Hi there,
The default for Nordic NRf is 9600 baud. Arduino as well. BTW :+1:
HTH
GL :slight_smile: PJ
:v:

8N1@9600

Hi @Afzal_Rehmani, This might be an out of date or out of sync library. I just compiled “Combination” from above with no errors. I have a clean install of the just the following:

  • Arduino IDE 2.3.2
  • Seeed NRF52 Boards 1.1.8
  • Seeed Arduino LSM6DS3 2.0.3

I remember installing “Adafruit SPIFlash” and “SdFat - Adafruit Fork” in the past, but it looks like they are not needed with the latest board package. (I haven’t played with this code for a while, so my memory is a bit out of date.) Maybe you have old versions of these libraries that need to be removed or updated. Also make sure you have selected the correct board.

2 Likes

Thanks daCoder. It’s now compiled i downloaded from the wrong source the SdFat causing issues.

Hey everyone. I have a weird one that might be relevant to this thread. Basically whats going on is that I’ve got daCoder’s nudgeWakeUp code running and it works great. The weird part is that it only works great when it is plugged into my computer. The second I try to run things off of battery it will go to sleep and then wake right back up again a few milliseconds later. What’s happening here? Any help would be greatly appreciated!

Here’s my code

#include <Adafruit_SPIFlash.h>
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#include <LSM6DS3.h>
#include <nrf52840.h>

Adafruit_FlashTransport_QSPI flashTransport;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
LSM6DS3 myIMU(I2C_MODE, 0x6A);

#define SLEEP_TIMEOUT 7000

const int button1Pin = D2;
const int button2Pin = D3;
unsigned long startTimeoutTime = 0;
volatile bool awake = true;

void QSPIF_sleep(void) {
  flashTransport.begin();
  flashTransport.runCommand(0xB9);
  flashTransport.end();
}

void setupWakeUpInterrupt() {  
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_DUR, 0x00); // No duration
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_WAKE_UP_THS, 0x05); // Set wake-up threshold
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x80);    // Enable interrupts and apply slope filter; latch mode disabled
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0x70);    // Turn on the accelerometer
                                                           // ODR_XL = 833 Hz, FS_XL = ±2 g
  delay(4);                                                // Delay time per application note
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, 0xB0);    // ODR_XL = 1.6 Hz
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL6_G, 0x10);     // High-performance operating mode disabled for accelerometer
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, 0x20);     // Wake-up interrupt driven to INT1 pin

	pinMode(PIN_LSM6DS3TR_C_INT1, INPUT_PULLDOWN_SENSE);

  return;
}

void setup() {
  u8g2.begin();

  pinMode(button1Pin, INPUT_PULLUP);
  pinMode(button2Pin, INPUT_PULLUP);

  QSPIF_sleep();

  myIMU.settings.gyroEnabled = 0;
  myIMU.settings.tempEnabled = 0;
  myIMU.begin();

  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_profont11_mf);
  u8g2.setDisplayRotation(U8G2_R3);

  NRF_POWER->DCDCEN = 1;
}

void loop() {
  u8g2.setPowerSave(0);
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_profont11_mf);
  u8g2.setCursor(10, 10);
  u8g2.print(F("Hello!"));
  u8g2.sendBuffer();

  if (startTimeoutTime == 0) startTimeoutTime = millis();

  if (startTimeoutTime > 0 && ((millis() - startTimeoutTime) > SLEEP_TIMEOUT)) {
    startTimeoutTime = 0;
    enterStandbySleep();
  }
}

void enterStandbySleep() {
  u8g2.setPowerSave(1);
  setupWakeUpInterrupt();
  pinMode(button1Pin, INPUT_SENSE_HIGH);
  delay(200);
  NRF_POWER->SYSTEMOFF = 1;
}

Hi there,

So that is AGE old , BRO… The Wait on Serial is the First one…
The second one is related to the BSP, and explicitly naming the IMU interrupt pin, READ more… and use the search you’ll find the code examples and threads myself and @msfujino have created , answered and tested.

HTH
GL :slight_smile: PJ :v:

1 Like