Robot App Store Developer Program

robots-app-store-developer-program

Knowledge Base

How to send commands to Lego NXT

  By Anna Sandler

The best way to learn how to program Lego NXT over Bluetooth's communication protocol, is by putting the hands in the dirt.
Let's play a bit with the commands by sending them directly to NXT’s serial port.
We strongly recommend using a simple freeware RealTerm Serial Capture Program, even if you are a .NET or a Java developer.
At least during the first steps. As we move on with the programming, you can send commands to NXT using your code.

RealTerm is available from: http://realterm.sourceforge.net/
(This is a Win-based terminal software. However, every terminal software can do the work).
Please refer to this chapter if you are a new RealTerm user, before you continue reading this post;

Keep reading to see some simple examples how to send commands using the terminal.

Let's send commands to NXT!

It's time to turn on your NXT.
Make sure it is fully charged, but not connected to the charger,
and we are ready to send some commands:

The "beep" example

In this example, we will send commands that will cause the robot to “beep” for half second.
Only the brick will be used in this example- no building instructions are needed.
Type the following commands:
0x06 0x00 0x80 0x03 0x0B 0x02 0xF4 0x01
(Press the “Send Numbers” button)

Cool, right? :-)

So, what these commands mean?
  • 0x06 0x00- Command length. This command is structured from 6 bytes + 2 length bytes.
    6 in hex is 0x06 or 0x00 0x06. NXT is programmed for little ending (LSB), meaning the last byte goes first.
    After switching the places we get 0x06 0x00;
  • 0x80- Prepare for Direct command no reply. Sound commands are part of Direct commands.
    Every command can request a response message from NXT. Use 0x00 for Direct command with reply;
  • 0x03- Play a tone;
  • 0x0B 0x02- Frequency. Tone of the Mi (C) note.
    According to the Frequency Note Mapper, one of the Mi notes is the 523.3 Hz frequency.
    523.3 is being rounded to 523. 523 is hex is 20B or 020B or 0x02 0x0B. LSB first, meaning, 0x0B 0x02;
  • 0xF4 0x01- Duration in milliseconds. 500 milliseconds are 1F4 is Hex or 01F4 or 0x01 0xF4. LSB first- 0xF4 0x01.
That was easy, right? Let’s continue to another example: driving! So buckle-up!

The driving example

Let's try another bunch of commands before we get deeper into NXT programming.
For this example we will use a motor. Connect one of the motors to port C.
For the driving experience, build a basic vehicle according to the quick start.

Put the robot on the floor and prepare to catch it and turn it OFF. Type the following commands:
0x0C 0x00 0x80 0x04 0x02 0x64 0x07 0x00 0x00 0x20 0x00 0x00 0x00 0x00 (Press the “Send Numbers” button)

The robot is moving!
To stop it – turn it OFF

Explanation:
  • 0x0C 0x00- Command length. This command is structured from 12 bytes + 2 length bytes.
    12 in Hex is 0x0C or 0x00 0x0C.
    LSB first, we get 0x0C 0x00;
  • 0x80- Prepare for Direct command no reply. Motors control commands are part of Direct commands.
    Every command can request a response message from NXT. Use 0x00 for Direct command with reply;
  • 0x04- SetOutputState command. This command controls the motors;
  • 0x02- Motor byte. 0x02 refers to motor that is connected to the C port;
  • 0x64- Power set point in percentages. 100% is 0x64% in Hex;
  • 0x07- Output mode byte. 0x07 for all ON;
  • 0x00- Regulation mode byte. 0x00 for idle;
  • 0x00- Turn ratio.
  • 0x20- Motor run state.0x20- for running;
  • 0x00 0x00 0x00 0x00- TachoLimit.0x00- for running forever;
So we’ve learned how to control Lego NXT, and how to send commands to the robot.
It wasn’t that hard, right?

What's next?

Let's talk about singing

will my wife cheat again click here how do i know if my wife has cheated
click here cheaters why do wife cheat
read find an affair click
married men affairs why husband cheat on their wife infidelity in marriage
reasons people cheat husband cheated on me wife cheat story
wifes who cheat cheat women women who cheat on their husband
transfer prescription coupon click cialis coupon







Related Robot-Apps™

Comments