The LEGO® MINDSTORMS® EV3 brick is at the core of the pyev3 package. Once the brick is powered up, you can use a PC to communicte with it in two ways:
requires a USB cable (that comes with the set)
very repeatable command/reply round-trip times of approx. 5 ms
WiFi (free to move around!)
requires a WiFi dongle (purchased separately)
not very repeatable command/reply round-trip times between 10 to 20 ms
LegoEV3(commtype='usb', IPaddress=None, deviceID=None)[source]
The class to represent the LEGO EV3 brick. You can use LegoEV3 to interact with the EV3 brick.
Set up USB connection between host and EV3 brick.
>>> from pyev3.brick import LegoEV3 >>> myev3 = LegoEV3(commtype='usb') >>> myev3.display_info() >>> myev3.close()
Set up WiFi connection between host and EV3 brick
>>> myev3 = LegoEV3(commtype='wifi', IPaddress='192.168.0.19', deviceID='001653470e58') >>> myev3.display_info() >>> myev3.close()
commtype (str) – The type of communication with the brick.
IPaddress (str) – The IP address assigned to the EV3 brick.
deviceID (str) – The individual device ID of the EV3 brick. Connect to the brick using commtype=’usb’ and use the display_info() method to retrieve the ID of the brick.
Always use the close() method before opening a new connection.
Try a USB connection first. It’s easier to set up and faster.
play_tone(volume=10, frequency=440, duration=1)[source]
Play a tone on the EV3 brick.
volume (int) – The volume of the played tone:
frequency (int) – The frequency (Hz) of the played tone:
duration (float) – The duration (s) of the played tone:
>>> myev3.play_tone(volume=5, frequency=880, duration=0.5)
Set the status light of the EV3 brick.
mode (str) – The light mode:
color (str) – The light color:
>>> myev3.set_statuslight(mode='pulsing', color='orange')
Contains the EV3 battery level in % (read only).
Contains a list with the sensors connected to the EV3 (read only).
Contains a developer mode flag. Default is
True, communication info is displayed after each direct command (read/write).