Loraone accelerometer interrups


I’m trying to get the accelerometer to produce interrupts, but without success.

Here’s my test code:

#include <Wire.h>
#include "LSM303.h"
LSM303 compass;
volatile bool int1_flag = false;

void ISR1()
  int1_flag = true;

void setup() 
	CONSOLE_SERIAL.println("Testing Accelerometer");

	attachInterrupt(ACCEL_INT1, ISR1, FALLING);


	compass.writeReg(0x30, 0b10001000); // Axes mask
	compass.writeReg(0x32, 0b00000011); // Threshold
	compass.writeReg(0x33, 0b00000000); // Duration
	compass.writeReg(0x22, 0b00100000);

void loop()
  if (int1_flag) {
    int1_flag = false;
    CONSOLE_SERIAL.println("INT1 Interrupt");
  SerialUSB.print("x: "); SerialUSB.print(compass.a.x * 0.061); //0.061 to convert to g)
  SerialUSB.print(", y: "); SerialUSB.print(compass.a.y* 0.061);
  SerialUSB.print(", z: "); SerialUSB.println(compass.a.z* 0.061);

  CONSOLE_SERIAL.print("register: 0x" + String(0x31, HEX));
  CONSOLE_SERIAL.println(", response: 0x" + String(compass.readReg(0x31), BIN));



  • What I want to do: get an interrupt whenever the device moves just a little bit in 1 axes (y in this case).
  • so, I’ve set up register 0x30 to monitor ‘HIGH’ event of the Y axes (‘and’ operator, does this matter for 1 axes?)
  • the threshold was set to 3, which I believe means: 3 * 16mg = 48mg. (16mg cause the default of 2g full scale is used)
    If I understand the docs correctly, this means that whenever y reports a value of more then 48mg or less then -48mg, then the interrupt should be triggered.

But this is the output that I get:

x: 281.27, y: 15.31, z: 961.79
register: 0x31, response: 0x100110
x: 43.07, y: -36.78, z: 1083.36
register: 0x31, response: 0x1101001
x: 46.60, y: -26.41, z: 1060.06
register: 0x31, response: 0x100101
x: 157.56, y: -195.93, z: 1184.74
register: 0x31, response: 0x1101010
x: 69.48, y: 89.00, z: 1036.57

so, at first, y is below 48mg, all ok, when I start to move the device, it goes to -195 and 89, so I would think that the interrupt should get triggered. The status byte also reports that it found a ‘high’ event on x, y and z + that it has generated an interrupt. But the interrupt is never called.
What am I doing wrong?

PS: The following docs were used for info:
and http://www.st.com/content/ccc/resource/technical/document/application_note/77/ed/e7/e1/28/5a/45/d6/CD00290365.pdf/files/CD00290365.pdf/jcr:content/translations/en.CD00290365.pdf


I think that you are just missing the configuration of the CTRL1 register (0x20).

Here is a test sketch I wrote a while ago:


The CTRL1 register was being set in the LSM303D lib, so I figured that was ok. Your example got me thinking though, cause it works indeed. So I merged my example into yours until I found where it was going wrong. Turns out that you need to attach to both interrupt 1 and 2, otherwise it don’t work.
Also, I have the impression that interrupt 1 and 2 are switched. I configured ‘Interrupt source 2’ to be triggered on the Z axes, but that raises interrupt 1.

Yes, I think I remember some issue with the documentation having switched the labels for INT1 & INT2.

I also have the impression that there is something wrong with the ‘writeReg’ function in the LSM303 lib. When using there ‘writeReg’ function, it doesn’t work, but it does work with yours.

I have a small delay (10ms) in my *writeReg() *method, perhaps that is the reason.

I can’t remember exactly why the delay was needed, it wasn’t required for every register write just a couple. The datasheet will probably have the details of how long you should wait after certain operations.