[Q] Proximity Sensor Calibration

mcelicalderon

New member
Sep 8, 2013
3
10
0
Not True

A full Odin restore should reset all these values and the whole thing should work right immediately as long as the sensor hardware hasn't gone bad, right?
Sadly, no. I would have thought so too, but recently I did a full Odin restore and that didn't fix the problem. I-m not sure why, as I thought that wipped everything on my phone. I believe it has something to do with the fact that doing a full ODIN restore won't necessarily restore your EFS partition, and I believe that's where the problem is. Actually be very careful not to wipe you EFS partition using ODIN as that's where your device's info is stored (That's what I found searching online).

But, as I said in my lateest post in this thread, following the steps described in this post about echoing your calibration values to you /efs/prox_cal file actually fixed my problem. Good luck!
 

jeromechin

New member
Nov 30, 2010
1
0
0
It worked!!

Easy FIX!!!!!
I took a can of compressed air and blew it through the top earpiece grill a few times and Voila, it works great now!!

I actually used a Old perfume can which perfume was over and it was only pressing Gas OFF!! :p:p :good::good::good::good:

This worked immediately!! Thank you so so much! I could not believe it! I thought I damaged the sensor after dropping the phone.

Thanks!! :good::good::good::good::victory:
 

czar22

Senior Member
Apr 19, 2011
460
610
133
so I did

Code:
$ echo -en $'\x74' > /efs/prox_cal
and then

Code:
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
$ sync
After that I rebooted my phone from the terminal using que command

Code:
$ reboot
-- Error

' not found

---------- Post added at 08:47 AM ---------- Previous post was at 08:40 AM ----------

after many attempt's i try the "Blow Air" method ---

and Succes

Thxxxxxx...
 

azawarai

Member
Sep 18, 2013
20
1
0
istanbul
so I did

Code:
$ echo -en $'\x74' > /efs/prox_cal
and then

Code:
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
$ sync
After that I rebooted my phone from the terminal using que command

Code:
$ reboot
-- Error

' not found

---------- Post added at 08:47 AM ---------- Previous post was at 08:40 AM ----------

after many attempt's i try the "Blow Air" method ---

and Succes

Thxxxxxx...
Codes worked on i9500. Thanks!
 

Fataldose

Senior Member
Oct 25, 2012
606
151
73
Ankara
On Samsung devices like i9100 (Galaxy S3) or N7100 (Note II) you can do the following if you have root permissions:

On Android Terminal App or adb shell do:
Code:
$ su
$ echo 0 > /sys/class/sensors/proximity_sensor/prox_cal
$ echo 1 > /sys/class/sensors/proximity_sensor/prox_cal
The zero resets the actual calibration offset.
The one does an auto calibration (read sensor value, set offset to this sensor value, write calibration offset to "/efs/prox_cal" which is read while device is booting).
Best for calibrate your sensor is to keep it dark, the glass have to be clean and the sensor free (so that the sensor doesn't measure anything).
The calibration offset is stored in efs, thats why you can make full wipe and use other ROMs without the need of recalibration.

You can check the running config by:
Code:
$ cat /sys/class/sensors/proximity_sensor/state
The first value is the calibration Offset, the second one is the sensor threshold (threshold is set at compile time).

Open *#0*# to see "sensors" and check if your proximity sensor is now working properly.


Because in Kernel code (copyright by Samsung) for the device driver is somthing like this autocalibration, i bet that there is a secret menue or code that does the calibration too. But until someone discovers this secret we have to have root permissions to do a proximity sensor calibration.

Thanks a lot man.
 

andr_lee

New member
Nov 1, 2013
3
2
0
I can't believe it!!!!

Finally, this fixed my problem. I don't know why, but the other solution worked one time while using a CM 10.2 nightly

Code:
$ su
$ echo 0 > /sys/devices/virtual/sensors/proximity_sensor/prox_cal
$ echo 1 > /sys/devices/virtual/sensors/proximity_sensor/prox_cal
But, when I upgraded to the latest nightly, this stopped working. It wouldn't work even if y restored my stock ROM backup using TWRP, I even flashed a stock image with odin and the sensor would still malfunction.

Today I followed this steps using the values returned for my phone and it finally worked! I did this.

Code:
$ cat state #finger on the sensor to test if the sensor is working properly
120
$ cat state #blank value
10
This returned 255 #finger on the sensor and 69 #blank value

and when I did
Code:
 cat /sys/devices/virtual/sensors/proximity_sensor/prox_cal
this returned 47,60,45.....so my offset was 47. Ths sum of offset and #blank value was 47 + 69 = 116 that is equal to 74 in HEX.

so I did

Code:
$ echo -en $'\x74' > /efs/prox_cal
and then

Code:
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
$ sync
After that I rebooted my phone from the terminal using que command

Code:
$ reboot
and that was it! Now my sensor is fixed and survives reboot. Thanks!

I executed this procedure just as a longshot after trying so many other things. And my Galaxy S4 works perfectly now. Unbelievable!!! Thanks :)
 
  • Like
