Post Reply

[Q] Proximity Sensor Calibration

OP CrazyEngineer

25th February 2013, 09:38 PM   |  #11  
Junior Member
Thanks Meter: 1
 
1 posts
Join Date:Joined: Feb 2013
It looks like the proximity threshold is set too low in the kernel and causes this to misbehave when the sensor gets a little dirty.

For example: If you open the diagnostic menu by dialing *#0*# and look under sensors if your ADC value for the sensor is anything over 12, the proximity sensor will register that something is close to the phone. That value can be temporarily adjusted by setting prox_thresh under /sys/devices/virtual/sensors/proximity_sensor to something higher (like 30).

Unfortunately, it looks like changing this value doesn't "stick" and the next time the sensor is accessed, something changes it back to the default of 12.

I'm guessing that the default value is set in the kernel at compile time. Maybe someone can talk of the kernel devs into tweaking the value.
Last edited by yushir0; 25th February 2013 at 09:51 PM.
The Following User Says Thank You to yushir0 For This Useful Post: [ View ]
15th April 2013, 04:54 AM   |  #12  
Junior Member
Thanks Meter: 0
 
3 posts
Join Date:Joined: Apr 2013
More
anyone found a solution to this yet?
Hi, is rooting the phone the only way to get this working? So annoying... Maybe will just send this galaxy note 2 back for a refund, tried for a long time to get this fixed, I think it started after the last android update I thought they'd have done something about it by now...
17th June 2013, 07:56 PM   |  #13  
Junior Member
Thanks Meter: 32
 
2 posts
Join Date:Joined: May 2012
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.
The Following 13 Users Say Thank You to greaty For This Useful Post: [ View ]
20th July 2013, 02:41 AM   |  #14  
Junior Member
Thanks Meter: 4
 
18 posts
Join Date:Joined: Mar 2011
Quote:
Originally Posted by greaty

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.

Hey, I've been looking for a fix for prox sensor on my Note 2 ever since I installed Paranoid back in december/january, went back to stock and it was still broken. This fixed it!! So thank you I have just one issue, it seems to go back to being broken when I reboot the phone. Is there any way to prevent this? Also the *#0*# doesn't work for me and the cat command returns just a 0. Thanks.

EDIT: it might help to note that I'm running cyanogenmod 10.1 nightly now
EDIT2: I figured it out! I did a search for prox_cal and found one in /sys/devices/virtual/sensors/proximity_sensor with the values 18,9. i put those values in the empty /efs/prox_cal. It now works on boot.
Last edited by marcmy; 21st July 2013 at 08:15 AM.
The Following User Says Thank You to marcmy For This Useful Post: [ View ]
21st July 2013, 04:12 PM   |  #15  
Junior Member
Thanks Meter: 32
 
2 posts
Join Date:Joined: May 2012
Quote:
Originally Posted by marcmy

... it seems to go back to being broken when I reboot the phone. Is there any way to prevent this? Also the *#0*# doesn't work for me and the cat command returns just a 0. Thanks.

EDIT: it might help to note that I'm running cyanogenmod 10.1 nightly now
EDIT2: I figured it out! I did a search for prox_cal and found one in /sys/devices/virtual/sensors/proximity_sensor with the values 18,9. i put those values in the empty /efs/prox_cal. It now works on boot.

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 $'\x0a' > /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.
The Following 19 Users Say Thank You to greaty For This Useful Post: [ View ]
27th July 2013, 02:29 PM   |  #16  
Senior Member
Stuttgart
Thanks Meter: 62
 
173 posts
Join Date:Joined: Nov 2010
More
Quote:
Originally Posted by greaty

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).

working great on my i9505 thanks !!!!
18th August 2013, 11:25 AM   |  #17  
Junior Member
Thanks Meter: 0
 
15 posts
Join Date:Joined: Sep 2009
Hello, so I had a very similar experience in flashing Paranoid and then my sensor went bezerk. It seems to be just not turning on with the phone, but the front camera does work fine. I was able to get it working a few days ago by flashing the stock rom and kernel multiple times, but I decided to get bold and reflash the Neak kernel and poof, that was over. Not another few flashes would bring my sensor back. At this point I don't even know what to do.

Thought it might also be worthwhile to mention: the light sensor also does not work and when I looked through the files in the sys/class/sensors for both proximity and light sensors the runtime status is unsupported.
Last edited by adrianjayy; 18th August 2013 at 11:41 AM.
23rd August 2013, 02:24 PM   |  #18  
Recognized Contributor
Baltimore
Thanks Meter: 3,925
 
4,966 posts
Join Date:Joined: Nov 2011
More
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?
24th September 2013, 08:37 PM   |  #19  
Junior Member
Thanks Meter: 4
 
18 posts
Join Date:Joined: Jul 2008
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
The Following User Says Thank You to vaghotstuff For This Useful Post: [ View ]
28th September 2013, 06:57 PM   |  #20  
Junior Member
Thanks Meter: 9
 
3 posts
Join Date:Joined: Sep 2013
Finally Fixed My Sensor
Quote:
Originally Posted by greaty

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 $'\x0a' > /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.

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!

The Following 8 Users Say Thank You to mcelicalderon For This Useful Post: [ View ]
Post Reply Subscribe to Thread
Previous Thread Next Thread


Top Threads in Galaxy Note II Q&A, Help & Troubleshooting by ThreadRank