Noob: Can't read from sensor

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
antonycowan
Posts: 2
Joined: 22 Dec 2010, 00:53

Noob: Can't read from sensor

Post by antonycowan »

Hi Folks,

Please forgive the noob-ness of this question.
I drive linux and have just managed to install the NXC firmware (128) and use nexttool to /COM=usb -download=showgyro.rxe ... the source for which is:

task main() {
unsigned int gyro = 5555;
repeat(100) {
gyro = SensorRaw(S1);
NumOut(0, 0, gyro);
Wait(1000);
}
}

I only see "0" on the screen ... ie: the SensorRaw(S1) is apparently only ever returning 0.
I have the HiTechnic gyro plugged into my brick's port #1.
I'm hoping this is easy for someone who knows what they're doing to spot.

Thanks in advance,
tc.
m-goldberg
Posts: 73
Joined: 29 Sep 2010, 12:05

Re: Noob: Can't read from sensor

Post by m-goldberg »

I don't have a gyro sensor, so I'm just winging it here. However, the NXC Programmer's Guide (which you should get familiar with) has the following example that my apply to your situation.

Code: Select all

task main()
{
   int offset = 400;
   SetSensorHTGyro(S1);
   NumOut(0, LCD_LINE1, SensorHTGyro(S1, offset + 5));
   Wait(SEC_9);
}
Two things to note: you need to initialize the sensor with SetSensorHTGyro and you need to supply and offset to get the sensor value.
Regards, Morton
antonycowan
Posts: 2
Joined: 22 Dec 2010, 00:53

Re: Noob: Can't read from sensor

Post by antonycowan »

Thanks for the reply Morton.
I was following code from the HiTechnic site: http://www.hitechnic.com/cgi-bin/commer ... ey=NGY1044
which reads:
The output of the Gyro Sensor can read from NXC by reading the sensor as shown in the following example.
NXC Example code
#define GYRO_PORT IN_3 //Gyro on port 3
#define GYRO_Offset 602 //offset value to apply to the output value
long Gyro_value;
..
Gyro_value=SensorRaw(GYRO_PORT)-GYRO_Offset; //read the gyro sensor
..
I don't know why they use "IN_3" as the port address to send to SensorRaw because the NXC documentation seems to suggest that it is expecting a (#define) value like S1-S4.
I note that your example uses the "SetSensorHTGyro" call. I was thinking that I wouldn't have to do that sort of thing because I'm trying to read the raw value and because I don't understand where why NXC would know about the HT Gyro natively, but I'm excited that it does.
I was in fact looking at the 1900 page NXC programmer's guide, but it didn't occur to me that it would know about the HT Gyro, so I only searched for SensorRaw ... Now I see the calls you reference, so I'll try using them.

Thanks,
tc.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests