Go Down

Topic: arduino pro mini sleep / wake up with adxl345 (Read 283 times) previous topic - next topic

ardushine

I connected the INT1 port of the adxl345 to PIN2 of the pro mini. For the rest I am using the I2C protocol and have it powered with VCC and GND.
The sensor itself works fine and is delivering good data to the pro mini.

To enhance the bat life, I want to put the Arduino pro mini to sleep and wake it up with adxl345. In the way that when the adxl345 detects INACTiVITY, the pro mini goes to sleep, and when it does not detect INACTIVITY, it wakes up.

Sparkfun gave me the attached program, but somehow it seems to not to work.

Any hints on what I am doing wrong?

Any help is greatly appreciated!

pylon

Default configuration for the interrupt pins is active high, so why are you activating the interrupt at low?

If the above description of the connections is the complete wiring (you should post a wiring diagram) you probably have the problem that as soon as the Mini falls asleep, the pull-ups for the I2C get inactive and the bus is floating. In that state the reaction of the ADXL345 is not defined, so you don't know what will happen.
Most probably you have another wiring, as with just the internal pull-ups you may damage the ADXL345. I guess that you're using some kind of breakout board but you didn't post the schematics of that board. This information is important.

ardushine

Dear pylon,
thx so much for your quick answer!
The wiring is:

adxl        adxl            pro mini

GND        SDO           GND
VCC                         VCC
INT1                        PIN2
SDA                         SDA
SCL                         SCL

I am using the adxl345 from sparkfun https://www.sparkfun.com/products/9836
and the pro mini https://www.sparkfun.com/products/11114

Since I conected the INT1 with the PIN2, I thought that I2C inactivity would not hurt me...

Does that info help?
Again, thx so much!

pylon

If you have the board you linked to, you have a Pro Mini 3.3V/8MHz, which makes a difference as the default is the 5V/16MHz version.

Have you tried to change the interrupt trigger signal as I suggested? This probably will already fix your issue.

I don't know how the ADXL345 reacts on a floating bus, it might simply run as expected but it might also decide that no one is listening and don't activate the interrupt.

ardushine

I am sorry, I am not sure which change eaxtly you want me to do. Do you want me to change line 115?

pylon

Quote
I am sorry, I am not sure which change eaxtly you want me to do. Do you want me to change line 115?
115 is an empty line in the code you posted. I thought about line 117. Change LOW to RISING.

ardushine

Hi pylon,

thx so much! It feels like a big step towards the goal:=)

When I change in line 117 LOW->RISING, not even the name of the code (SparkFun ADXL345 Accelerometer Hook Up Guide Example) is displayed entirely

After out commenting lines 121 and 124 at least it works somehow. The name is displayed, and the message "Going to sleep" pops up.

BUT every 10 seconds it displays the current acceleration and it says "going to sleep" again.

That feels like the command
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
is not a sleep_forever command:=)

Any hints? Thx so much for your time and affords!!!

pylon

Quote
When I change in line 117 LOW->RISING, not even the name of the code (SparkFun ADXL345 Accelerometer Hook Up Guide Example) is displayed entirely
That's because serial output is written into a buffer and effectively sent later on in interrupts. Insert a Serial.flush() after line 51 in your code and the complete line will display before the code is going on.

Quote
After out commenting lines 121 and 124 at least it works somehow. The name is displayed, and the message "Going to sleep" pops up.
That is only display because of the delay() calls after it.

Quote
BUT every 10 seconds it displays the current acceleration and it says "going to sleep" again.

That feels like the command
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
is not a sleep_forever command:=)
Is it exactly 10 seconds? Did you check the ADXL345 interrupt line?
The SLEEP_FOREVER just means that the watchdog timer is not activated. Any other wake up source is still active.

ardushine

Thx so much for your help!!!

I inserted Serial.flush(); after line 51.
You were right, the name shows up again.
Then the inactivity notification popped up every 10.1 seconds again (I guess the 0.1 comes from me pushing the stop watch button).
I than reactivated lines 122 and 125.
Current status is now, that the prog name is displayed, and nothing else. Only the name, no going to sleep or whats so ever.
Due to lines 140 to 144 I would have estimated to see at least the acceleration values for the first ten seconds. But - I don't. Can you also explain why?

pylon

The ten seconds are the inactivity timeout of the ADXL345 (you set it to 10s in the setup()). So you get interrupted from it after that amount of time. Deactivate that timeout and your Arduino will sleep forever.

Quote
Due to lines 140 to 144 I would have estimated to see at least the acceleration values for the first ten seconds. But - I don't. Can you also explain why?
I would expect it to see after 20s as you put the Arduino to sleep twice before that happens. Insert a Serial.flush() above each sleep command to have the serial queue emptied before it goes asleep.

ardushine

I deactivated line 70 and put a Serial.flush(); into lines 119 and 178.

Result: Only the name was displayed. Did I misunderstand you?

Also: If I deactivate line 70, how is sketch supposed to know when to detect INACTIVITY? 

pylon

Deactivate line 90. You can configure any time as long as the interrupt doesn't fire.

Quote
Result: Only the name was displayed. Did I misunderstand you?
What name is displayed?

Quote
Also: If I deactivate line 70, how is sketch supposed to know when to detect INACTIVITY?
Why does it have to know? Do you want it to sleep forever or just until the inactivity timeout fires? Define what you want to achieve!

ardushine

the displayed name is "SparkFun ADXL345 Accelerometer Hook Up Guide Example"



The intention is to

have the board detect a TAB, perform a measurement (both things work),
then
detect INACTIVITY and go to sleep //that works if I set line 90 to 0, correct?
until
DOUBLE TAB is detected -> wake up  //that works if I set line 93 to 1, correct?
then
receive a TAB and perform the measurement again
OR
detect INACTIVITY and go to sleep again
and so on


ardushine

Btw, I am well aware, that the code posted by me beforehand does not achieve all I stated in the post above. I just wanted to see one item working, and than develop the rest by my self. I did not want to bother anyone with my specific challenge. But I figured the general solution / problem might be of common interest. Pls correct me if I am wrong

pylon

Quote
detect INACTIVITY and go to sleep //that works if I set line 90 to 0, correct?
No, that change would deactivate the detection of inactivity completely.
But as far as I understood the datasheet so far you should leave line 90 as it is but once you detected inactivity you should deactivate that interrupt source and then go to sleep.

Quote
DOUBLE TAB is detected -> wake up  //that works if I set line 93 to 1, correct?
Yes and no, if you leave the rest of the program as it is, it will wake up by every event (TAB also).

If you want to get above functionality you have to change the interrupt configuration of the sensor chip for every event received. This is especially important if you put the Arduino to sleep as any interrupt will wake it up.

Go Up