Skip to main content

Operate LEGO MINDSTORMS Inventor Hub from your computer

Project description

Operate LEGO MINDSTORMS Inventor Hub from your computer

This module allows you to operate the LEGO mindstorms hub from your computer. This means that instead of sending entire python files to the hub and letting it run them, you can run the command one after another from your computer. This allows easy experimenting from a python shell on your computer, showing you completions and API documentation on the way. This also allows you to use the regular debugging facilities you're used to.

The API mirrors that of the actual micropython API, so programs that run on the hub (and don't use callbacks) should run on your computer using this module and vice versa.

The API documentation was copied from the official LEGO MINDSTORMS Inventor Hub documentation.

Managing the actual connection to the hub is using the excellent rshell project.

Getting Started

Run:

pip install mindstorms

Connect the hub to your computer using the USB cable, and then run this from Python:

from mindstorms import Hub
hub = Hub()
while True:
    while hub.motion.gesture() != hub.motion.TAPPED:
        pass
    hub.sound.play('/extra_files/Hello')

Tap the hub, and hear it say "hello".

Easier usage of sensors using spikedev

You can use Daniel Walton's spikedev for easier usage of the sensors, like this:

pip install git+https://github.com/noamraph/spikedev.git@sensor-support-cpython
>>> from mindstorms import *
>>> from spikedev.sensor import *
>>> hub = Hub()
>>> color = ColorSensor(hub.port.D)
>>> color.value()
[0]
>>> dist = DistanceSensor(hub.port.E)
>>> dist.set_mode(DistanceSensorMode.DISTL)
>>> dist.value()
[58]

This currently relies on my pull-request. I hope it will be merged, and then you'll be able to use it directly from his repository.

Notes

The only missing classes from the official API are hub.BT_VCP and hub.USB_VCP. Adding them shouldn't be too difficult, I just didn't know how to test them.

I added all the methods from the official API, except for those that contains a callback.

License

MIT license.

Copyright (c) 2022 - Noam Raphael.

Based on the official API docs:

The MIT License (MIT)

Copyright (c) 2017-2021 - LEGO System A/S - Aastvej 1, 7190 Billund, DK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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

mindstorms-0.1.2.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

mindstorms-0.1.2-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file mindstorms-0.1.2.tar.gz.

File metadata

  • Download URL: mindstorms-0.1.2.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.4.0-100-generic

File hashes

Hashes for mindstorms-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bb5144f38ac2e1e1ef98587ae239b553fde9878e54c19b8889d9c39a3c4e90b9
MD5 4c83c840afe8feb6ff2de3721d0c5470
BLAKE2b-256 eb184f835563432aad7fd18809640f04549d57e9b92ca35b31f940f3c999403d

See more details on using hashes here.

File details

Details for the file mindstorms-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mindstorms-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.4.0-100-generic

File hashes

Hashes for mindstorms-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6ebb23f581efb8d2eccf3178cecf22efe7fdac64bbef6693aa08f330e44ce391
MD5 80da08086edc607def897a971c205128
BLAKE2b-256 2be7afe2024a0230ff94f25a0cb07954495da18299e688cc35f44abb555cf285

See more details on using hashes here.

Supported by

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