Page 1 of 7

NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 14:44
by HaWe
I tried to use my Dexter pressure sensor again but I get no readings
(edit:) always "0" with TYPE_CUSTOM and always 1023 wit TYPE_LIGHT_INACTIVE) - what may be faulty?
(pressure hose tested on both ends)

What's wrong? Maybe the sensor itself?

Code: Select all

int val;
float pressure;

task main(){
  SetSensorType(S2, SENSOR_TYPE_LIGHT_INACTIVE);
  SetSensorMode(S2, SENSOR_MODE_RAW);

  while(true) {
    val = SensorValue(S2);
     pressure = ((val / 1023)  - 0.04) / 0.0018;  // Vout = ((val * DPRESS_VREF) / 1023);

     printf("raw=%5d", val);
     //printf("hPa=%5.1f", pressure);  // alrenatively show raw or pressure

     Wait(10);
  }

}

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 15:01
by mightor
See if making "val" a float helps.

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 15:04
by HaWe
no difference!

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 16:08
by mightor
Did you test it with the NXT-G block to see if it works with that? You can download it here: http://dexterindustries.com/download.html

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 16:29
by HaWe
I can't use NXT-G, I don't have the software!

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 17:01
by mightor
Not sure what to suggest then. You've never bought an NXT set, ever?

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 17:32
by HaWe
no I didn't, because I never liked those pictures for programming (and never tried it since I once tried RCX-code).
I bought the NXTs and some specific sensors at ebay as I already had a lot of Lego Technic and 3 RIS kits at home.

Haven't you got a well-working NXC-program for testing?

BTW: what's the correct sensor end for the pressure input hose? The one closer to the NXT-cable plug or the one at the opposite side? (as I mentioned - just for safety - I tested both without success)

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 17:39
by HaWe
surprise, surprise:
if I define
SetSensorType(1, SENSOR_TYPE_TOUCH);
SetSensorMode(1, SENSOR_MODE_RAW);

I get values between 60 and 90, but with
SetSensorType(S2, SENSOR_TYPE_LIGHT_INACTIVE);
SetSensorMode(S2, SENSOR_MODE_RAW);

I'm now getting 1023 (0 was the value with type_custom, I corrected this above).

With both types I get valid readings of the sound sensor if I plug it to the port instead.

What sensor type else should I try?

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 17:57
by mightor
This program works for me:

Code: Select all

int val;
float pressure;

task main(){
  //SetSensorType(S2, SENSOR_TYPE_TOUCH);
  SetSensorType(S2, SENSOR_TYPE_LIGHT);
  //SetSensorType(S2, SENSOR_TYPE_LIGHT_ACTIVE);
  SetSensorMode(S2, SENSOR_MODE_RAW);

  while(true) {
    val = SensorRaw(S2);
     pressure = ((val / 1023)  - 0.04) / 0.0018;  // Vout = ((val * DPRESS_VREF) / 1023);

     printf("raw=%5d", val);
     //printf("hPa=%5.1f", pressure);  // alrenatively show raw or pressure

     Wait(10);
  }
}
However, as I suspected, the raw readings from TOUCH and LIGHT are the same, whereas LIGHT_ACTIVE is not. The firmware does some normalisation with this particular sensor. I would suggest you use LIGHT or TOUCH and read the raw values if you want the true ADC values and not something Lego wants you to think is raw. I know you probably won't believe me that the "raw" values for the light sensor (and indeed the sound sensor) are cooked, but I refer you to do the source code. I had this issue when writing a driver for the EOPD sensor.

- Xander

Re: NXC: can't read Dexter pressure sensor values

Posted: 26 Feb 2011, 18:09
by HaWe
SetSensorType(S2, SENSOR_TYPE_LIGHT);
makes the same as
SetSensorType(S2, SENSOR_TYPE_LIGHT_ACTIVE);

in both cases constant 0 , so still all the same!

BTW I had _INACTIVE, not _ACTIVE

(Of course I believe that some raw values are cooked if you tell me - but that's weird, they really must not do that with raw values and this should be abolished by the EFW)