Reactions: aleson and johnhe4

LiMunnn

Member
Apr 28, 2011
7
0
0
Hello friends, I have a problem with samsung s4 (proximity sensors) sensor as the non-stop running, I went to test the ADC 130, and when you put your finger on the sensor, then the 255, I tried to change the value in / sys / class / sensors / proximity_sensor /prox_cat but I could if my phone is rooted, if someone can help me please
 

Attachments

vchawla

Member
Mar 5, 2010
5
2
0
I executed this procedure just as a longshot after trying so many other things. And my Galaxy S4 works perfectly now. Unbelievable!!! Thanks :)
Same for my S4. Air can method only got me down from 255 to 160 with the sensor uncovered. This procedure restore my proximity sensor such that it is now usable again.
 

Ammar Saood

Senior Member
Jan 23, 2012
118
114
0
FIXED. Thanks to mcelicalderon, Finally Fixed

Methods that worked for me.
Method 1.
Blow Air it will solve your prob hopefully.

Method 2.
go to samsung code *#0*#. then SENSORS and Read your Proximity sensor values.

<<< DECISION >>>>>
####Calibration isnot needed if ####
.
your phone doesnt vibrate in normal but does so when u physically put your finger on the Sensor.

#### Calibration needed if ####
.
your phone is vibrating in this menu no matter what, you put your finger on the sensor or not
Follow these steps
1. download Android Terminal from store
2. type these commands to calibrate automatically
$ su
# echo 0 > /sys/devices/virtual/sensors/proximity_sensor/prox_cal
# echo 1 > /sys/devices/virtual/sensors/proximity_sensor/prox_cal

Reboot and see if it works.go to *#0*# and check if it continuously vibrating or only does so when you put your finger on the SENSOR.

<<<< IF Continuously Vibrating Follow these steps>>>>

you need to manually put values in ur /efs/prox_cal.it Reads Hexadecimal value. so you have to convert your decimal values into HEX.

##### FIND YOUR Decimal Values and pushing them into /efs/prox_cal ######

Method : finding two values for calibration . offset + normal value.
##.. FINDING OFFSET ######
cat /sys/devices/virtual/sensors/proximity_sensor/prox_cal

note down the values it returns.. mine is 5,64,100.. you only need the 1st value which is 5.
### FINDING NORMAL STATE ######

cat /sys/devices/virtual/sensors/proximity_sensor/state
note down the value if returns. mine is 64

now ADD OFFSET value + Normal Value
5 + 64 = 69
Convert in Hexadecimal which is 45.

<<<<<<<<<<< Pushing the value in /efs/prox_cal >>>>>>>>>>>>>>

# echo -en $ '\x45' > /efs/prox_cal

then
# chown system:system /efs/prox_cal
# chmod 644 /efs/prox_cal
# sync
# Reboot

