NXC: can't read Dexter pressure sensor values

Discussion specific to the intelligent brick, sensors, motors, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: can't read Dexter pressure sensor values

Post 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);
  }

}
Last edited by HaWe on 26 Feb 2011, 17:42, edited 2 times in total.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

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

Post by mightor »

See if making "val" a float helps.

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post by HaWe »

no difference!
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

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

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post by HaWe »

I can't use NXT-G, I don't have the software!
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

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

Post by mightor »

Not sure what to suggest then. You've never bought an NXT set, ever?

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post 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)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post 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?
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

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

Post 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
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests