Lego USB Devices Driver



Identifies USB 1.1/2.0/3.0 devices; Identifies IEEE 1394 devices; Identifies ISA Plug&Play devices; Identifies AGP Bus devices; Identifies PCI, PCI-E, eSATA devices; Find drivers for hardware devices; Contact hardware vendor directly from app; Unknown Device Identifier 9.01 on 32-bit and 64-bit PCs. Garmin Support Center is where you will find answers to frequently asked questions and resources to help with all of your Garmin products.

Intro

The LEGO Dimensions game makesuse of NFC technology to allow some interaction between physical LEGO creations(characters, vehicles and gadgets) and the videogame.

The LEGO Toy Pad is in fact just a custom USB triple NFC reader that can readNFC tags (not only the LEGO Toy Tags but also several other tags including thoseused in other games like Disney Infinity) and change the color of the RGB lightassociated to each reader.

Credits

Since the beginning of 2015 several people have been reverse engineering theLEGO Toy Pad.This tutorial is strongly based on @woodenphonework available at GitHub.

Requirements

You will need:

  • a proper LEGO Dimensions Toy Pad
  • a Mindstorms EV3
  • an available USB port
  • python and pysub
  • udev rule

Several people reported a difference between PS3/PS4/Wii devices and Xbox sothis tutorial most probably will not work with the Xbox type.

You don’t really need a Mindstorms EV3 as this tutorial can be used on almost anyrecent linux system (like my Ubuntu laptop or my Raspberry Pi). If using ev3dev,just be sure to use a recent version - this tutorial was tested with kernel4.4.15-13-ev3dev-ev3.

Of course, you need an available USB port so if you’re already using the MindstormsEV3 with an USB Wi-Fi dongle you will also need an USB Hub.

After you connect the LEGO Toy Pad it should be recognized as an HID device:

Lego

You can also check with lsusb:

You also need python and pyusb. Most Linux distributions alreadyinclude python as default so you probably only need to install the pyusb librarywith:

To allow python script to access USB without running with root privileges we needto add an udev rule:

with the following rule inside:

then unplug and replug the LEGO Toy Pad again.

Initializing

The following script will check for the presence of a LEGO Toy Pad and initializesit, turning the middle (round) pad red for one second:

If everything was OK the output should be:

and of course the center pad should stay red for one second.

Changing pad colors

In the above script we’ve seen that all commands sent to the LEGO Toy Pad havethe same size: 32 bytes.

The first bytes define the command, some other bytes the arguments and theremaining bytes are just to assure proper communication (checksum).

I’ll show just how to change the color of each pad but there are some othercommands available (switch on/off, fade, flash…). You can see these commandsin @woodenphone’s lego_dimensions_gateway.py script.

Reading tags

Whenever a tag is inserted or removed the LEGO Toy Pad sends a 32-byte messagestarting with 0x56. The message also contains:

  • the number of the pad affected
  • the UID of the tag inserted or removed
  • the action itself (tag was inserted or removed)

So if we already know the UID of a tag we can track it with the LEGO Toy Pad (Iuse my Android phone to read my tags but we can also use the LEGO Toy Pad).For the next script we’ll track Darth Vader from Disney Infinity 3.0 (a MifareClassic Mini tag) but we can track several types of NFC tags - LEGO Toy Tags areMifare Ultralight C (also known as NTAG213) and Nintendo amiibo are also MifareUltralight (but not C, so NTAG215).

The script also tracks unknown UIDs. So:

  • if it recognizes Darth Vader, it turns the corresponding pad RED;
  • if it doesn’t recognize the tag, it turns the pad GREEN;
  • whenever a tag is removed it turns the pad OFF:

Authors


Input / Output Ports¶

By default, a sysfs device is created for each input and output port on theEV3. See the input ports and output ports driver descriptions for moreinformation on how these work. There is a single module for input and outputports named ev3_ports. This module has some module parameters.

Input Ports¶

LEGO MINDSTORMS EV3 has four input ports labeled 1, 2, 3 and 4. These portsare used with LEGO MINDSTORMS EV3 and NXT compatible sensors and otherdevices. Most sensors can be automatically detected when plugged in.Unlike the EV3, however, NXT analog sensors cannot be detected, so to usethese sensors, the port has to be placed in nxt-analog mode manually.

General Info¶

Moduleev3_ports
Driver nameev3-input-port
Connection typesNXT/Analog, NXT/I2C, Other/I2C, EV3/Analog, EV3/UART, Other/UART
Connection prefixin
Number of modes9

Modes¶

NameDescription
auto[1]Automatically detect most sensors.
nxt-analog[2]Configures the port for NXT/Analog sensors
nxt-color[3]Configures the port for the LEGO NXT Color sensor
nxt-i2cConfigure for I2C communications and load the nxt-i2c-host device.
other-i2cConfigure for I2C communications but do not probe for NXT sensors. Also configure pin 1 to output 9V (battery voltage).
ev3-analogConfigures the port for EV3/Analog sensors
ev3-uartConfigure for UART communications and load the ev3-uart-host device.
other-uartConfigure for UART communications but do not load any device.
raw[4]Provide access to low level drivers.

Notes¶

[1]In auto mode, the port will attemptto automatically detect the type of sensor that wasconnected and load the appropriate driver. See the list ofSupported Sensors to determine if a sensor can beautomatically detected.
[2]This loads the genericNXT/Analog sensor nxt-analog driver. Useset_device to load the appropriate device/driver.
[3]NXT Color sensor driver has notbeen implemented yet, so right now, this mode does nothing.
[4]Exports gpios and analog/digitalconverter values to sysfs so that they can be controlleddirectly.

Output Ports¶

The EV3 has four output ports labeled A, B, C and D. These portsare used with LEGO MINDSTORMS EV3, NXT and RCX compatible motors and otherdevices. EV3 motors can be automatically detected when plugged in. Othermotors with position feedback (such as the NXT motor) are usually detectedas an EV3 Large Motor. RCX motors and LEDs cannot be automatically detectedand the mode of the output port must be manually set to use these types ofdevices.

Lego usb devices driver download

General Info¶

Moduleev3_ports
Driver nameev3-output-port
Connection typestacho-motor, dc-motor, led
Connection prefixout
Number of modes5

Modes¶

NameDescription
auto[5]Automatically detect motors when they are connected.
tacho-motor[6]Configure the port for NXT/EV3 motors.
dc-motor[7]Load the port for RCX/Power Functions motors.
led[8]Load the port for RCX/Power Functions LEDs.
raw[9]Provide access to low level drivers.

Notes¶

[5]Only the EV3/NXT large motors andthe EV3 medium motor can be automatically detected. Allother devices must be manually configured.
[6]Configures the port to usethe tacho-motor Subsystem. The default driver isthe EV3 Large Motor (lego-ev3-l-motor). You can changethe driver using the set_device attribute.
[7]This can be use with MINDSTORMSRCX motors, Power Functions motors and any other “plain”DC motor. By “plain”, we mean the motor is just a motorwithout any feedback.

Lego Usb Devices Driver Downloads

[8]This can be used with MINDSTORMS RCXLEDs, Power Functions LEDs or any other LED connected topins 1 and 2 of the output port.

Lego Usb Devices Driver Free

[9]Exports gpios, pwm and analog/digitalconverter values to sysfs so that they can be controlleddirectly.

Buttons¶

The EV3 buttons use the standard Linux input subsystem. You can find the eventdevice node at /dev/input/by-path/platform-gpio-keys.0-event. The buttonsare mapped to Linux key codes as shown in the table below.

Button map
ButtonLinux key code (value)
BackKEY_BACKSPACE (14)
CenterKEY_ENTER (28)
UpKEY_UP (103)
LeftKEY_LEFT (105)
RightKEY_RIGHT (106)
DownKEY_DOWN (108)

LEDs¶

The EV3 brick status LEDs used the standard Linux LEDs subsystem. You canfind the LED devices at /sys/class/leds/. There are two bi-color LEDs.The color for each LED is controlled separately, so there is a green andred device node for each LED. Turning both of these on at the same timewill make the LED appear orange(ish).

The LEDs are controlled by a PWM signal, so you can vary the brightness between0 and max_brightness.

Display¶

The EV3 display uses the standard Linux frame buffer subsystem (fbdev). Thedisplay memory can be directly accessed by reading and writing or memory mapping/dev/fb0. Display attributes such as width, height and row stride can beread using FBIOGET_VSCREENINFO and FBIOGET_FSCREENINFO ioctls.

Note

You must make sure that you control the active virtual console beforedrawing on the display, otherwise other programs could be writing to thedisplay at the same time, causing unexpected results.

Lego Usb Drive

Sound¶

The snd-legoev3 module provedes an ALSA driver for PCM playback and aLinux input device with sound capabilities (EV_SND) for producing tones.

The ALSA driver can be used with standard tools such as alsamixer andaplay. Tones can be produced by using the beep command, ioctls suchas KDMKTONE (must run on local console or as root for ioctls) or bywriting SND_* events to the event device (must be member of inputgroup for this).

Battery¶

Lego USB Devices Driver

  • This driver is used to get information about the EV3 battery.
  • It uses the power_supply subsystem.
  • It registers a sysfs device node at /sys/class/power_supply/lego-ev3-battery/.

Lego Usb Devices Driver Download

Sysfs Attributes
current_nowReturns the battery current in microamps.
scopeAlways returns System.
technologyReturns Unknown or Li-ion depending on if the rechargeablebattery is present. If the technology is Unknown, you can writeNiMH to this attribute if you are using rechargeable NiMH batteries.
typeAlways returns Battery.
voltage_max_designReturns the nominal “full” battery voltage. The value returneddepends on technology.
voltage_min_designReturns the nominal “empty” battery voltage. The value returneddepends on technology.
voltage_nowReturns the battery voltage in microvolts.