Sodaq one Accelerometer

Hi All,

I’m having trouble getting the LSM303 to work.
First of all I have to comment out:
/*
unsigned int millis_start = millis();
while (Wire.available() < 6) {
if (io_timeout > 0 && ((unsigned int)millis() - millis_start) > io_timeout)
{
did_timeout = true;
return;
}
}*/

For the Sodaq not to hang. Second, I’m only getting -1 values.

Inital communication to the device seems to work through:
if (!lsm303.init(LSM303::device_D, LSM303::sa0_low)) {
debugSerial.println(“Initialization of the LSM303 failed!”);
return;
}
else {
debugSerial.println(“Initialization of the LSM303 complete!”);
lsm303.enableDefault();
}

Anyone that can help? I’m using the version 2 of the Sodaq LoraWan.

1 Like

Hi Glenn,

We have replaced the LSM303 for the LIS3DE on the ONE V2
http://support.sodaq.com/sodaq-one/#one-vs-one-v2

Regards,
Jan

Hi Jan,

Thank you for the reply. I was using the tutorial for the LSM303 on the website.
Do you have a library and tutorial for the new module?

Kind regards,

Glenn

1 Like

Hi Jan,

I am also using the version 2 of the Sodaq Lora and I would appreciate if you could share some example of how to use the accelerometer.

Do you have an example which works with the interruption? For example, wake up Sodaq Lora when it has moved. In the schematics it is not clear where those interruptions lines go to.

Any help would be really appreciated.

Kind regards,

Pablo

1 Like

Hello again,

Do you have (or anyone else) a glue of how to access the accelerometer and how to put the board in deep sleep mode to be waked up by the accelerometer?

Could you at least tell us which are the interrupt pins in the MCU? Thanks!

Hi Glenn/Pablo,

I have not an up and running sketch, but have a look at the following:

attachInterrupt(ACCEL_INT1, ISR2, FALLING);
attachInterrupt(ACCEL_INT2, ISR1, FALLING);

pinMode(ACCEL_INT1, INPUT_PULLDOWN);
pinMode(ACCEL_INT2, INPUT_PULLDOWN);


EIC->WAKEUP.reg |= (1 << digitalPinToInterrupt(ACCEL_INT1));
EIC->WAKEUP.reg |= (1 << digitalPinToInterrupt(ACCEL_INT2));

// IG1 interrupt generator 1 on INT1.
writeReg(0x22, 0b01000000);

//CTRL5
writeReg(0x24, 0b00000000);	// no latching

// Interrupt generator 2 enabled on INT2 pin.
writeReg(0x25, 0b00100000);

//IG1_CFG
writeReg(0x30, 0b01101010);

// IG_THS1
writeReg(0x32, 0b00000111);

// IG_DURATION
writeReg(0x33, 0b00000000);


// IG2_CFG
writeReg(0x34, 0b10101010);

// IG_THS2
writeReg(0x36, 0b00011111);

// IG_DURATION
writeReg(0x37, 0b00000000);

Axel

Dear Axel,

Thanks for the update, but I have tried that code and it is not working for me.

Could you paste the writeReg function? Maybe put an entire arduino sketch that is working for you? That would be really appreciated.

Thanks for your help in any case,

Pablo

Dear all,

Same here, can’t find informations on how to use the LIS3DE. Just find a lib for LIS3DH but not for LIS3DE.

And the LIS2DE seem not to has a gyro : datasheet.
So not like the LSM303, it’s a loss in functionnalities.

Please, tell me I’m wrong ! I need to get a accel/gyro for a competition in 8 days.

Thanks.
Pascal

I wrote the code below using the SodaqOne-UniversalTracker-v2 as baseline.
Although it has the code for managing interrupts, It is not activated.

Please improve the code and share.
// Code for LIS3DE accelerometer inside SODAQ v2

#include <Arduino.h>
#include <Wire.h>
#include "Sodaq_RN2483.h"
#include "Sodaq_wdt.h"
#include "LIS3DE.h"
#include "RTCTimer.h"
#include "RTCZero.h"

#define debugSerial SerialUSB
#define loraSerial Serial1
#define MAX_RTC_EPOCH_OFFSET 25

RTCZero rtc;
RTCTimer timer;
LIS3DE accelerometer;
double x, y, z;
String xDoble, yDouble, zDouble;
volatile bool isOnTheMoveActivated;
volatile uint32_t lastOnTheMoveActivationTimestamp;
uint32_t getNow();
void initRtc();
void rtcAlarmHandler();
void resetRtcTimerEvents();
void initSleep();
void accelerometerInt1Handler();
volatile bool minuteFlag;
static bool isOnTheMoveInitialized;
void setAccelerometerTempSensorActive(bool on);

void setup() {
  //Power up the LoRaBEE
 
  pinMode(ENABLE_PIN_IO, OUTPUT); // ONE
  digitalWrite(ENABLE_PIN_IO, HIGH); // ONE
  delay(3000);
  Wire.begin();
  while ((!SerialUSB) && (millis() < 10000)){
    // Wait 10 seconds for the Serial Monitor
  }

  //Set baud rate
  debugSerial.begin(57600);
  loraSerial.begin(LoRaBee.getDefaultBaudRate());
 debugSerial.println("Starting...");
 isOnTheMoveInitialized = true;

  // Activate interrupt on the move
  initOnTheMove();
  
}
void loop(){
  /*
  x = accelerometer.getGsFromScaledValue(.readRegister(LIS3DE::OUT_X));
  y = accelerometer.getGsFromScaledValue(readRegister(LIS3DE::OUT_Y));
  z = accelerometer.getGsFromScaledValue(a.readRegister(LIS3DE::OUT_Z));
  */
 
  x=accelerometer.getX();
  y=accelerometer.getY();
  z=accelerometer.getZ();
  debugSerial.print("X: "); debugSerial.println(x);
  debugSerial.print("Y: "); debugSerial.println(y);
  debugSerial.print("Z: "); debugSerial.println(z);
}

