Connecting two NXTs via Hi-Speed Port 4
Friday, January 4th, 2008John Hansen put this code piece in Lugnet:
I’ve been getting a number of emails from some people who want to know how to
use the hi-speed RS-485 port 4 functionality in the NXT using the standard
firmware. With John Barnes’ help I now know how to get it to work correctly.Here is a simple program that demonstrates how to send a message to a device
attached to the hi-speed port:#define MESS_WAIT 20
void SendRS485Message(const string msg)
{
byte mlen = ArrayLen(msg);
SetHSOutputBuffer(0, mlen, msg);
SetHSOutputBufferOutPtr(0);
SetHSOutputBufferInPtr(mlen);
SetHSState(HS_SEND_DATA);
SetHSFlags(HS_UPDATE); //send it
}task main()
{
SetSensorType(IN_4, SENSOR_TYPE_HIGHSPEED);
SetHSState(HS_INITIALISE);
SetHSFlags(HS_UPDATE);Wait(10);
while (true) {
SendRS485Message(”goofy”);
Wait(50);
}
}Once you have initialized the port type and the hi-speed state machine by
calling SetHsState(HS_INITIALISE) and SetHsFlags(HS_UPDATE) then reading
messages is about as simple as calling GetHSInputBuffer(offset, size, buffer);According to folks at LEGO you can simply use a sensor wire to connect two NXTs
together on port 4 and send data back and forth using this sort of code.John Hansen
If anyone makes a demonstration of two NXTs communication using this method - let me know! I’ll be happy to blog and post your code here.
Posted in news | Comments Off