5
votes

I just broke my s3. 3 years ago it was one of the best smartphones.

Question How can I get the values of the inertial sensors of the phone via usb?

I would like to use the accelerometer, gyroscope, magnetometer, barometer and gps sensors of the device.

Let's say that we want to get:

  • the raw acceleration's data along the three axes.

I connected the usb cable and ran adb root and adb shell. Ok.

root@android:/ # find / -type d -iname "sensors"                           
/sys/devices/virtual/sensors
/sys/class/sensors

The '/sys/class/sensors' directory contains:

root@android:/ # ls sys/class/sensors                                          
accelerometer_sensor
barometer_sensor
gyro_sensor
light_sensor
magnetic_sensor
proximity_sensor

The problem

The raw measurements do not change even if I tilt the phone. The sensor is in standby mode. It always displays the same values.

root@android:/sys/class/sensors/accelerometer_sensor # cat raw_data            
-74,121,1016

I have noticed the folder power/control which controls the power state of the sensor.

root@android:/sys/class/sensors/accelerometer_sensor # cat power/control       
auto

I tried with echo on/yes/ok/yeah/wtf > power/control but nothing changed.

I remember that when I had the screen of the phone working, it was sufficient to open an Android application with sensors' permissions, like Google Maps with the compass feature, to Enable the sensors and get the values refreshed at a constant rate. The Java application probably writes something in a file to activate the sensors and reads the raw values.

How can I activate the sensors from the shell?

1
Not sure if you can make it, but still you can launch an app that uses it even with a broken screen to get the raw values updated or am i wrong? - Nanoc
Unfortunately, the screen is broken, the only possible interaction is through the usb cable. - UserK
Whats the problem on launching the app through adb? you can even install a new one. - Nanoc
Have you thinked on posting the sensors data on your computer or a server through network? or is that out of your requirements? - Nanoc
It doesnt matter if you get the result via usb cable or via network connection the data will be exactly the same... if you are going to post it to a raspberry a server may do the job of both receiving and sending - Nanoc

1 Answers

3
votes

Using

root@:/ # getevent -S

You can get the list of all sensor.. look for one called "proximity_sensor" and retrieve device name. Ex.

root@:/ # getevent -S
add device 1: /dev/input/event11
  name:     "compass_sensor"
add device 2: /dev/input/event8
  name:     "barometer_sensor"
add device 3: /dev/input/event7
  name:     "light_sensor"
add device 4: /dev/input/event6
  name:     "proximity_sensor"

As you can see your device is aliased as "event6"

Now, go inside directory /sys/class/input/input6

cd /sys/class/input/input6
echo 1 > enable # TO ACTIVATE THE SENSOR
echo 0 > enable # TO TURN IT OFF AGAIN