?
Solved

Communicating with LEGO NXT via Bluetooth in Delphi

Posted on 2007-08-10
2
Medium Priority
?
1,345 Views
Last Modified: 2016-05-20
Hi,
I recently bought myself a Lego Mindstorm Robotics Kit.  The Kit comes with a unit called the NXT Brick.  This brick can be programmed using virtually any language using either Bluetooth or USB.  

As a project I have decided to try and connect Delphi to the NXT Brick.  As I have only started learning delphi, I am somewhat unfamiliar with how Pascal/Delphi send bytes of data.  So far I can get Delphi to connect to the NXT brick by simulating a COM port, but I am stuck as how to send data to the brick.

I am using the Synaser (Serial Port Synchronous) Library to get the PC to connect to the NXT Brick via bluetooth.

To send data to the NXT Brick using Perl, I would the following:

...
my $data = "\x00\x01\x88";

$data = pack("h2", length($data) ) . "\x00" . $data;

$nxt->write( $data );
...

Open in new window


What the NXT Brick is looking for, if using Bluetooth is:

Byte 0: 0x00 - Length, LSB
Byte 1: 0x00 - Length, MSB
Byte 2: 0x01 - Command Type
Byte 3: 0x88 - Command

Note: All those commands must be prefixed by a 2 bytes header indicating the command length

So, can you please help me work out how to send and receive data to and from the NXT Brick.  Any guidance will be most appreciated.
0
Comment
Question by:falthorn
2 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 19675097
I'm not sure if I understand the format completely, but here is an example:

const COMMAND = 'DUNNO';
var Data: string;
   DataLength: integer;
begin
 Data := 'h2';   // some sort of header? stole from your example
 DataLength := Length(COMMAND);

 // first add the LSB and MSB of the length
 Data := Data + Chr(LoByte(DataLength)) + Chr(HiByte(DataLength));
 
 // now add the 0 and the actual command
 Data := Data + Chr(0) + COMMAND;
end;
 
0
 

Author Comment

by:falthorn
ID: 19692883
Hi MerijnB,

I tried the above, with a few minor changes and it worked a treat.

Thank you for your help.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a step by step guide on how to create a basic PTP link using Ubiquiti airOS devices. This guide can be used on the following Ubiquiti AirMAX devices. Nanostation, Bullets, AirBridge, Nanobeam, NanoBridge to name a few. Please review …
Today sees the launch of a new case study, focusing on BYOD technologies we have been working with for some time now.  But with the advent of 802.11ac wireless technologies and the story behind our landmark developments, we would like to share this …
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question