sparkfun / SparkFun_ADXL345_Arduino_Library

Arduino Library for the ADXL345
46 stars 52 forks source link

Interrupt #19

Open danieldeesousa opened 4 years ago

danieldeesousa commented 4 years ago

Has anyone successfully tested and found the interrupt to work when a freefall, tap, or activity event occurred?

DimiLaprog commented 3 years ago

Hi, For any interrupt with this library, here are some things to try:

  1. Put adxl.getInterruptSource(); after finishing the setup of the interrupt in the setup() and after attachInterrupt function. Reason for this is that during the setup, interrupts are triggered.
  2. Make sure that you know if your interrupt is active high or active low. I found that , active low works. To set the interrupt pins of adxl345 to active low , just do adxl.setInterruptLevelBit(1); at some point in the setup. Make sure that attachInterrupt has falling as a trigger. Setting it to just "LOW" was buggy for me.
  3. Make sure you have set ALL the parameters-functions for the specific interrupt you are trying to trigger with the proper thresholds. For example, if you are testing freefall from a distance of 20 cm, you must set the duration pretty low,even lower than the recommended values. eg adxl.setFreeFallDuration(12); . So i would say definitely play around with threshold values before giving up.
  4. IF you decide to put in the ISR (interrupt service routine), function: adxl.getInterruptSource(); causes CPU panic and errors. The reason for that is I guess , that it uses readFrom function which reads directly from wires and probably has some weird behavior in interrupt context.
  5. I strongly suggest using volatile variables if you want a variable to change in the ISR (for example a flag to notify the main loop that an interrupt has taken place). Reason for this is , registers can get pretty messed up in the transition to and from ISR, so it's best to read from RAM directly.
  6. Do some debugging in software, set the interrupt pin of your microcontroller/dev board to INPUT and see what values you are getting (serial print works). Do the same with the pins of ADXL345. Play around with giving and reading values and you might see what the problem is. Maybe your interrupt pin is not being initialised to the proper value (depending on active high or low interrupt) for example. Finally, change interrupt pins, I have seen in forums that PIN2 of adxl345 might be problematic in some cases with this library. I have not witnessed it myself , but definitely change pins both in the adxl345 and your development board.
  7. Check for hardware issues. One way to do that is to try and trigger the data_ready continuously. you should be getting constantly interrupts. Also check for hardware issues with a multimeter, short circuits etc. Finally, check your soldering that you probably have done in some component (adxl345 pins for example). It is many times the culprit. Good Luck. I hope I am not forgetting something.
stuomas commented 2 years ago

Hi, not sure if related to this library, but any tips how to use INT1 for deep sleep wake-up? I have inactivity and tap interrupts working, they activate and deactivate deep sleep as expected. However, the CPU is woken up after some time (~30 seconds) by itself, without touching anything. Any ideas what could cause this?

Edit: Upon further investigation, the auto-wakeup time depends on inactivity time set with for example setTimeInactivity(30). If I set it to 10s, it is also woken up after 10s.

Edit: OK so now I understood. Inactivity interrupt is still active in deep sleep. So upon X seconds of more inactivity, it triggers another inactivity interrupt, that in turn wakes up the CPU. So my solution is to disable inactivity interrupt (InactivityINT(0)) before activating deep sleep. Thanks all for being my rubber duck :P