All done. after that go to *#0*# then SENSORS and move your finger on the sensor, yout phone will Vibrate only when you put your finger on the sensors.

Manual method worked for me.
ENJOY.
 

wujh

New member
Dec 13, 2013
2
0
0
I described the sensor recalibration on Samsung rom or Samsung based roms. " *#0*# "is a "secret code" that starts a samsung test tool - only included in stock or stock rom based.

I have read from other users that "cat state" returns zero. I don't know exactly why. But it could be because:
1. that the sensor is powered down (on my phone the sensor never sleeps)
2. the calibration offset is too high
3. the calibration offset is optimal
To test the sensor is on and working you should read the value with finger put on. (there should be value around 127-calibration offset). I guess to do the calibration/sensor reading with display on and phone unlocked. Another user told me that it helped to start an app which reads the sensor values (so the sensor wake up).

But in your case proximity_sensor with the values 18,9 means that the sensor is already calibrated to 18 which can cause a zero at "cat state".
Note that the offset is read from file calibration file at boot time and from that on holded in ram. The RAM value can only be influenced by "/sys/class/sensors/proximity_sensor/prox_cal" or by calibration file (on boot). The auto calibration process not only try to create a /efs/prox_cal file but also changes the calibration value in ram at run time .
So if you try "echo 0 > /sys/class/sensors/proximity_sensor/prox_cal; echo 1 > /sys/class/sensors/proximity_sensor/prox_cal" -> "mmh auto calibration does not work there is no prox_cal file, i will try it manually" can be the wrong way because the calibration offset can be already changed to a calibrated value and so you wont get the correct blank value read out "state".


The other path in virtual filesystem to the sensor control you mentioned is also correct. I don't know which is the most common one.
But since both pathes are available in samsung stock i guess it should be " /sys/devices/virtual/sensors/proximity_sensor".



Be careful of putting in the calibration value manually. In Samsung stock rom the kernel which is reading the calibration value at boot time don't make a character conversion. So if you write the config file like this:
Code:
echo '18,9' > /efs/prox_cal
Ends Up with Calibration value of 49 because the kernel will read the first byte of file. This is a "1" which is the ASCII code for "0x31" which is 49 in decimal. That should work too but throw away half of the sensor sensivity.


If you would like to calibrate it manually you have to:

Code:
cd /sys/devices/virtual/sensors/proximity_sensor/
Read the blank value ( glass have to be clean and fingers away from sensor ).
Code:
$ cat state #finger on the sensor to test if the sensor is working properly
120
$ cat state #blank value
10
Read the actual configuration:
Code:
$ cat prox_cal
0,9
The first value is the "sensor offset" and the second one is "Cancelation Threshold" (threshold can not stored in calibration file)

So you calculate your calibration value: 0 (actual sensor offset) + 10 (blank value) = 10 (new offset) = 0x0a HEX. Make shure your efs partition is mounted writeable and then:

Code:
$ su
$ echo -en $'\x[B]0a[/B]' > /efs/prox_cal
$ sync
If the prox_cal is created first you should change the permisssions. Kernel sets 666 by default :

Code:
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
$ sync
After reboot you can confirm the calibration

Code:
$ cat /sys/devices/virtual/sensors/proximity_sensor/prox_cal
10,9
$ cat  /sys/devices/virtual/sensors/proximity_sensor/state
0

If you have to calibrate to a lower sensor value and want to do it the "manual way" you have to reset the calibration or delete the calibration file and reboot. because state value = sensor value - offset . And if offset gets to big the state is alway zero.

I was using S4 MINI
When my finger on the sensor to test ,The maximum value of only to 7, with white paper to cover the value may to 14 (more than 10) Action
How to use the manual adjustment value from (0,10) to (0,5), Because I enter # echo -en $ '\x05' > /efs/prox_cal ,Will become (5,10), To take action as more than 10
When I enter $ echo ‘0,5’ > /efs/prox_cal ,Will become (171256880,58), Use white paper will not operate。(14<58)
How do I enter in order to reduce "Cancelation Threshold"=5 , prox_cal value from (0,10) to (0,5)

