Skip to main content

EV3 direct commands

Project description

Use python3 to program your LEGO Mindstorms EV3. The program runs on the local host and sends direct commands to the EV3 device. It communicates via bluetooth, wifi or USB. I wrote a blog about this code.

There is no need to boot the EV3 device from a SD Card or manipulate its software. You can use it as it is, the EV3 is designed to execute commands which come from outside.

Installation

python3 -m pip install --user ev3_dc

Examples

Writing and sending direct commands

This program communicates via USB with an EV3 device (mac-address: ‘00:16:53:42:2B:99’, replace it by the the mac-address of your EV3) and plays a tone with a frequency of 440 Hz for a duration of 1 sec.

import ev3_dc as ev3

my_ev3 = ev3.EV3(protocol=ev3.USB, host='00:16:53:42:2B:99')
my_ev3.verbosity = 1
ops = b''.join((
    ev3.opSound,
    ev3.TONE,
    ev3.LCX(1),  # VOLUME
    ev3.LCX(440),  # FREQUENCY
    ev3.LCX(1000),  # DURATION
))
my_ev3.send_direct_cmd(ops)

The output shows the direct command, which was sent to the EV3 device:

11:48:31.188008 Sent 0x|0E:00|2A:00|80|00:00|94:01:01:82:B8:01:82:E8:03|

Subclasses of EV3 with comfortable APIs

Method play_tone of class Jukebox also plays tones:

import ev3_dc as ev3

jukebox = ev3.Jukebox(protocol=ev3.BLUETOOTH, host='00:16:53:42:2B:99')
jukebox.verbosity = 1
jukebox.play_tone("a'", duration=1)

This program does the very same thing via bluetooth! Before you can run it, you need to pair the two devices (the computer, that executes the program and the EV3 brick). The output:

11:55:11.324701 Sent 0x|0E:00|2A:00|80|00:00|94:01:01:82:B8:01:82:E8:03|

Independent Tasks

Specialized classes (e.g. class Jukebox) provide factory methods, that return thread tasks. Thread tasks allow to start, stop and continue independent tasks.

import ev3_dc as ev3

jukebox = ev3.Jukebox(protocol=ev3.WIFI, host='00:16:53:42:2B:99')
antemn = jukebox.song(ev3.EU_ANTEMN)

antemn.start()

This program plays the EU antemn. Before you can execute it, you need to connect both devices (the computer, that runs the program and the EV3 brick) with the same LAN (local area network), the EV3 brick must be connected via wifi. If you don’t own a wifi dongle, modify the protocol and select ev3.BLUETOOTH or ev3.USB.

Some remarks:
  • Method song() returns a thread_task object, which can be started, stopped and continued. It plays tones and changes the LED-colors.

  • Starting the thread task does not block the program nor does it block the EV3 brick. It runs in the background and allows to do additional things parallel.

Read ev3_dc.readthedocs.io for more details.

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

ev3_dc-0.9.4.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

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

ev3_dc-0.9.4-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file ev3_dc-0.9.4.tar.gz.

File metadata

  • Download URL: ev3_dc-0.9.4.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for ev3_dc-0.9.4.tar.gz
Algorithm Hash digest
SHA256 344f11fbcaa783e57a0343e7b25ee08a1b64137144fa8d1094c38628c056be45
MD5 58b190a4ff441e30f6f33aad13b10607
BLAKE2b-256 608bc36945d343c677528cba143f28babcaf9155c8956ad21edf8c88f5dda6b8

See more details on using hashes here.

File details

Details for the file ev3_dc-0.9.4-py3-none-any.whl.

File metadata

  • Download URL: ev3_dc-0.9.4-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/49.3.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for ev3_dc-0.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 616b4308462209ea482cbdecad4c6590a6833ff3b57aa28427531f8739ef57ac
MD5 bc8bfd5093e5eb6410725a2ff66037cd
BLAKE2b-256 de5bdb53f3d61d458d8c01e91588c40b108302c3675b27017a7f4082f8ac6b39

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