Read any sensor on NXT 2

HomeForumsMonoBrick Communication LibraryRead any sensor on NXT 2

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5437
    Author Image
    Danny Meier
    Participant

    Hi,

    I tried to read any kind of sensors using my NXT 2 brick. Either the result is always 0 or I get a StackOverflowException (e.g. using the Sonar sensor)

    Code example for Ultrasonic sensor (produces a StackOverflowException):

                    var brick = new Brick<Sensor, Sensor, Sensor, Sensor>("usb");
                    brick.Connection.Open();
                    
                    var test = new Sonar(SonarMode.Centimeter);
                    brick.Sensor4 = test;
                    Console.WriteLine(test.ReadDistance());
                    brick.Connection.Close();

    Code example for Touch sensor (reads always 0)

                    var brick = new Brick<Sensor, Sensor, Sensor, Sensor>("usb");
                    brick.Connection.Open();
                    
                    var test = new TouchSensor();
                    brick.Sensor1 = test;
                    Console.WriteLine(test.Read());

    In any case the IsInitialized property is always false. Also calling test.Initialize() doesn’t change anything.

    #5438
    Author Image
    Tcm0
    Participant

    Can you try it with the following code:

    var brick = new Brick<Sensor, Sensor, Sensor, Sensor>("usb");
    brick.Connection.Open();
    
    brick.Sensor1 = new TouchSensor();
    Console.WriteLine(brick.Sensor1.ReadAsString());
    • This reply was modified 8 years, 10 months ago by Author ImageTcm0.
    #5440
    Author Image
    Danny Meier
    Participant

    Reads all the time 0. Independent whether I press the button or not.

    #5441
    Author Image
    Tcm0
    Participant

    Can you try Bluetooth?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Posted in

Make a donation