Page 1 of 1
RCX-Temperature-Sensor with NXT
Posted: 30 Jun 2011, 20:58
by lebostein
Hi,
I have a problem to get values in Celsius. Old RCX-Temperature-Sensor is connected with LEGO adapter cable on slot 1.
What command should I use for
???. I have tried SensorValue(S1) and SensorTemperature(S1) don't work...
Code: Select all
task main()
{
SetSensor(S1, SENSOR_CELSIUS);
while(true)
{
temp = ???;
NumOut(1, 1, temp);
}
}
Re: RCX-Temperature-Sensor with NXT
Posted: 01 Jul 2011, 02:34
by mattallen37
I don't know the "best" way, but I would use SENSOR_1. You also need to declare the variable. I assume you want a 16-bit signed value, so you should also add "int temp;". I would also not display the number 1 pixel from bottom and left. I would use LCD_LINE1, 0. You also need to clear the screen from previous values. I would use ClearScreen(), and to slow it down so it doesn't flicker a lot I would add a 50ms wait. I would make the program like this:
Code: Select all
int temp;
task main()
{
SetSensor(S1, SENSOR_CELSIUS);
while(true)
{
temp = SENSOR_1;
ClearScreen();
NumOut(LCD_LINE1, 0, temp);
Wait(50);
}
}
And if you only want to display the temperature, you don't even need variable temp.
Here is how I would do it simply:
Code: Select all
task main()
{
SetSensor(S1, SENSOR_CELSIUS);
while(true)
{
ClearScreen();
NumOut(LCD_LINE1, 0, SENSOR_1);
Wait(50);
}
}
Or with a more fancy appearance:
Code: Select all
task main()
{
SetSensor(S1, SENSOR_CELSIUS);
while(true)
{
string temp = NumToStr(SENSOR_1) + " C";
ClearScreen();
TextOut(LCD_LINE1, 0, temp);
Wait(50);
}
}
Note however, that I didn't test run any of these programs.
Re: RCX-Temperature-Sensor with NXT
Posted: 02 Jul 2011, 07:38
by lebostein
Code: Select all
unsigned int val = SensorValue(S1);
unsigned int val = Sensor(S1);
unsigned int val = SENSOR_1;
It seems that all 3 options get the same sensor value....
But it don't work correctly!
I get room temperatures near 240 °C!
I have tested it with old RCX and NQC too, temperature sensor works correct.
Is this a bug of NXC or Firmware?
Re: RCX-Temperature-Sensor with NXT
Posted: 02 Jul 2011, 07:47
by afanofosc
I would try the standard firmware and the on-board view system to see what you get. If that works with both the standard firmware and the enhanced NBC/NXC firmware then the next thing I would try is a program written in NXT-G using the legacy temperature block and a display block in a loop to display the temperature in C on your screen. If that works then I would send me the RXE from the NXT-G program and the RXE from your NXC program and let me figure out what, if anything, is different.
John Hansen
Re: RCX-Temperature-Sensor with NXT
Posted: 02 Jul 2011, 08:56
by lebostein
Ok, I have tested:
* LEGO FW 1.29 + NXC
* LEGO FW 1.29 + NXT-G
* Bricx FW 1.31 + NXC
* Bricx FW 1.31 + NXT-G
the same result in every case: 239
It is possible, that a mistake exist in all documentations/manuals from LEGO and NXC?
It is possible, that I get the temperature in tenth of a degree, 239 = 23,9 °C?
PS: When I put the sensor in my mouth (
), I get 362 = 36,2 °C ... sounds plausible
Re: RCX-Temperature-Sensor with NXT
Posted: 02 Jul 2011, 09:26
by mattallen37
Indeed, it sounds most likely. Unfortunately I don't have an RCX temp sensor, but that seems right.
Re: RCX-Temperature-Sensor with NXT
Posted: 02 Jul 2011, 09:41
by mattallen37
I just ran a test (with a non-temp, but still analog sensor), and I can get results from -20 to 70 (once divided by 10). It looks like you were right.
Here is a program to display the temperature:
Code: Select all
string S_temp;
float F_temp;
task main()
{
SetSensor(S1, SENSOR_CELSIUS);
while(true)
{
F_temp = SENSOR_1/10;
sprintf(S_temp, "%.1f", F_temp);
S_temp += " C";
ClearScreen();
TextOut(0, LCD_LINE1, S_temp);
Wait(50);
}
}
Re: RCX-Temperature-Sensor with NXT
Posted: 02 Jul 2011, 16:47
by afanofosc
I noticed that the firmware now uses the NXT digital temperature sensor for its on-board view menu rather than the old RCX temperature sensor. Sorry for the mis-direction. It also divides the result by 10 to get a floating point number in 10ths of degrees.
I have also reviewed the RCX documentation and it supports the notion that the value returned by the analog temperature sensor is scaled by 10. The range for celsius is documented to be -200 to 700 and the range for fahrenheit is -40 to 1580. These are clearly scaled values. The RCX2 LASM byte codes PDF also says "When specifying temperature thresholds the threshold must be given as temperature multiplied by 10."
John Hansen