Sorry, my English is not good, hoping to understand what I mean
 

wujh

New member
Dec 13, 2013
2
0
0
Thank you for your answer.
I have tried this method but without effect.
Because my hand to cover the sensor, the value only to 7, so I want to adjust this value back 10 to 5(prox_cal 0,10->0,5), when it will hand to cover the action, without the use white paper
 

peter_baum

New member
Dec 18, 2010
4
0
0
be careful about spaces

I think there should not be any space between the dollar sign and the single quoted string. Try
Code:
$ echo -en $'\x0a' > /efs/prox_cal
instead of
Code:
$ echo -en $ '\x0a' > /efs/prox_cal
 

Maozvi

New member
Dec 24, 2013
1
0
0
Thanks!

I described the sensor recalibration on Samsung rom or Samsung based roms. " *#0*# "is a "secret code" that starts a samsung test tool - only included in stock or stock rom based.

I have read from other users that "cat state" returns zero. I don't know exactly why. But it could be because:
1. that the sensor is powered down (on my phone the sensor never sleeps)
2. the calibration offset is too high
3. the calibration offset is optimal
To test the sensor is on and working you should read the value with finger put on. (there should be value around 127-calibration offset). I guess to do the calibration/sensor reading with display on and phone unlocked. Another user told me that it helped to start an app which reads the sensor values (so the sensor wake up).

But in your case proximity_sensor with the values 18,9 means that the sensor is already calibrated to 18 which can cause a zero at "cat state".
Note that the offset is read from file calibration file at boot time and from that on holded in ram. The RAM value can only be influenced by "/sys/class/sensors/proximity_sensor/prox_cal" or by calibration file (on boot). The auto calibration process not only try to create a /efs/prox_cal file but also changes the calibration value in ram at run time .
So if you try "echo 0 > /sys/class/sensors/proximity_sensor/prox_cal; echo 1 > /sys/class/sensors/proximity_sensor/prox_cal" -> "mmh auto calibration does not work there is no prox_cal file, i will try it manually" can be the wrong way because the calibration offset can be already changed to a calibrated value and so you wont get the correct blank value read out "state".


The other path in virtual filesystem to the sensor control you mentioned is also correct. I don't know which is the most common one.
But since both pathes are available in samsung stock i guess it should be " /sys/devices/virtual/sensors/proximity_sensor".



Be careful of putting in the calibration value manually. In Samsung stock rom the kernel which is reading the calibration value at boot time don't make a character conversion. So if you write the config file like this:
Code:
echo '18,9' > /efs/prox_cal
Ends Up with Calibration value of 49 because the kernel will read the first byte of file. This is a "1" which is the ASCII code for "0x31" which is 49 in decimal. That should work too but throw away half of the sensor sensivity.


If you would like to calibrate it manually you have to:

Code:
cd /sys/devices/virtual/sensors/proximity_sensor/
Read the blank value ( glass have to be clean and fingers away from sensor ).
Code:
$ cat state #finger on the sensor to test if the sensor is working properly
120
$ cat state #blank value
10
Read the actual configuration:
Code:
$ cat prox_cal
0,9
The first value is the "sensor offset" and the second one is "Cancelation Threshold" (threshold can not stored in calibration file)

So you calculate your calibration value: 0 (actual sensor offset) + 10 (blank value) = 10 (new offset) = 0x0a HEX. Make shure your efs partition is mounted writeable and then:

Code:
$ su
$ echo -en $'\x[B]0a[/B]' > /efs/prox_cal
$ sync
If the prox_cal is created first you should change the permisssions. Kernel sets 666 by default :

Code:
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
$ sync
After reboot you can confirm the calibration

Code:
$ cat /sys/devices/virtual/sensors/proximity_sensor/prox_cal
10,9
$ cat  /sys/devices/virtual/sensors/proximity_sensor/state
0

If you have to calibrate to a lower sensor value and want to do it the "manual way" you have to reset the calibration or delete the calibration file and reboot. because state value = sensor value - offset . And if offset gets to big the state is alway zero.

Many thanks! this method solve this issue for me :)
 

Lightning

New member
Aug 28, 2006
3
1
0
I described the sensor recalibration on Samsung rom or Samsung based roms. " *#0*# "is a "secret code" that starts a samsung test tool - only included in stock or stock rom based.

I have read from other users that "cat state" returns zero. I don't know exactly why. But it could be because:
1. that the sensor is powered down (on my phone the sensor never sleeps)
2. the calibration offset is too high
3. the calibration offset is optimal
To test the sensor is on and working you should read the value with finger put on. (there should be value around 127-calibration offset). I guess to do the calibration/sensor reading with display on and phone unlocked. Another user told me that it helped to start an app which reads the sensor values (so the sensor wake up).

But in your case proximity_sensor with the values 18,9 means that the sensor is already calibrated to 18 which can cause a zero at "cat state".
Note that the offset is read from file calibration file at boot time and from that on holded in ram. The RAM value can only be influenced by "/sys/class/sensors/proximity_sensor/prox_cal" or by calibration file (on boot). The auto calibration process not only try to create a /efs/prox_cal file but also changes the calibration value in ram at run time .
So if you try "echo 0 > /sys/class/sensors/proximity_sensor/prox_cal; echo 1 > /sys/class/sensors/proximity_sensor/prox_cal" -> "mmh auto calibration does not work there is no prox_cal file, i will try it manually" can be the wrong way because the calibration offset can be already changed to a calibrated value and so you wont get the correct blank value read out "state".


The other path in virtual filesystem to the sensor control you mentioned is also correct. I don't know which is the most common one.
But since both pathes are available in samsung stock i guess it should be " /sys/devices/virtual/sensors/proximity_sensor".



Be careful of putting in the calibration value manually. In Samsung stock rom the kernel which is reading the calibration value at boot time don't make a character conversion. So if you write the config file like this:
Code:
echo '18,9' > /efs/prox_cal
Ends Up with Calibration value of 49 because the kernel will read the first byte of file. This is a "1" which is the ASCII code for "0x31" which is 49 in decimal. That should work too but throw away half of the sensor sensivity.


If you would like to calibrate it manually you have to:

Code:
cd /sys/devices/virtual/sensors/proximity_sensor/
Read the blank value ( glass have to be clean and fingers away from sensor ).
Code:
$ cat state #finger on the sensor to test if the sensor is working properly
120
$ cat state #blank value
10
Read the actual configuration:
Code:
$ cat prox_cal
0,9
The first value is the "sensor offset" and the second one is "Cancelation Threshold" (threshold can not stored in calibration file)

So you calculate your calibration value: 0 (actual sensor offset) + 10 (blank value) = 10 (new offset) = 0x0a HEX. Make shure your efs partition is mounted writeable and then:

Code:
$ su
$ echo -en $'\x[B]0a[/B]' > /efs/prox_cal
$ sync
If the prox_cal is created first you should change the permisssions. Kernel sets 666 by default :

Code:
$ chown system:system /efs/prox_cal
$ chmod 644 /efs/prox_cal
$ sync
After reboot you can confirm the calibration

Code:
$ cat /sys/devices/virtual/sensors/proximity_sensor/prox_cal
10,9
$ cat  /sys/devices/virtual/sensors/proximity_sensor/state
0

If you have to calibrate to a lower sensor value and want to do it the "manual way" you have to reset the calibration or delete the calibration file and reboot. because state value = sensor value - offset . And if offset gets to big the state is alway zero.
Well done for working that out.... it's the only thing that worked for me ;)

(i must admit i needed to use a hex calculator)

PS This worked on my Samsung Galaxy S3 SCH-i535
 
Last edited: