This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

legoev3

Connection to LEGO MINDSTORMS EV3 brick

Description

This object represents a connection to a LEGO® MINDSTORMS® EV3 brick. To interact with peripherals on the EV3 brick, such as the speaker, LCD, buttons, or status light, use this object with the functions listed in Object Functions. To connect to sensors and motors, use this object with the following sensor objects: touchSensor, irSensor, gyroSensor, colorSensor, sonicSensor, or motor.

Creation

Syntax

myev3 = legoev3
myev3 = legoev3(communicationtype)
myev3 = legoev3(communicationtype,ipaddress,id)
myev3 = legoev3(communicationtype,comport)

Description

example

myev3 = legoev3 creates a connection to an EV3 brick, myev3, that uses the same settings as the previous connection.

example

myev3 = legoev3(communicationtype) creates a connection to an EV3 brick using a specified connection type. communicationtype sets the CommunicationType property of the connection object.

example

myev3 = legoev3(communicationtype,ipaddress,id) creates a connection to an EV3 brick using a type of connection that requires the IP address and ID of the EV3 brick.

example

myev3 = legoev3(communicationtype,comport) creates a connection to an EV3 brick using a type of connection that requires a COM port number.

Input Arguments

expand all

COM port or serial device on host computer, specified as a character vector.

Example: 'COM3'

Example: '/dev/tty.EV3-SerialPort'

Data Types: char

Properties

expand all

This property is read-only.

EV3 firmware version, returned as a character vector.

Example: 'V1.03E'

Data Types: char

This property is read-only.

Unique hardware ID, returned as a character vector. You can set this property when you create the object. After you create the object, this property cannot be changed. This value is available in the EV3 interface under Brick Info.

Example: '00165340e49b'

Data Types: char

This property is read-only.

IP address when connecting over a wireless network, returned as a string. You can set this property when you create the object. After you create the object, this property cannot be changed. This value is available in the EV3 interface under Brick Info.

Example: '192.168.1.2'

Data Types: char

This property is read-only.

Connection type, returned as a character vector. You can set this property when you create the object. After you create the object, this property cannot be changed.

Example: 'USB'

Data Types: char

This property is read-only.

Percentage of battery power remaining, returned as an int8 value.

Example: 68

Data Types: int8

This property is read-only.

List of connected sensors, returned as a cell array of character vectors. '' means no connected sensors.

Example: {'touch' 'infrared' 'color' 'sonic'}

Object Functions

clearRemove items from workspace, freeing up system memory
writeLCDWrite characters to LCD on EV3 brick
clearLCDClear characters from LCD on EV3 brick
playTonePlay tones from speaker on EV3 brick
beepPlay beep from speaker on EV3 brick
readButtonRead whether button on EV3 brick is being pressed
writeStatusLightControl color and mode of status light on EV3 brick

Examples

collapse all

If you have connected to the EV3 brick previously, you can reconnect without specifying any details.

myev3 = legoev3;

You can communicate with the EV3 brick over a USB cable.

Using the supplied USB cable, connect the host computer to the EV3 brick.

In the MATLAB Command Window, connect over USB.

myev3 = legoev3('USB');

You can communicate with the EV3 brick over a wireless network connection.

Set up and configure a wireless network connection.

In the Command Window, connect using a wireless network. Specify the IP address and ID of the EV3 brick.

myev3 = legoev3('WiFi','192.168.1.2','00165340e49b');

You can communicate with the EV3 brick over a Bluetooth® connection.

Set up and configure a Bluetooth connection.

In the MATLAB® Command Window, create a connection from a host computer running Windows® to an EV3 brick over Bluetooth. Specify the COM port number.

myev3 = legoev3('Bluetooth','COM3');

You can communicate with the EV3 brick over a Bluetooth connection.

On Mac OS, Set up and configure a Bluetooth connection to the EV3 brick.

Open Terminal in Mac OS and enter:

ls /dev/tty*
/dev/tty.EV3-SerialPort

The command response gives the name of the Bluetooth connection from Mac OS to the EV3 Brick

In the MATLAB Command Window, create a connection from a host computer running Mac OS to an EV3 brick over Bluetooth. Specify the COM port number.

myev3 = legoev3('Bluetooth','/dev/tty.EV3-SerialPort');