Page 1 of 1

Ultrasonic sensor won't work in NXC/Bricxcc

Posted: 06 May 2011, 01:09
by caltosax
I have not been able to get the ultrasonic sensor to work with Bricxcc, either when written into a program, or when reading the values directly using the "watching the brick" tool. When using the tool, the value always reads "0." I set the sensor to type "lowspeed" using the direct control tool. Any suggestions?

Re: Ultrasonic sensor won't work in NXC/Bricxcc

Posted: 06 May 2011, 02:00
by mattallen37
In the program, did you set it to LowSpeed? Did you make sure you used the right port number? Can you post a program that demonstrates the issue? What version of FW are you running on the NXT? What BCC version are you using?

Re: Ultrasonic sensor won't work in NXC/Bricxcc

Posted: 09 May 2011, 23:11
by afanofosc
To read an I2C device value via the Watching the Brick tool you need to use the I2C section on the NXT tab. You can't view its value using the regular analog sensor watch fields.

Lots of people have used this sensor in NXC. You need to read its value via SensorUS rather than Sensor, which only works for analog sensor values. The NXC help describes how to do this.

Code: Select all

task main()
{
  SetSensorLowspeed(S1);
  while(true)
  {
    NumOut(0, LCD_LINE1, SensorUS(S1), true);
    Wait(SEC_1);
  }
}
John Hansen