Académique Documents
Professionnel Documents
Culture Documents
Jeremy Schultz
University of Lethbridge
NXT Specs
Technical Specifications:
I
NXT Software
The MINDSTORM comes with development software to
program the NXT. Currently, only Windows and Mac OSX are
supported.
What is NBC/NCX?
NBC/NXC
I
Available at
http://bricxcc.sourceforge.net/nbc/
NBC/NCX Documentation
Download the NXC Guide, a 123-paged pdf.
Guide Overview:
I Section 2 gives the basics of the Language
I
I
LCD_LINE2-2);
Upload:
I
Run program:
I
Bluetooth on NXT
Bluetooth Functionality:
I Master/slave communication channel
I
I
Bluetooth on Linux
Basic information:
I
NXT
Compiling:
I
I
Use gcc
Specify the libraries to use
I
I
Complete command:
# gcc -lm -bluetooth nxt_bt_connect.c -o nxt_bt_connect
/*----------------------------------------------------------* SOCK_STREAM
Provides sequenced, reliable, two-way, connection-based
*
byte streams. An out-of-band data transmission
*
mechanism may be supported.
*
*----------------------------------------------------------*/
// Allocate a socket
nxtSocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
// Set what type and who to connect to
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 1;
str2ba(btAddress, &addr.rc_bdaddr);
// Connect to the NXT
status = connect(nxtSocket, (struct sockaddr *)&addr, sizeof(addr) );
if (status < 0) {
perror("Error connecting Bluetooth");
return status;
}
return 0;
}
Linux machine will act as the master and the NXT as the slave
Basic setup, pairing the devices:
I
Turn on NXT
The NXT will beep and want the same code (passkey)
Length, MSB
I
NXT Mailboxes
Mailbox Information:
I
Master/Slave Communication:
I
Mailbox: mboxdisplay.nxc
#define pixels_per_char 6
task main()
{
int loopnum = 0;
// initial display
clearscreen();
textout(0, lcd_line1, "display mailbox 3");
wait(1000);
// we will manually cancel the program
while(1)
{
string buffer, message="";
char result;
// display loop number
clearscreen()
textout(0, lcd_line1, "loop number:");
numout( (strlen("loop number:") * pixels_per_char), lcd_line1, loopnum);
// read mailbox 3
result = receivemessage(3, true, buffer);
numout(0, lcd_line2, result);
if (result == 0)
{
message = buffer;
// send message back to master
sendmessage(3+10, message)
}
textout(0, lcd_line3, message);
wait(500);
loopnum++;
}
}
// send command
if ( (result = write(nxtsocket, cmd, btlength[0])) < 0) {
perror("error sending messagewrite command ");
return result;
}
//- read reply ----------------------------------------// get bluetooth message length
if ( (result = read(nxtsocket, reply, 2)) < 0) {
perror("error receiving messagewrite reply ");
return result;
}
replylength = reply[0] + (reply[1] * 256);
// get return package
if ( (result = read(nxtsocket, reply, replylength)) < 0)
perror("error receiving messagewrite reply ");
return result;
}
command
= 0x00;
= 0x13;
= mbox+10;
= 0x00;
= 0x01;
Mailbox: main.c
int main (void) {
// nxt brick alpha bluetooth address
char btaddress[18] = "00:16:53:01:2c:84";
// initiate bluetooth connection
if (init_bluetooth(btaddress) < 0)
{
close(nxtsocket);
return 1;
}
printf("bluetooth connected to %s \n", btaddress);
// Send Message
nxt_sendMessage(3, "world");
// Read Message
while ( (status = nxt_readMessage(3, &reply)) == 0X40);
if (status < 0) {
return 1;
}
printf("Reply: %s\n", reply);
free(reply);
close(nxtsocket);
return 0;
}