6

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

Question How can I get the values from 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?

UserK
  • 884
  • 3
  • 17
  • 40
  • 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 Nov 04 '15 at 16:34
  • Unfortunately, the screen is broken, the only possible interaction is through the usb cable. – UserK Nov 04 '15 at 16:37
  • Whats the problem on launching the app through adb? you can even install a new one. – Nanoc Nov 04 '15 at 16:44
  • I'm looking for an app that enables all the sensors at once... Found Sensor Kinects. I'll try it and let you know! – UserK Nov 04 '15 at 16:45
  • 1
    Have you thinked on posting the sensors data on your computer or a server through network? or is that out of your requirements? – Nanoc Nov 04 '15 at 16:47
  • I'm actually trying to recycle sensors from a broken device and use them to estimate the orientation. First I need to retrieve the data from the phone, next to use them in a script and send the result to a raspberry pi connected via usb. If I set up a network, would I get the same result or a better ones? – UserK Nov 04 '15 at 16:57
  • 1
    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 Nov 04 '15 at 16:59
  • I think you can write a candidate answer explaining what you are suggesting. – UserK Nov 04 '15 at 17:02
  • 1
    for anyone wondering how to use a android phone with broken screen, connect usb and use scrcpy, then you can interact with it using your mouse and keyboard – eroc123 Dec 25 '22 at 04:45

2 Answers2

3

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
Micko
  • 41
  • 1
  • 5
-1

nice, that worked

cd /sys/class/input/input6  
echo 1 > enable # TO ACTIVATE THE SENSOR  
echo 0 > enable # TO TURN IT OFF AGAIN
greybeard
  • 2,249
  • 8
  • 30
  • 66
Victor
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 02 '22 at 11:05