Ultrasonic sensor won't work in NXC/Bricxcc

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
caltosax
Posts: 1
Joined: 06 May 2011, 00:56

Ultrasonic sensor won't work in NXC/Bricxcc

Post 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?
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

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

Post 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?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

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

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests