The LPF2 connector is LEGO's proprietary interface for Powered Up devices. Understanding this protocol is essential for building custom sensors, intercepting motor data, or creating "man-in-the-middle" architectures. This guide provides the complete pinout and communication protocol.

Table of Contents

LPF2 Connector Pinout

The LPF2 connector uses 6 wires with dual-purpose functionality:

Pin Name Voltage/Signal Description
1 M1 0-9V PWM Motor Power (+). PWM controls speed.
2 M2 0-9V PWM Motor Power (-). Polarity reversal changes direction.
3 GND 0V Ground. Common reference for logic and power.
4 VCC 3.3V Logic Power. Supplies smart sensors and motor encoders.
5 ID1 0-3.3V Identification & Data line 1.
6 ID2 0-3.3V Identification & Data line 2.

Pin Functions Explained

Pins 1-2: Motor Power

These pins deliver high current (up to 1A) to drive motors. The hub uses PWM (Pulse Width Modulation) to control speed. Reversing polarity (swapping M1/M2 voltage) reverses motor direction.

Pin 3: Ground

Common ground reference shared between logic circuits and motor power.

Pin 4: VCC (3.3V Logic Power)

Supplies power to the logic chips inside smart sensors (color sensor, distance sensor) and the encoders in smart motors. Current limited to ~100mA.

Pins 5-6: ID/Data (Dual Mode)

These pins serve two functions:

  1. Identification Mode: Hub measures resistance across ID1/ID2 to identify device type
  2. Data Mode: After identification, pins switch to high-speed UART for bidirectional data

Device Identification

When you connect a device, the hub performs device identification by measuring resistance:

Identification Sequence

  1. Hub applies small voltage to ID pins
  2. Measures resistance between ID1, ID2, and GND
  3. Compares to known values to identify device type
  4. If smart device, switches to UART mode

Known Device ID Resistances

Device ID1-GND ID2-GND
Simple Motor (no encoder) Open Open
Train Motor Open Open
Medium Angular Motor ~22kΩ UART
Large Angular Motor ~15kΩ UART
XL Motor ~10kΩ UART
Color/Distance Sensor ~47kΩ UART
💡 Key Insight: By placing the correct resistor between ID1 and GND, you can make the hub think any device is connected. This is the basis for custom sensor spoofing.

UART Communication

Smart devices (motors with encoders, sensors) communicate via UART on the ID pins after identification.

UART Specifications

  • Baud Rate: 115200
  • Data Bits: 8
  • Parity: None
  • Stop Bits: 1
  • Voltage: 3.3V logic levels

Data From Smart Motors

Smart motors (Angular motors) send back:

  • Position: Absolute angle in degrees (0-360°)
  • Speed: Current rotational speed
  • Load: Motor load/torque feedback

Reading Motor Data with Arduino

// Read LEGO motor encoder data
// Connect motor ID2 pin to Arduino RX (through level shifter!)

void setup() {
  Serial.begin(115200);   // Debug output
  Serial1.begin(115200);  // LEGO motor UART
}

void loop() {
  if (Serial1.available()) {
    byte data = Serial1.read();
    Serial.print(data, HEX);
    Serial.print(" ");
  }
}

Building Custom Sensors

To build a sensor that LEGO hubs recognize, you need to:

  1. Match the correct ID resistance
  2. Respond to UART handshake
  3. Send data in expected format

Simple Custom Sensor (Analog Input)

// Custom analog sensor that appears as "simple device"
// No UART needed - hub just reads analog voltage on ID pins

// Hardware setup:
// - Connect your sensor output to ID1 through voltage divider
// - Ensure output is 0-3.3V range
// - Add 47kΩ resistor ID1 to GND for device ID

// The hub will read analog voltage as "raw sensor value"

Smart Custom Sensor (UART)

// Arduino-based custom sensor with UART communication
// Appears as color sensor to LEGO hub

#include <SoftwareSerial.h>

const int ID_RESISTOR = 47000;  // 47kΩ for color sensor ID
SoftwareSerial legoSerial(10, 11);  // RX, TX to LEGO ID pins

void setup() {
  legoSerial.begin(115200);
  // Add ID resistor between pin and GND
}

void loop() {
  // Read your actual sensor
  int myValue = analogRead(A0);

  // Format as LEGO expects
  byte packet[4];
  packet[0] = 0x46;  // Header
  packet[1] = myValue & 0xFF;
  packet[2] = (myValue >> 8) & 0xFF;
  packet[3] = calculateChecksum(packet, 3);

  legoSerial.write(packet, 4);
  delay(50);
}

Man-in-the-Middle Architecture

A powerful technique is intercepting communication between hub and device:


[LEGO Hub] ←--LPF2--→ [Arduino/ESP32] ←--LPF2--→ [LEGO Motor]
                          ↓
                    [Your Logic]
                    - Read encoder
                    - Modify commands
                    - Add safety limits

Use Cases

  • Position Logging: Record motor movements for replay
  • Safety Limits: Prevent motor from exceeding safe angles
  • Speed Smoothing: Apply acceleration curves to jerky commands
  • Sensor Fusion: Combine LEGO sensor data with external sensors

Safety Considerations

⚠️ Important Safety Notes:
  • Voltage Levels: ID pins are 3.3V logic. Never apply 5V directly - use level shifters.
  • Current Limits: VCC (Pin 4) supplies limited current. Don't draw more than 100mA.
  • Motor Power: Pins 1-2 can supply 9V at 1A. Shorting them can damage the hub.
  • ESD Protection: Handle connectors carefully. Static discharge can damage hub ports.
  • Warranty: Modifying LEGO electronics voids warranty. Experiment with spare hubs.

Resources