1

So I'm relatively new to microcontrollers, and I'm having a problem implementing a feature I want for a project.

I've learned about putting an Atmega328P to sleep from this tutorial. I'm using an Arduino Nano, so I only get my current down to ~9mA rather than the µAs the tutor is getting. Nonetheless, it demonstrates the abstraction I want to learn for when I move to just the Atmega328 with no board.

I've learned to wake up my microcontroller from sleep with a falling external interrupt on INT0/D2 from a simple button. My ISR is empty and just boots me back to the loop, which is fine. As an aside, I have heard that it is better to have simple and short ISR's, but I am not completely sure why.

My question is, can I use my ADXL345 to trigger an interrupt that wakes my Arduino? I am semi-familiar with using an ADXL345 over I2C, although I don't understand why my Sparkfun ADXL345 requires different wiring than my unbranded one, but that's for a separate question I suppose.

So my question is, is it possible, and if so, how? Also, is the I2C connection meaningful for an ADXL345 that is primarily being used as a wake-up interrupt on the Z-axis only? (My use case is an item someone picks up, which wakes my embedded circuit out of sleep and begins logging load cell and UWB sensor data, and is put back to sleep after a period of inactivity).

Thanks in advance - I appreciate any and all help!

  • If you don't have anything in the ISR, you could use EMPTY_INTERRUPT(INT0_vect); instead. Secondly, the Atmega328P can wake up from falling edge interrupt to (though the datasheets states differently). What I sometimes to is disabled the INT0 interrupt inside the ISR, so it only fires once; then enable it again before I go to sleep. The accelerometer probably doesn't remember any settings, so you'd still need the I2C to setup the ADXL345 at power-up. – Gerben Nov 2 '16 at 18:58
  • So I would have a setup function, a loop function, and an ISR. I would configure the ADXL345 in my setup, run a loop that puts my microcontroller to sleep, and use an ISR for when my accelerometer receives a double tap (for example). In the ISR, the microcontroller wakes from sleep, and I would also disable the interrupt, and point the program back to my setup to refresh my accelerometer setup, reattach an interrupt, and run the loop to go to sleep again. Does this sound correct? – A. Orchard Nov 2 '16 at 19:22
  • Mostly, yes. You only need to setup the accelerometer once. By "power-up" I meant applying power. So e.g. when you insert new batteries. – Gerben Nov 2 '16 at 19:52
  • Do you have any example code where you do this all? – A. Orchard Nov 2 '16 at 19:57
0

When using an ADXL345 to trigger an interrupt to wake an Arduino, I2C (or SPI) need not be relevant. Instead, you can just connect pin 8 or 9 (INT1, INT2) of the ADXL345 directly to the Arduino pin that wakes the Arduino. Note, INT1 and INT2 in this answer refer to pins 8 and 9 of the ADXL345.

On the ADXL345, map the wake-up event (or events) to whichever of INT1 or INT2 (pin 8 or 9 on the ADXL345) you've connected to the Arduino. By sending commands from the Arduino to the ADXL345, you can map multiple events to INT1 and INT2 on the ADXL345, and might have both of them connected to different pins on the Arduino for different purposes.

As noted on page 20 of the Analog Devices ADXL345.pdf Rev. E datasheet,

The default configuration of the interrupt pins is active high. This can be changed to active low by setting the INT_INVERT bit in the DATA_FORMAT (Address 0x31) register.

How do I toggle bits in an ADXL345?

You can use SPI or I2C to set up registers on the ADXL345. You will need to configure the unit before it does anything, because it powers up into standby mode. See the second paragraph of POWER SEQUENCING, page 13 in spec sheet, and see Table 6 on that same page:

At power-up, the device is in standby mode, awaiting a command to enter measurement mode, and all sensor functions are off. After the device is instructed to enter measurement mode, all sensor functions are available.

  • When you say map the wake-up event to INT1 (digital 2) on the Arduino, do you mean in Arduino code? Also, how do I toggle bits in an ADXL345 - do I do it through my Arduino IDE? – A. Orchard Nov 2 '16 at 18:45
  • @A.Orchard, please see added paragraphs at end of answer. Also, I rephrased some 'map' refs, eg, “By sending commands from the Arduino to the ADXL345, you can map multiple events to INT1 and INT2 on the ADXL345” – James Waldby - jwpat7 Nov 2 '16 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.