Page 3 of 5
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 20:55
by mattallen37
Indeed, analog NXT sensor stuff is a mess, that's why I try to only use SensorRaw for just about everything.
I can't seem to figure it out. Try this program, and see what happens. Note that it should read about 3-4 even with no pressure.
Code: Select all
float ScaleRange(float Value, float ValueMin, float ValueMax, float DesiredMin, float DesiredMax)
{
return (DesiredMax - DesiredMin) * (Value - ValueMin) / (ValueMax - ValueMin) + DesiredMin;
}
float PPS35_PSI (byte port){
return ScaleRange(SensorRaw(port), 400, 1000, 32.7, 6.7);
}
task main(){
SetSensorTouch(S1);
while(true){
ClearScreen();
NumOut(0, LCD_LINE1, PPS35_PSI(S1));
Wait(50);
}
}
If that seems to work, I'll try simplifying it.
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 21:44
by mattallen37
According to the compiled NBC code, the NXC function "SensorMSPressure(S1)" is:
Code: Select all
set __SensorMSPressure_7qG2_port_7qG2_000_inline_main, 0
getin __D0SensorMSPressure_inline_main, __SensorMSPressure_7qG2_port_7qG2_000_inline_main, 2
sub __D0SensorMSPressure_inline_main, __constVal1024, __D0SensorMSPressure_inline_main
div __main_7qG2_v_7qG2_000, __D0SensorMSPressure_inline_main, __constVal25
which is equivalent to:
it's just that it isn't float.
So, this should work the same, but with floating point:
Code: Select all
float PPS35_PSI (byte port){
float PPS35_PSI_001 = 1024 - SensorRaw(port);
return PPS35_PSI_001 / 25;
}
Obviously this is assuming that SensorMSPressure works properly the way it is (just with very poor resolution).
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 21:57
by HaWe
SensorTouch now is really funny^^
Code: Select all
SensorValue SensorMSPressure SensorMSPressureRaw Matt's PSI
0 1 995 6.7
0 3 943 9.3
0 6 869 12.2
0 9 790 15.5
0 12 723 18.9
0 15 646 22.0
0 18 568 25.2
_1000 (limit) 21 482 29.2
Code: Select all
/************************************************************************/
#define printf1( _x, _y, _format1, _value1) { \
string sval1 = FormatNum(_format1, _value1); \
TextOut(_x, _y, sval1); \
}
float ScaleRange(float Value, float ValueMin, float ValueMax, float DesiredMin, float DesiredMax)
{
return (DesiredMax - DesiredMin) * (Value - ValueMin) / (ValueMax - ValueMin) + DesiredMin;
}
float PPS35_PSI (byte port){
return ScaleRange(SensorRaw(port), 400, 1000, 32.7, 6.7);
}
task main()
{
string msg;
int v,w,r, hPa;
float PSI, f;
//SetSensorType(S1, SENSOR_TYPE_LIGHT);
SetSensorTouch(S1);
while (true) {
msg = "Attach PPS35-Nx ";
TextOut(0, LCD_LINE1, msg, false);
//***************************************************************
v = SensorValue(S1);
w = SensorMSPressure(S1);
r = SensorRaw(S1);
f = PPS35_PSI (S1);
hPa = w * 68.95;
PSI = (0.043 * SensorRaw(S1)) - 38;
if (hPa < 1200) OnFwd(OUT_A,100); // air pressure pump
else Off(OUT_A);
//***************************************************************
printf1(0,40, "RAW=%5d", v);
printf1(0,32, "MSP=%5d", w);
printf1(0,24, "MSR=%5d", r);
printf1(0,16, "MSF=%5.1f", f);
printf1(0,08, "PSI=%5.1f", PSI);
Wait (200);
}
}
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 21:58
by mattallen37
Okay, that last formula doesn't match the graphs on mindsensors.com. In order to match the graphs, it needs to be more like this:
Code: Select all
float PPS35_PSI (byte port){
float PPS35_PSI_001;
PPS35_PSI_001 = 1024 - SensorRaw(port);
PPS35_PSI_001 /= 23.07692307692308;
return PPS35_PSI_001 + 5.7;
}
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 21:59
by mattallen37
So, other than an offset of 5.7, that seems right then. I am very sure that either John Hansen or mindsensors messed up (either the reading function, or the graph).
Edit: try the very last formula I posted.
Edit2: and it will not match John's function, but it should match the graph nearly perfectly.
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 22:04
by HaWe
still the same...
Code: Select all
SensorValue SensorMSPressure SensorMSPressureRaw Matt's PSI
0 1 995 6.7
0 3 943 9.0
0 6 869 12.4
0 9 790 15.5
...
Code: Select all
#define printf1( _x, _y, _format1, _value1) { \
string sval1 = FormatNum(_format1, _value1); \
TextOut(_x, _y, sval1); \
}
float PPS35_PSI (byte port){
float PPS35_PSI_001;
PPS35_PSI_001 = 1024 - SensorRaw(port);
PPS35_PSI_001 /= 23.07692307692308;
return PPS35_PSI_001 + 5.7;
}
task main()
{
string msg;
int v,w,r, hPa;
float PSI, f;
//SetSensorType(S1, SENSOR_TYPE_LIGHT);
SetSensorTouch(S1);
while (true) {
msg = "Attach PPS35-Nx ";
TextOut(0, LCD_LINE1, msg, false);
//***************************************************************
v = SensorValue(S1);
w = SensorMSPressure(S1);
r = SensorRaw(S1);
f = PPS35_PSI (S1);
hPa = w * 68.95;
PSI = (0.043 * SensorRaw(S1)) - 38;
if (hPa < 600) OnFwd(OUT_A,100); // air pressure pump
else Off(OUT_A);
//***************************************************************
printf1(0,40, "RAW=%5d", v);
printf1(0,32, "MSP=%5d", w);
printf1(0,24, "MSR=%5d", r);
printf1(0,16, "MSF=%5.1f", f);
printf1(0,08, "PSI=%5.1f", PSI);
Wait (200);
}
}
probably also the MS graph is faulty...
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 22:08
by HaWe
if substract 5.7 (delete the last line of your code) or even substract 6.7 it's maybe better... 8-)
But who knows if those values will be indeed pressure by psi?
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 22:16
by HaWe
that's more trustworthy...
Code: Select all
SensorValue SensorMSPressure SensorMSPressureRaw Matt's PSI
0 1 995 0.0
0 3 943 2.7
0 6 869 5.6
0 9 790 8.9
0 12 723 12.2
0 15 646 15.3
0 18 568 18.6
0 (limit) 21 482 22.8
Code: Select all
#define printf1( _x, _y, _format1, _value1) { \
string sval1 = FormatNum(_format1, _value1); \
TextOut(_x, _y, sval1); \
}
float PPS35_PSI (byte port){
float PPS35_PSI_001;
PPS35_PSI_001 = 1024 - SensorRaw(port);
PPS35_PSI_001 /= 23.07692307692308;
return PPS35_PSI_001 -1;
}
task main()
{
string msg;
int v,w,r, hPa;
float PSI, f;
//SetSensorType(S1, SENSOR_TYPE_LIGHT);
SetSensorTouch(S1);
while (true) {
msg = "Attach PPS35-Nx ";
TextOut(0, LCD_LINE1, msg, false);
//***************************************************************
v = SensorValue(S1);
w = SensorMSPressure(S1);
r = SensorRaw(S1);
f = PPS35_PSI (S1);
hPa = w * 68.95;
if (hPa < 1200) OnFwd(OUT_A,100); // air pressure pump
else Off(OUT_A);
//***************************************************************
printf1(0,40, "RAW=%5d", v);
printf1(0,32, "MSP=%5d", w);
printf1(0,24, "MSR=%5d", r);
printf1(0,16, "MSF=%5.1f", f);
Wait (200);
}
}
edit:
tested it 3 times with identical results (+/- 0.2 units).
Seems really to be trustworthy.
Thanks a lot, matt!
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 16 Nov 2011, 22:39
by mattallen37
That + 5.7 was added so that it matched the mindsensors graph of RAW compared to PSI. Indeed I don't think it is logical for it to be there, but it was in an attempt to match the graph. Actually, based on the graph, the sensor is for the range of ~5.7 to ~37. I think you should leave the +5.7 on there, as it should be more accurate.
Edit: I think John forgot to add the offset that the graph shows very clearly. I think he also rounded 23.07692307692308 to 25, and because of both of those things, our formulas and results don't match (by 5.7 to probably 6 or 7 PSI).
Re: NXC: Mindsensors PPS35 - ADC values to bar?
Posted: 17 Nov 2011, 08:15
by HaWe
Matt,
for 0 (zero) pressure I get with an offset +5.7 an output of 6.7, that didn't appear to be very logical (CMIIW),
so I thought an offset -1.0 would make more sense (pressure=0 => output 0)
(sensorValue now always shows "0" at any pressure configured as a TouchSensor, but the first line in the chart is for 0 external pressure difference = environmental pressure)
I actually don't trust the MS graph which can be just as wrong and faulty as the formula.
ps
won't it make more sense to take SensorLight (unfortunately we still have no sensor type yet for "standard analog" or "general analog" clearly made for pure unmodified ADC readings , that's still weird and confusing)