The NXT firmware speaks a simple request/reply protocol, documented by LEGO
in the MINDSTORMS NXT Bluetooth Developer Kit . nxt-rs implements it in
nxt_rs::protocol, without any I/O.
request: [type] [opcode] [arguments…]
reply: [0x02] [opcode] [status] [data…]
Type byte Meaning
0x00Direct command, reply requested
0x01System command, reply requested
0x80Direct command, no reply
0x81System command, no reply
0x02Reply
All multi-byte values are little-endian .
A telegram is at most 64 bytes .
Status 0x00 means success. Other values are listed in
Status codes .
File and module names are 20-byte, NUL-padded ASCII fields (15.3
characters plus the terminator).
Link Framing
USB None: one bulk transfer per telegram (endpoint 0x01 out, 0x82 in)
Bluetooth / serial Each telegram is preceded by its length as a 2-byte little-endian number
use nxt_rs::transport::frame;
let (buf, len) = frame(&[0x00, 0x0B]).unwrap();
assert_eq!(&buf[..len], &[0x02, 0x00, 0x00, 0x0B]);
80 03 E0 01 F4 01
│ │ └─┬─┘ └─┬─┘
│ │ │ └─ duration 500 ms (0x01F4)
│ │ └─────── frequency 480 Hz (0x01E0)
│ └──────────── opcode 0x03 PlayTone
└─────────────── direct command, no reply
02 06 00 | 01 | 9C | 05 | 01 | 00 | 20 | 68 01 00 00 | 10 00 00 00 | F0 FF FF FF | 00 01 00 00
reply port B mode ratio tacho limit tacho count block tacho rotation
opcode power -100 regulation run state 0x20 360 16 -16 256
status ok
The opcode tables are in Direct commands
and System commands . Each command’s
struct in nxt_rs::protocol::direct and nxt_rs::protocol::system
documents its fields.
Field Values
Port 0–2 (A–C); 0xFF = all (only SetOutputState)
Power -100…100 (signed byte)
Mode bits 0x01 motor on, 0x02 brake, 0x04 regulated
Regulation 0x00 idle, 0x01 speed, 0x02 sync
Turn ratio -100…100
Run state 0x00 idle, 0x10 ramp up, 0x20 running, 0x40 ramp down
Tacho limit u32 degrees; 0 = unlimited
USB: a few milliseconds per round trip.
Bluetooth: about 60 ms per round trip. The Bluetooth module needs time to
switch between sending and receiving. Commands sent without a reply
avoid half of that.