Skip to main content

Direct Commands for LEGO EV3

Project description

pyev3

pyev3 can be used to interact with the LEGO Mindstorms EV3.

Send direct commands to the EVR from your PC (local host) using a USB or WiFi connection. pyev3 is an alternative to pybricks, which requires booting the EV3 brick from an SD card, and where micropython programs run in the EV3 memory. With pyev3 you can run the EV3 as is. Just connect it to a USB port, or create a WiFi connection, and you're good to go!

Classes

Interact with each one of the EV3 devices through simple methods and properties, implemented in the following classes:

  • LegoEV3
  • Motor
  • Touch
  • Color
  • Ultrasonic
  • Infrared
  • Gyro

Install

py -m pip install pyev3

Documentation

Comprehensive documentation for pyev3 is available here.

Example Code

Start and stop a motor using the touch sensor. The motor speed is proportional to ambient light intensity.

""" Example Code """
# Importing modules
import time
from pyev3.brick import LegoEV3
from pyev3.devices import Motor, Touch, Color
# Creating LEGO EV3 objects
ev3 = LegoEV3(commtype='usb')
motor = Motor(ev3, port='A')
touch = Touch(ev3, portnum=1, inputmode='bump')
color = Color(ev3, portnum=2, inputmode='ambient')
# Initializing system
motor.outputmode = 'speed'
motor.output = 0
motor.start()
touch.reset_count()

# Changing EV3 status light
ev3.set_statuslight(mode='pulsing')
# Running for 30 seconds
print('Running ...')
tcurr = 0
tstart = time.perf_counter()
while tcurr <= 30:
    # Getting current time (s)
    tcurr = time.perf_counter() - tstart
    # Checking for even/odd number of 'bumps'
    if (touch.output % 2) == 0:
        # Assigning ZERO speed output
        motor.output = 0
    else:
        # Assigning output proportional to ambient light
        motor.output = color.output

# Stopping motor and closing EV3 connection
motor.stop()
ev3.set_statuslight(mode='solid')
ev3.close()
print('Done.')

Notes:

  1. pyev3 was developed and tested on MS Windows 10. It uses cython-hidapi for the USB communication interface.
  2. It's very likely it will also work on Unix and macOS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyev3-0.0.5.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyev3-0.0.5-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file pyev3-0.0.5.tar.gz.

File metadata

  • Download URL: pyev3-0.0.5.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for pyev3-0.0.5.tar.gz
Algorithm Hash digest
SHA256 6a928016e84e07d4cabe096b050683cc60e8d0ac0c045b410729cbb6f9732a42
MD5 d23b4adfe2600072e31bad49561420ed
BLAKE2b-256 f430005fa95021255b3b2d3022a1bddc8dc2486f2873f5c977f62a689b7c385d

See more details on using hashes here.

File details

Details for the file pyev3-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: pyev3-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for pyev3-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0e971575e4d4199188d4365fb061c0cfed2f1dedf79dbdbe150177bc6c98b189
MD5 6d6c23e9c5819dd0144c2ec629ad52ad
BLAKE2b-256 741e13ee7d87a12beb4c8284c232e27bd76850db0879cd802882751d1cb38ba6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page