NXT I2C Sensors
(Created page with "<yambe:breadcrumb self="I2C Sensors">NXT|NXT</yambe:breadcrumb> {| class="wikiText" |- |''For ROBOTC NXT Sensor ''functions'', check out the [[NXT_Functions_Sensors|NXT Sens...") |
(→sendI2CMsg) |
||
| Line 215: | Line 215: | ||
|- | |- | ||
| style="border-style: solid; border-width: 0px 0px 0px 0px"|''nReplySize'' | | style="border-style: solid; border-width: 0px 0px 0px 0px"|''nReplySize'' | ||
| − | | style="border-style: solid; border-width: 0px 0px 0px 0px"| | + | | style="border-style: solid; border-width: 0px 0px 0px 0px"|Specifies the length, in bytes, of the reply expected from the sensor. |
| style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_int|int]] | | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_int|int]] | ||
|- | |- | ||
| Line 224: | Line 224: | ||
|- | |- | ||
|<syntaxhighlight lang="robotc"> | |<syntaxhighlight lang="robotc"> | ||
| − | sendI2CMsg(i2cScanPort, i2cScanDeviceMsg[0], 8); // send | + | sendI2CMsg(i2cScanPort, i2cScanDeviceMsg[0], 8); // send a message from 'i2cScanDeviceMsg[0]' to |
| − | + | //'i2cScanPort' (S1), expecting an 8 byte return message | |
</syntaxhighlight> | </syntaxhighlight> | ||
|- | |- | ||
Latest revision as of 07:31, 6 September 2012
| For ROBOTC NXT Sensor functions, check out the NXT Sensor Functions page!
For more examples and explanations, head over to NXT Sensors Overview page! |
|
| |||||||
Information
| User programming of NXT digital sensors is for advanced users. The average user will not require this capability.
Each of the four sensor ports on the NXT can be configured as either a digital or analog sensor. There are integrated device drivers for the LEGO developed sensors built into the ROBOTC firmware. If an application program wants to provide its own device drivers for either existing or new 3rd party sensors, it is important to set the sensor type to a “custom user provided device driver” so that there are no conflicts between the built-in device drivers and the user written code. There are four sensor types that are valid for application controlled digital sensors on a NXT. These are:
There are several sample programs in the ROBOTC distribution that illustrate the use of I2C messaging on the NXT with ROBOTC. There are a few things to remember in I2C messaging:
|
nI2CBytesReady
| word nI2CBytesReady[tSensors sensor] | ||||||
| (word) Number of queued bytes ready for access from previous I2C read requests. | ||||||
| ||||||
|
nI2CRetries
| word nI2CRetries | |
| (word) The number of re-transmission attempts that should be made for I2C message. | |
|
nI2CStatus
| TI2CStatus nI2CStatus[tSensors sensor] | ||||||
| (TI2CStatus) Current status of an sensor I2C link. | ||||||
| ||||||
|
readI2CReply
| void readI2CReply(const tSensors nPort, byte &replyBytes, const int nBytesToRead) | ||||||||||||
| (void) Retrieve the reply bytes from an I2C message. | ||||||||||||
| ||||||||||||
|
sendI2CMsg
| void sendI2CMsg(const tSensors nPort, const byte &sendMsg, const int nReplySize) | ||||||||||||
| (void) Send an I2C message on the specified sensor port. | ||||||||||||
| ||||||||||||
|