From 5549b873777cf9ac240fe7eea00f9e2a17d18eb9 Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 18 Feb 2022 18:35:38 +0100 Subject: [PATCH 01/13] Update howto-control-rpi-poweredup.md --- docs/howto/howto-control-rpi-poweredup.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/howto/howto-control-rpi-poweredup.md b/docs/howto/howto-control-rpi-poweredup.md index 57a8a19..cc83365 100644 --- a/docs/howto/howto-control-rpi-poweredup.md +++ b/docs/howto/howto-control-rpi-poweredup.md @@ -6,6 +6,17 @@ This document explains how to install a use a Python script to control a LEGO Po ## Step-by-step instructions +### Install "LEGO® TECHNIC™ CONTROL+" App + +Install the "LEGO® TECHNIC™ CONTROL+" app from + +* Google Play Store: +* Apple Store: TODO + +TODO + +### Install undera/pylgbst + Logged in as pi@rpi4gm35 From 56c93f30552be5e326f59653bf583bab66626b11 Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 18 Feb 2022 19:01:08 +0100 Subject: [PATCH 02/13] Instructions for updating the firmware on the Hub --- docs/howto/howto-control-rpi-poweredup.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/howto/howto-control-rpi-poweredup.md b/docs/howto/howto-control-rpi-poweredup.md index cc83365..8fccbc2 100644 --- a/docs/howto/howto-control-rpi-poweredup.md +++ b/docs/howto/howto-control-rpi-poweredup.md @@ -13,6 +13,12 @@ Install the "LEGO® TECHNIC™ CONTROL+" app from * Google Play Store: * Apple Store: TODO +Launch the app and select set "Liebherr 9800". + +Connect 2x XL motor and 1x L motor to the Hub. + +Follow the instructions displayed by the app and update the firmware if requested. + TODO ### Install undera/pylgbst From eb231ce3fa7fe088481ecbe804bbfd4d052a5b65 Mon Sep 17 00:00:00 2001 From: Macario Gianpaolo Date: Fri, 25 Feb 2022 05:43:17 +0100 Subject: [PATCH 03/13] Add section: Using Pybricks Signed-off-by: Macario Gianpaolo --- docs/howto/howto-control-rpi-poweredup.md | 30 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/howto/howto-control-rpi-poweredup.md b/docs/howto/howto-control-rpi-poweredup.md index 8fccbc2..5e3a68f 100644 --- a/docs/howto/howto-control-rpi-poweredup.md +++ b/docs/howto/howto-control-rpi-poweredup.md @@ -4,9 +4,7 @@ This document explains how to install a use a Python script to control a LEGO Powered Up Hub through BLE. -## Step-by-step instructions - -### Install "LEGO® TECHNIC™ CONTROL+" App +## Using the "LEGO® TECHNIC™ CONTROL+" App Install the "LEGO® TECHNIC™ CONTROL+" app from @@ -21,7 +19,31 @@ Follow the instructions displayed by the app and update the firmware if requeste TODO -### Install undera/pylgbst +## Using Pybricks + +### Install the Pybricks firmware + +Instructions at + +Before you begin, turn the hub off. The update works best with fresh batteries. +If you use the City Hub, you must unplug all motors and sensors. Follow these steps: + +1. Go to [Pybricks Code](https://code.pybricks.com/). +2. Press and hold the hub button. Wait for a blinking pink light. +3. While you hold it, click the _firmware update_ button. +4. Select the _LEGO Bootloader_ and click _Pair_. +5. Wait until the light turns off, and then blinks red/green/blue. +6. Release the button and wait for the installation to finish. + +### Load some Python program + +From the [Pybricks Code](https://code.pybricks.com/) web interface, upload to the LEGO Technics BT Hub the Python sources at TODO. + +TODO + +## Controlling using the Raspberrry Pi + +### Install undera/pylgbst on the Raspberry Pi From b235ef368efb821a012a43941810f30ae328d94d Mon Sep 17 00:00:00 2001 From: Macario Gianpaolo Date: Fri, 25 Feb 2022 05:48:12 +0100 Subject: [PATCH 04/13] code/pybricks-test01: Add main.py Signed-off-by: Macario Gianpaolo --- code/pybricks-test01/main.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 code/pybricks-test01/main.py diff --git a/code/pybricks-test01/main.py b/code/pybricks-test01/main.py new file mode 100644 index 0000000..71b2250 --- /dev/null +++ b/code/pybricks-test01/main.py @@ -0,0 +1,32 @@ +from pybricks.pupdevices import Motor +from pybricks.pupdevices import ColorDistanceSensor +from pybricks.parameters import Port, Stop +from pybricks.tools import wait + +# We'll use two motors. One is a dial +# to set the speed of the other motor. +motor = Motor(Port.A) +# dial = Motor(Port.A) +sensor = ColorDistanceSensor(Port.B) + +# Say hello :) +print("Hello, Pybricks!") + +# First, we'll move the dial to zero. +# dial.run_target(500, 0, Stop.COAST) + +while True: + # Set the speed based on dial angle + dist = sensor.distance() + speed = dist * 5 # dial.angle()*3 + if abs(speed) < 100: + speed = 0 + print("dist=", dist, ", speed=", speed) + + # Run motor at desired speed + motor.run(speed) + + # Wait briefly, then repeat + wait(10) + +# EOF From 7e600a26bceb2ad1b05d6e4cc76331d4c0540994 Mon Sep 17 00:00:00 2001 From: Macario Gianpaolo Date: Fri, 25 Feb 2022 05:50:18 +0100 Subject: [PATCH 05/13] LEGO: Add a few more links Signed-off-by: Macario Gianpaolo --- docs/bibliography.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/bibliography.md b/docs/bibliography.md index 199aab1..8bf6bcc 100644 --- a/docs/bibliography.md +++ b/docs/bibliography.md @@ -30,6 +30,9 @@ * [Build and Code Creative Robots with LEGO BOOST](https://www.packtpub.com/product/build-and-code-creative-robots-with-lego-boost/9781801075572) by Ashwin Shah. Packt Publishing, November 2021 * [Glossario by Italian LEGO® Users Group](https://itlug.org/glossario/) * [Smart Robotics with LEGO MINDSTORMS Robot Inventor](https://www.packtpub.com/product/smart-robotics-with-lego-mindstorms-robot-inventor/9781800568402) by Aaron Maurer. Packt Publishing, May 2021 +* +* +* ### Controlling LEGO via Bluetooth From f687d004a8c1e092400761e40a80a4682b5635f9 Mon Sep 17 00:00:00 2001 From: Macario Gianpaolo Date: Fri, 25 Feb 2022 05:53:21 +0100 Subject: [PATCH 06/13] Cleanup source code Signed-off-by: Macario Gianpaolo --- code/pybricks-test01/main.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/code/pybricks-test01/main.py b/code/pybricks-test01/main.py index 71b2250..334bb9f 100644 --- a/code/pybricks-test01/main.py +++ b/code/pybricks-test01/main.py @@ -1,10 +1,7 @@ -from pybricks.pupdevices import Motor -from pybricks.pupdevices import ColorDistanceSensor -from pybricks.parameters import Port, Stop +from pybricks.parameters import Port +from pybricks.pupdevices import ColorDistanceSensor, Motor from pybricks.tools import wait -# We'll use two motors. One is a dial -# to set the speed of the other motor. motor = Motor(Port.A) # dial = Motor(Port.A) sensor = ColorDistanceSensor(Port.B) @@ -16,12 +13,13 @@ # dial.run_target(500, 0, Stop.COAST) while True: - # Set the speed based on dial angle + # Set the speed based on sensor distance dist = sensor.distance() - speed = dist * 5 # dial.angle()*3 + speed = dist * 5 if abs(speed) < 100: speed = 0 print("dist=", dist, ", speed=", speed) + # speed = dial.angle() * 3 # Run motor at desired speed motor.run(speed) From ce557e54a9494fcb9fb331a5f9208f1e88656e38 Mon Sep 17 00:00:00 2001 From: Macario Gianpaolo Date: Fri, 25 Feb 2022 06:10:46 +0100 Subject: [PATCH 07/13] Rename file to *.mpy Signed-off-by: Macario Gianpaolo --- code/pybricks-test01/{main.py => main.mpy} | 0 docs/bibliography.md | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) rename code/pybricks-test01/{main.py => main.mpy} (100%) diff --git a/code/pybricks-test01/main.py b/code/pybricks-test01/main.mpy similarity index 100% rename from code/pybricks-test01/main.py rename to code/pybricks-test01/main.mpy diff --git a/docs/bibliography.md b/docs/bibliography.md index 8bf6bcc..bdba059 100644 --- a/docs/bibliography.md +++ b/docs/bibliography.md @@ -27,18 +27,31 @@ * [Powered Up - A tear down...](https://www.eurobricks.com/forum/index.php?/forums/topic/162288-powered-up-a-tear-down/) - Eurobricks Forum, 2018-06-07 * Reverse Engineering the LEGO BOOST Move Hub: * Python for LEGO BOOST: -* [Build and Code Creative Robots with LEGO BOOST](https://www.packtpub.com/product/build-and-code-creative-robots-with-lego-boost/9781801075572) by Ashwin Shah. Packt Publishing, November 2021 +* Book: [Build and Code Creative Robots with LEGO BOOST](https://www.packtpub.com/product/build-and-code-creative-robots-with-lego-boost/9781801075572) by Ashwin Shah. Packt Publishing, November 2021 * [Glossario by Italian LEGO® Users Group](https://itlug.org/glossario/) * [Smart Robotics with LEGO MINDSTORMS Robot Inventor](https://www.packtpub.com/product/smart-robotics-with-lego-mindstorms-robot-inventor/9781800568402) by Aaron Maurer. Packt Publishing, May 2021 -* -* -* ### Controlling LEGO via Bluetooth * [Controlling the Lego Technics Hub (Hub 2) via Bluetooth (btle) using a Rasperry Pi 4B](https://dietrichchristopeit.github.io/lego-pi-docs/#controlling-the-lego-technics-hub-hub-2-via-bluetooth-btle-using-a-rasperry-pi-4b) * [LEGO Wireless Protocol 3.0.00](https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#document-index) +New links to check and sort out: + +* Google Search: "[Powered Up Python library](https://www.google.com/search?q=Powered+Up+Python+library&oq=powered+up+Python+library)" +* Thread on StackExchange.com: [Which programming environments or APIs are available for the LEGO BOOST?](https://bricks.stackexchange.com/questions/10786/which-programming-environments-or-apis-are-available-for-the-lego-boost) +* [Hack Lego Boost with Raspberry Pi](https://magpi.raspberrypi.com/articles/hack-lego-boost-with-raspberry-pi) - The MagPi Magazine, 2019-xx-xx +* **pylgbst** - Python library to interact with Move Hub / PoweredUp Hubs + - GitHub repository: + - LibHunt: Pylgbst Alternatives: +* **BrickNil** - A Python async library for PoweredUp/Boost + - GitHub repository: + - Discussion on Eurobricks.com: +* +* +* +* + ## Python and Machine Learning * [Advanced Deep Learning with Python](https://www.packtpub.com/product/advanced-deep-learning-with-python/9781789956177) by Ivan Vasilev. Packt Publishing, December 2019 From f4e12f71119d615a5a2e6bc07859505324e4902f Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 25 Feb 2022 07:29:21 +0100 Subject: [PATCH 08/13] Change title and name of last section --- docs/howto/howto-control-rpi-poweredup.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/howto/howto-control-rpi-poweredup.md b/docs/howto/howto-control-rpi-poweredup.md index 5e3a68f..7ce4c62 100644 --- a/docs/howto/howto-control-rpi-poweredup.md +++ b/docs/howto/howto-control-rpi-poweredup.md @@ -1,4 +1,4 @@ -# HOWTO Control a LEGO Powered Up Hub from a Raspberry Pi +# HOWTO Control a LEGO Powered Up Hub for the ARNEIS Project ## Introduction @@ -41,7 +41,7 @@ From the [Pybricks Code](https://code.pybricks.com/) web interface, upload to th TODO -## Controlling using the Raspberrry Pi +## Controlling from a Raspberrry Pi ### Install undera/pylgbst on the Raspberry Pi From d4e178a83d3a1c5cac9e3bd91c3ab6ccaef3988c Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 25 Feb 2022 07:42:07 +0100 Subject: [PATCH 09/13] Detail where to find sample MicroPython sources --- docs/howto/howto-control-rpi-poweredup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/howto/howto-control-rpi-poweredup.md b/docs/howto/howto-control-rpi-poweredup.md index 7ce4c62..2170c7a 100644 --- a/docs/howto/howto-control-rpi-poweredup.md +++ b/docs/howto/howto-control-rpi-poweredup.md @@ -37,7 +37,7 @@ If you use the City Hub, you must unplug all motors and sensors. Follow these st ### Load some Python program -From the [Pybricks Code](https://code.pybricks.com/) web interface, upload to the LEGO Technics BT Hub the Python sources at TODO. +From the [Pybricks Code](https://code.pybricks.com/) web interface, create or open a MicroPython source file and upload it to the LEGO Technics BT Hub. You may find some examples under the `/code` folder of the [ARNEIS repository on GitHub](https://github.com/B-AROL-O/ARNEIS). TODO From ffe3805e0074fceaeacff4429cb37e9790d12dd3 Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 25 Feb 2022 08:24:01 +0100 Subject: [PATCH 10/13] Update and rename main.mpy to main.py --- code/pybricks-test01/{main.mpy => main.py} | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename code/pybricks-test01/{main.mpy => main.py} (77%) diff --git a/code/pybricks-test01/main.mpy b/code/pybricks-test01/main.py similarity index 77% rename from code/pybricks-test01/main.mpy rename to code/pybricks-test01/main.py index 334bb9f..f6f95d0 100644 --- a/code/pybricks-test01/main.mpy +++ b/code/pybricks-test01/main.py @@ -1,13 +1,15 @@ -from pybricks.parameters import Port +from pybricks.parameters import Port, Color from pybricks.pupdevices import ColorDistanceSensor, Motor from pybricks.tools import wait +# Say hello :) +print("Hello, Pybricks!") + motor = Motor(Port.A) # dial = Motor(Port.A) sensor = ColorDistanceSensor(Port.B) - -# Say hello :) -print("Hello, Pybricks!") +# Sensor light will be set to Color.GREEN when measuring distance +sensor.light.off() # First, we'll move the dial to zero. # dial.run_target(500, 0, Stop.COAST) @@ -15,6 +17,7 @@ while True: # Set the speed based on sensor distance dist = sensor.distance() + # sensor.light.on(Color.RED) speed = dist * 5 if abs(speed) < 100: speed = 0 @@ -25,6 +28,6 @@ motor.run(speed) # Wait briefly, then repeat - wait(10) + wait(100) # EOF From 2b2c6aec5a630c07dd5d24a36a748a936142774a Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 25 Feb 2022 08:31:57 +0100 Subject: [PATCH 11/13] main.py: Please Super-Linter (isort) --- code/pybricks-test01/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/pybricks-test01/main.py b/code/pybricks-test01/main.py index f6f95d0..e03b37b 100644 --- a/code/pybricks-test01/main.py +++ b/code/pybricks-test01/main.py @@ -1,4 +1,4 @@ -from pybricks.parameters import Port, Color +from pybricks.parameters import Color, Port from pybricks.pupdevices import ColorDistanceSensor, Motor from pybricks.tools import wait From cfad76a36eb49061b871ab2cb4e08571a903907d Mon Sep 17 00:00:00 2001 From: Gianpaolo Macario Date: Fri, 25 Feb 2022 08:34:23 +0100 Subject: [PATCH 12/13] Update main.py --- code/pybricks-test01/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/pybricks-test01/main.py b/code/pybricks-test01/main.py index e03b37b..fdcf173 100644 --- a/code/pybricks-test01/main.py +++ b/code/pybricks-test01/main.py @@ -17,7 +17,7 @@ while True: # Set the speed based on sensor distance dist = sensor.distance() - # sensor.light.on(Color.RED) + sensor.light.on(Color.RED) speed = dist * 5 if abs(speed) < 100: speed = 0 From 8c373311059b657d15d0c9bb5f889ded2e35e79c Mon Sep 17 00:00:00 2001 From: Macario Gianpaolo Date: Fri, 25 Feb 2022 16:53:01 +0100 Subject: [PATCH 13/13] code/pybricks-test01: Add requirements.txt Signed-off-by: Macario Gianpaolo --- code/pybricks-test01/requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 code/pybricks-test01/requirements.txt diff --git a/code/pybricks-test01/requirements.txt b/code/pybricks-test01/requirements.txt new file mode 100644 index 0000000..e6631ba --- /dev/null +++ b/code/pybricks-test01/requirements.txt @@ -0,0 +1 @@ +pybricks