Skip to main content

image_pypi image_downloads image_license passing quality Coverage Status

BrickNil [*] provides an easy way to connect to and program LEGO® Bluetooth hubs (including the PoweredUp Passenger Train 60197 and Cargo Train 60198 sets, and the Lego Duplo Steam Train 10874 and Cargo Train 10875 ) using Python on OS X and Linux. This work was inspired by this EuroBricks thread, and the NodeJS Powered-Up library. Unlike the official apps available from LEGO, BrickNil allows you to control multiple hubs with a single program, which lets you easily scale to programming large interactive systems.

BrickNil requires modern Python (designed and tested for 3.7) and uses asynchronous event programming built on top of the Curio async library. As an aside, the choice of async library is fairly arbitrary; and enabling another library such as asyncio or Trio should be straightforward.

An example BrickNil program for controlling the Train motor speed is shown below:

from curio import sleep
from bricknil import attach, start
from bricknil.hub import PoweredUpHub
from bricknil.sensor import TrainMotor

@attach(TrainMotor, name='motor')
class Train(PoweredUpHub):

    async def run(self):
        for i in range(2):  # Repeat this control two times
            await self.motor.ramp_speed(80,5000) # Ramp speed to 80 over 5 seconds
            await sleep(6)
            await self.motor.ramp_speed(0,1000)  # Brake to 0 over 1 second
            await sleep(2)

async def system():
    train = Train('My train')

if __name__ == '__main__':
    start(system)

Features

  • Supports the following LEGO® Bluetooth systems:
  • Supports the following actuators/sensors:
    • Internal motors

    • Train motors

    • Hub LED color

    • Boost vision sensor (color, distance)

    • Boost internal tilt/orientation/accelerometer

    • Boost external motor

    • External light

    • Hub buttons

    • Wedo external motor

    • Wedo tiltand motion sensors

  • Fully supports Python asynchronous keywords and coroutines
    • Allows expressive concurrent programming using async/await syntax

    • The current implementation uses the async library Curio by David Beazley

  • Cross-platform
    • Uses the Adafruit Bluefruit BluetoothLE library for Mac OS X

    • Uses the Bleak Bluetooth library for Linux and Win10; also tested on Raspberry Pi.

Release files for bricknil 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for bricknil 0.9.3
File Interpreter ABI Platform
bricknil-0.9.3-py3-none-any.whl Python 3 none any Details

Release files / bricknil-0.9.3-py3-none-any.whl

Download URL bricknil-0.9.3-py3-none-any.whl
Size 85.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c542976f9f794833133a26d5c7d028fa599bff12e13c6d653da95c744cbcb54
BLAKE2b-256 checksum
How to use checksums
2046f33df76cb574dbffeeab6f438a1e3ee902f163bda24d16b294c5004f74c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.9.3 This release

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7

1 release file

0.6

1 release file

0.5.1

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page