/*
/**

 * Returns the board temperature.



int8_t getBoardTemperature()

{

    setAccelerometerTempSensorActive(true);




    int8_t temp = params.getTemperatureSensorOffset() + accelerometer.getTemperatureDelta();




    setAccelerometerTempSensorActive(false);




    return temp;

}
*/
/**

* Initializes the on-the-move functionality (interrupt on acceleration).

*/

void initOnTheMove()

{

    pinMode(ACCEL_INT1, INPUT);

    attachInterrupt(ACCEL_INT1, accelerometerInt1Handler, CHANGE);




    // Configure EIC to use GCLK1 which uses XOSC32K, XOSC32K is already running in standby

    // This has to be done after the first call to attachInterrupt()

    GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(GCM_EIC) |

        GCLK_CLKCTRL_GEN_GCLK1 |

        GCLK_CLKCTRL_CLKEN;




    accelerometer.enable(true, LIS3DE::NormalLowPower10Hz, LIS3DE::XYZ, LIS3DE::Scale4g, true);

    sodaq_wdt_safe_delay(10);




    accelerometer.enableInterrupt1(

        LIS3DE::XHigh | LIS3DE::XLow | LIS3DE::YHigh | LIS3DE::YLow | LIS3DE::ZHigh | LIS3DE::ZLow,

        18.75 * 8.0 / 100.0,

        100,

        LIS3DE::MovementRecognition);

}

/**

 * Runs every time acceleration is over the limits

 * set by the user (if enabled).

*/

void accelerometerInt1Handler()

{

    if (digitalRead(ACCEL_INT1)) {

       




        // debugPrintln("On-the-move is triggered");




        isOnTheMoveActivated = true;

        lastOnTheMoveActivationTimestamp = getNow();

    }

}



/**

 * Initializes the accelerometer or puts it in power-down mode

 * for the purpose of reading its temperature delta.

*/

void setAccelerometerTempSensorActive(bool on)

{

    // if on-the-move is initialized then the accelerometer is enabled anyway

    if (isOnTheMoveInitialized) {

        return;

    }




    if (on) {

        accelerometer.enable(false, LIS3DE::NormalLowPower100Hz, LIS3DE::XYZ, LIS3DE::Scale2g, true);

        sodaq_wdt_safe_delay(30); // should be enough for initilization and 2 measurement periods

    }

    else {

        accelerometer.disable();

    }

}

/**
 * Returns the current datetime (seconds since unix epoch).
 */
uint32_t getNow()
{
    return rtc.getEpoch();
}

void initRtc()
{
    rtc.begin();

    // Schedule the wakeup interrupt for every minute
    // Alarm is triggered 1 cycle after match
    rtc.setAlarmSeconds(59);
    rtc.enableAlarm(RTCZero::MATCH_SS); // alarm every minute

    // Attach handler
    rtc.attachInterrupt(rtcAlarmHandler);

    // This sets it to 2000-01-01
    rtc.setEpoch(0);
}

/**
 * Runs every minute by the rtc alarm.
*/
void rtcAlarmHandler()
{
    minuteFlag = true;
}

/**
 * Initializes the RTC Timer and schedules the default events.
 */
void initRtcTimer()
{
    timer.setNowCallback(getNow); // set how to get the current time
    timer.allowMultipleEvents();

    resetRtcTimerEvents();
}

Dear Pablo and fellows, I am a beginner on Accelerometer LIS3DE. The code above seem to work with serial output. Can any one please attach a code with interrupts enabled? Like accelerometer awakes the board from deep sleep mode. Your kind help is appreciated.

Regards, Adeel.

Have you found any more information on this topic? I am trying to get interrupts working as well. Thank you.

Dear, I have not had time to work further on this. I will update once I have more information. Hope that you manage to get up and running on this. Br, Adeel.

1 Like

I’ll see what I can figure out, maybe we could help each-other.

Exactly - there is no example at all on the sodaq_one_support_page! Please someone add one.

// This sample code was executed on SODAQ ONE Version 2
// Roger Rabbit took this informations from (2017-11-17)…
// https://github.com/SodaqMoja/Sodaq_LIS3DE/blob/master/Readme.md
#include <Sodaq_LIS3DE.h>
#include <Wire.h>
#define debugSerial SerialUSB

// Constructor with optional Wire instance and address parameters.
// Sodaq_LIS3DE(TwoWire& wire = Wire, uint8_t address = LIS3DE_ADDRESS)
Sodaq_LIS3DE accelerometer;

void setup()
{
debugSerial.begin(57600);
Wire.begin();

// Enables the sensor with the default values or the given data rate, axes and scale.
accelerometer.enable();
// optinal: Resets all the registers of the sensor.
accelerometer.reboot();
}

void loop()
{
// Returns the temperature delta as read from the sensor (8-bit int).
uint8_t tempDelta = accelerometer.getTemperatureDelta();
debugSerial.println("temp: " + String(tempDelta));

double x = accelerometer.getX(); // Returns a measurement of the X axis.
double y = accelerometer.getY(); // Returns a measurement of the Y axis.
double z = accelerometer.getZ(); // Returns a measurement of the Z axis.

debugSerial.println("x: " + String(x));
debugSerial.println("y: " + String(y));
debugSerial.println("z: " + String(z));

delay(100);
}

it took me a while to find out how it works. It was so annoying.
Why did the not just provide this bit of sample code??!