ROBOTC has a very powerful utility for testing digital sensors on the NXT. Digital sensors are those that support the industry standard I2C protocol for communications between the NXT and the sensor. The utility allows you to easily test an I2C sensor on the NXT. A screen shot of the utility is shown below.
Use either of these two buttons to quickly configure all four sensor ports as a custom I2C sensor.
“Fast” sensors will use the ROBOTC firmware capability to
transmit I2C messages at five times the speed found in the standard LEGO
supplied firmware. Fast mode generally works with all third party sensors, slow
mode is required for the LEGO ultrasonic sensor. The difference is that most 3rd
party sensors include a microprocessor that has I2C messaging support in
hardware and can keep up with the faster ROBOTC messaging rate. Slow sensors
have a “bit-banged’ implementation and cannot keep up.
Configure these parameters for either standard LEGO firmware or ROBOTC firmware. Standard firmware does not support fast mode signaling and will always try to send a I2C message three times before reporting failures. Trying three times can easily mask intermittent transient errors.
The number of total tries can be user configured in the ROBOTC
firmware. The default value is a total of three tries. Setting the number of
retries to zero is useful to ensure transient errors are not masked.
Use these drop down menu items to set the sensor type and sensor mode for each of the four sensor ports. When this utility is first opened, it will interrogate the NXT to get the current settings of these values. The “Fast I/O” check-mark is read-only. It is calculated from the type of sensor.
If you want to test a LEGO ultrasonic tester with this utility, do not set the type to “SONAR”. This will activate the built-in firmware device driver which will periodically poll the value of the ultra-sonic sensor. The device driver does not expect any other application to send I2C messages to the sensor! Instead set the type to “I2C Custom Slow”.
These fields represent the “heart” of the I2C Test Utility. It allows up to six different I2C messages that can be sent in every “cycle” of the test utility.
Field |
Meaning |
Port |
Used to select which of the four ports that should be used. |
Output Message |
Contains the hexadecimal bytes for the message to be sent. |
Reply Len |
Contains the number of reply bytes to send |
Reply |
If a non-zero reply length, contains the received reply |
Select |
Used to include / exclude this message from the test cycle. |
Count |
Number of times the message has been sent. |
Bus Errs |
Number of bus errors encountered during error transmission. Bus error is detected by the I2C firmware and usually indicates an attempt to send an I2C message to a sensor that does not support I2C messaging. |
Same Msg |
Number of times that reply message received is the same contents as received in the previous cycle. This provides a good method to test most sensors. Run the test in “continuous’ mode for 10K (or higher) cycles and see if the same reply was always received. |
These buttons select whether a single test cycle or continuous testing should be performed.