Archived:Using the PySymbian Sensor module
All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.
This code snippet shows how to use the PySymbian Sensor module in pys60 to access the Symbian rotation and accelaration sensors. Note that the sensor framework has not been implemented in PySymbian . This is for use with older devices.
Article Metadata
Tested with
Compatibility
Article
First of all import sensor and e32 module
import e32
import sensor
Now Lets see the available sensors
sensor.sensors()
To get the acceleration sensor
# if you wants to get Rotation sensor Change 'AccSensor' to 'RotSensor'
accsensor=sensor.get('AccSensor')
To get the id and category of acceleration sensor
id=accsensor.get('id')
cat=accsensor.get('cat')
Create a callback for sensor events
def printout(value):
print value
Now lets get the object of Acceleration Sensor
senobj=sensor.Sensor(id,cat)
lets set an event filter for the acceleration filter
#if you are working with rotation sensor then change sensor.OrientationEventFilter() to sensor.RotEventFilter()
# if you wants to get low level data then sensor.EventFilter() which is the base event filter class.
senobj.set_event_filter(sensor.OrientationEventFilter())
lets connect to the sensor
senobj.connect(printout)
wait for 15 seconds
e32.ao_sleep(15)
Disconnect from the sensor
senobj.disconnect()
Thats it for now. the complete code is listed below for Acceleration Sensor:
# __author__='Fayyaz Ali'
# version = '1.0 beta'
# license='GNU GPL'
import e32
import sensor
sensor.sensors()
accsensor=sensor.get('AccSensor')
id=accsensor.get('id')
cat=accsensor.get('cat')
def printout(value):
print value
senobj=sensor.Sensor(id,cat)
senobj.set_event_filter(sensor.OrientationEventFilter())
senobj.connect(printout)
e32.ao_sleep(15)
senobj.disconnect()
for Rotation Sensor:
# __author__='Fayyaz Ali'
# version = '1.0 beta'
# license='GNU GPL'
import e32
import sensor
sensor.sensors()
accsensor=sensor.get('RotSensor')
id=accsensor.get('id')
cat=accsensor.get('cat')
def printout(value):
print value
senobj=sensor.Sensor(id,cat)
senobj.set_event_filter(sensor.RotEventFilter())
senobj.connect(printout)
e32.ao_sleep(15)
senobj.disconnect()
Additional information
Above code is written by Fayyaz Ali and is Licensed under gnu gpl.


18 Sep
2009
>>> sensor.get('AccSensor') Traceback (most recent call last):
AttributeError: 'module' object has no attribute 'get'
Getting KeyError for AccSensor
The code, as is, throws an error 'module' object has no attribute 'get'
I've modified the code to bypass that and things worked for the RotSensor but when I try the AccSensor, I get a KeyError.
The comment made about a month ago says "...you can not use this program directly on devices..."
I'm not sure what that means - if not devices then what...the emulator? I'm sure I'm missing something or mis-interpreting that comment. Any help?
Thanks!