views:

134

answers:

4

I'm making an accelerometer based app using cocos2d, and I noticed that it's possible to set the accelerometer update time.

[[UIAccelerometer sharedAccelerometer] setUpdateInterval: (1.0f / 60.0f)];

I was wondering if updating the accelerometer very often like this, 60 times a second is a battery drain? Or should I not worry at all?

+1  A: 

http://www.google.com/search?hl=en&client=firefox-a&hs=7ew&rls=org.mozilla%3Aen-US%3Aofficial&q=iPhone+accelerometer+battery+drain&aq=f&aqi=m1&aql=&oq=&gs_rfai=

My answer would be yes. It does drain battery faster. And 60 times / seconds is excessive.

VOX
Ah, thanks. :) Do you know how many times a second it normally updates when you don't touch the -setUpdateInterval: method?
Johannes Jensen
I'm just doing a quick google search to give you a quick answer. However, I don't know default update rate. I would suggest you should update it the same rate as your framerate. Because I think it'd be wise to update the screen the same time as soon as you get new accelerometer data.
VOX
+3  A: 

According to the LIS302DL accelerometer data sheet, it consumes ~0.75 mWatts of power at an update rate of 100Hz, and 0.0025 mWatts of power when in stand-by mode (i.e., no readings taking place).

So, the short answer is "Yes", but off the top of my head, I can't put those numbers in perspective to give you an idea of, say, "how many minutes of on time" it drains from the battery.

My recommendation would be to do a bit of testing. Find the lowest update rate that provides satisfactory results.

johne
+2  A: 

From the Event Handling Guide for iPhone OS:

When configuring the update interval for acceleration events, it is best to choose an interval that minimizes the number of delivered events and still meets the needs of your application. Few applications need acceleration events delivered 100 times a second. Using a lower frequency prevents your application from running as often and can therefore improve battery life.

According to this, the more expensive part of having a high update frequency may be the fact that your application has to process each of those accelerometer events, rather than idling for a longer period.

Also, from the iPhone Application Programming Guide:

If you use the UIAccelerometer class to receive regular accelerometer events, disable the delivery of those events when you do not need them. Similarly, set the frequency of event delivery to the smallest value that is suitable for your needs.

Brad Larson
More information how to "disable the delivery of those events", from the above-linked Event Handling Guide:"To stop the delivery of acceleration events, set the delegate of the shared UIAccelerometer object to nil. Setting the delegate object to nil lets the system know that it can turn off the accelerometer hardware as needed and thus save battery life."
Glenn Barnett
+1  A: 

Given the numbers in the accepted answer the power usage by the actual accelerometer is trivial. Your real hit will come from your app having to process the events and thus making the CPU not sleep more often.

The 3GS has a 4.51 Watt hour battery. Drain from only the accelerometer when running at 100 hz would kill the battery in (roughly) 6000 hours (assuming the 0.75 mW value is correct)

(Also, the iPhone 4 has a 5.25 Watt hour battery, in case you're curious)

Donnie