Class Attributes
Set/Get Property
This sensor class provides additional functions that can be used to set or get some of the properties specific to this sensor.
The following table lists the set/get properties of the sensor class:
| Set/Get properties | Description |
get_available_data_rates() |
Returns the data rates that can be used for this channel. |
set_data_rate(data_rate) |
Sets the data rate to be used for this channel. |
get_data_rate() |
Returns the current data rate for this channel. |
set_measure_range(measurerange) |
Sets the measure range. Pass 0 to set +-2g, 1 for +-8g |
get_measure_range() |
Returns the current measure range. Returns 0 for +-2g, 1 for +-8g |
Example
from sensor import *
import e32
import time
class DemoApp():
def __init__(self):
self.accelerometer = \
AccelerometerXYZAxisData(data_filter=LowPassFilter())
self.accelerometer.set_callback(data_callback=self.my_callback)
self.counter = 0
def my_callback(self):
# For stream sensor data the callback is hit 35 times per sec(On 5800).
# The device cannot handle resource hungry operations like print in the
# callback function for such high frequencies. A workaround is to
# sample the data as demonstrated below.
if self.counter % 5 == 0:
print "X:%s, Y:%s, Z:%s" % (self.accelerometer.x,
self.accelerometer.y, self.accelerometer.z)
print "Timestamp:", self.accelerometer.timestamp
self.counter = self.counter + 1
def run(self):
self.accelerometer.start_listening()
if __name__ == '__main__':
d = DemoApp()
d.run()
e32.ao_sleep(5)
d.accelerometer.stop_listening()
print "Exiting Accelorometer"
See About this document... for information on suggesting changes.