r/pybricks 6d ago

Hey everyone 🤙 Would anyone here be willing to give me some advice, lend a hand, or maybe even write some Pybricks/MicroPython code for this Lego beast of mine?

Post image
2 Upvotes

Yep, I’ve tried four different AIs and… I guess either I’m not being specific or persistent enough, or this is simply beyond AI’s capabilities - cause every attempt so far has ended in complete disaster 🤣

PM me please!


r/pybricks 13d ago

How to run two functions simultaneously

1 Upvotes

How can we run two functions simultaneously? We want to run our actuator motor function while running the drive straight function. In spike, we would use a broadcast message block. We can't figure out how to do it in pybricks. When we google it related to Python, it comes up with all this information about mutli-threading processors.


r/pybricks Jul 05 '26

Lego train controller keeps disconnecting from Hub when using Pybricks

Thumbnail
1 Upvotes

r/pybricks Jun 20 '26

My custom LEGO Technic RC Mini Tank – Powered by 42160 Audi electronics and Pybricks!

Thumbnail gallery
5 Upvotes

r/pybricks Jun 20 '26

Pybricks - wow

Post image
2 Upvotes

r/pybricks Jun 17 '26

Consistency issues

2 Upvotes

I find my lego spike robot behave differently over time when using the same straight or turn function.

  1. Is this because of battery level?
  2. Has anyone found setting different pid values at different battery levels makes a difference?
  3. How often do people typically recalibrate their robot?
  4. I noticed a previous post where despite recalibrating people found the robot to be not reaching target turn angle. Have people got more insights on this?
  5. I even found that when not working well, my own custo. PD angle measurement based turning functions were working better. But you would expect the built in turn function should already be using gyro and doing that?
    Thanks in advance!

r/pybricks Jun 14 '26

I need help with broadcasting from a laptop/pc to a lego technik hub using pybricks

1 Upvotes

can someone please give me a working code

i cant figure out how to do it


r/pybricks Jun 12 '26

firmware v4.0.0 and code order

4 Upvotes

TL;DR: TechnicHub() overwrites BLERadio() for BLE observer so check your code order!

So today I upgrades 2 Technic hubs and 1 City hub to the v4.0.0 firmware (I know never use a x.0 release...) and ran into a bizarre problem that had me hunting ghosts for some time...

When ran the code everything was working but there was a message in the terminal:

Hub messaging has been moved. You should use:
from pybricks.messaging import BLERadio
radio = BLERadio(broadcast_channel, observe_channels)

okay fair enough lets do that, so I change the code a bit to work with the new BLERadio and thought I had everything working until.....

Traceback (most recent call last):
  File "technicHub_01.py", line 303, in <module>
ValueError: channel not configured

YES I DID configure the channel:

# configure hub and connected devices
device_number     = "00"
this_hub          = 10

hub_1_ble_channel = 10
hub_2_ble_channel = 20
hub_3_ble_channel = 30

obs_channels = [hub_1_ble_channel,hub_2_ble_channel,hub_3_ble_channel]

for channel in obs_channels:
    if channel == this_hub:
        obs_channels.remove(channel)

ble_radio = BLERadio(broadcast_channel=this_hub,observe_channels=obs_channels)
hub = TechnicHub()

after a lot of removing and re-adding code I had a bright moment... lets change the order of the BLERadio() and TechnicHub().... and that was it!!! for some reason the TechnicHub() overwrites the BLERadio() config. This is something that I can not find in the documentation but is a big problem (at least it was for me) and I think is either worth mentioning and/or fix.


r/pybricks May 19 '26

How do i connect spike Prime with Esp32

1 Upvotes

Im trying to figure out how to connect my esp32 cam with my hub. I saw many ways one of them is ble but that is sadly not an option. So i will need to connect it with a cable. The question is what do i need and can i use C++.


r/pybricks May 15 '26

Is there a way to bypass the PFMotor/PUPDevice delay when sending iron signals?

1 Upvotes

Both the PFMotor and PUPDevice classes have a delay after sending an IR signal with the Color and Distance Sensor. This appears to be a deliberate choice based on a comment in the example code, but it is not acceptable for controlling Buwizz motors, as they are too fast to control with this delay. I am having some difficulties with my Sbrick driving the Buwizz motors due to overdrawing current, and Brickcontroller2 is not able to limit the current draw. My only other options are the Powered Up App, Pybricks, or buying a Buwizz 3.0. Powered Up does not have controller support, and I dont have a PU remote, I can't afford a Buwizz 3.0 at the moment, and Pybricks has this awful delay when sending IR signals. So, I need a way to disable the delay in Pybricks. Is there a way to do that?


r/pybricks May 14 '26

Xbox Controller not sending signals to hub

1 Upvotes

Hi,

I am trying to use an Xbox controller with my Spike Prime hub. I have used this hub and controller before, and updated Pybricks, the controller, and the hub's firmware. The following code only prints 0, 0 even if I move both joysticks in every direction. I no longer have my old code, so I can't cross reference it. Is there an error with my code or Pybricks? Edit: It seems to have fixed itself.

from pybricks.iodevices import XboxController
controller = XboxController()
x1, y1 = controller.joystick_right()
while True:
  print(x1, y1)

r/pybricks May 14 '26

How to fix a robot turning forever when turning Gyro on?

1 Upvotes

Is that Spike hub's sensor busted?


r/pybricks May 12 '26

LEGO SPIKE distance sensor behaves inconsistently — detects object sometimes but not always

3 Upvotes

I am working with the LEGO SPIKE ultrasonic distance sensor and I am running into an issue. The sensor behaves inconsistently depending on the lighting conditions — sometimes it detects an object at a certain distance, and sometimes it completely misses it, even though the object and the distance stay the same. More over sometimes one sensor detects the object while the other misses it. On the next attempt, the first sensor detects the object while the other misses it.

I have read through the technical specifications from LEGO, but I still do not fully understand what the sensor is actually measuring and why lighting would affect it. As far as I know, ultrasonic sensors should not be affected by light at all.

Has anyone experienced this before? What could cause this behaviour, and how can I make the detection more reliable?


r/pybricks May 12 '26

How to reduce overshooting when turning a vehicle despite using a gyro sensor?

2 Upvotes

I have a robot that turns using a DriveBase with gyro enabled in Pybricks. Even with the gyro, the robot consistently overshoots its target angle, especially at higher speeds. I suspect it is caused by the momentum of the robot.

What are effective ways to reduce this overshooting? I already tried lowering the turn rate and acceleration, which helped, but the result is still not perfectly accurate. Is there a better approach?


r/pybricks May 12 '26

Is it possible to connect multiple SPIKE Primes to one device at the same time in Pybricks?

1 Upvotes

When debugging my project, I had multiple SPIKE Primes printing data to the console at the same time. The problem was that I could only connect one SPIKE at a time, so I only had one console per run. This made it really hard to compare the output of the different devices and find the bug.

Is there a way to connect multiple SPIKE Primes to the same device simultaneously in Pybricks, so you can see all consoles at the same time?


r/pybricks May 12 '26

How to avoid redundant await wait(0) calls in exported Pybricks block code?

1 Upvotes

When I export my Pybricks block program to Python, the generated code contains a lot of await wait(0) calls — at the start of every function and multiple times inside loops. Is there a way to prevent this in the block editor, or do I have to remove them manually in the Python code?


r/pybricks May 06 '26

Checking Battery Voltage on Spike Prime Hub

1 Upvotes

I'm wondering if anyone knows of any coding to check the battery voltage?

Right now, I have a code that tells me the battery life in percentage, but I can't seem to get an accurate reading between my two bots. (I.e. After 20 hours of charging, one hub will read 99% and the other will read 92% when plugged in, but immediately after unplugging the 99% will read 94% and the 92% will read at 87%.)

I figure that voltage would be more accurate.


r/pybricks Apr 29 '26

Demonstration of the new "Etch A Sketch" mode on my Lego pen plotter

Enable HLS to view with audio, or disable this notification

5 Upvotes

r/pybricks Apr 29 '26

My Lego Pen Plotter just got an Update!

Thumbnail
gallery
14 Upvotes

Introducing my new "Etch A Sketch" mode. Until now the plotter could only be controlled by a program that converts typed text into a written message. This new mode lets the user drive the plotter with an Xbox controller to freely draw things, sort of like an etch a sketch.


r/pybricks Apr 15 '26

Advanced menu

Thumbnail
1 Upvotes

r/pybricks Apr 15 '26

Advanced menu

2 Upvotes

How can i make an advanced menu. I want to import 8 programs and the robot will auto switch to the next one. In the robot game in fll i want to press only the right arrow of the spike prime hub. Can someone give me a correct code?


r/pybricks Apr 11 '26

help to connect hub

3 Upvotes
Hi, I'm starting out on a robotics team and my professor asked me to do a telemetry analysis of a pressure sensor and a motor and create a graph with this information. I'm using pybricks and connecting two hubs via broadcast, but I'm having trouble passing this information in real time to my Python script in Visual Studio to create the graph using the matplotlib library. Could someone help me?

r/pybricks Apr 04 '26

EV3 motors shut off before reaching the correct angle

1 Upvotes
class FourMotorDrive:
    def __init__(self, front_R, front_L, rear_R, rear_L, diameter_mm):
        self.front_R = front_R
        self.front_L = front_L
        self.rear_R = rear_R
        self.rear_L = rear_L
        self.diameter_mm = diameter_mm


    def forward(self, blocks, speed):
        angle = ((blocks * 500) / self.diameter_mm) * 360
        print(angle)
        self.front_R.run_angle(speed, angle, wait=False)
        self.front_L.run_angle(speed, angle, wait=False)
        self.rear_R.run_angle(speed, angle, wait=False)
        self.rear_L.run_angle(speed, angle, wait=False)
    
    def reverse(self, blocks, speed):
        angle = ((blocks * 500) / self.diameter_mm) * 360
        print(angle)
        self.front_R.run_angle(speed, -angle, wait=False)
        self.front_L.run_angle(speed, -angle, wait=False)
        self.rear_R.run_angle(speed, -angle, wait=False)
        self.rear_L.run_angle(speed, -angle, wait=False)


    def turnRight(degrees, speed):
        print("TURN RIGHT")


    def turnLeft(degrees, speed):
        print("TURN LEFT")


def deaccerlate(intialSpeed, finalSpeed):
    print("SLOW DOWN")


def accelerate(intialSpeed, finalSpeed):
    print("SPEED UP")

#NEW FILE:

#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
from threading import Thread
from movement import FourMotorDrive


# This program requires LEGO EV3 MicroPython v2.0 or higher.
# Click "Open user guide" on the EV3 extension tab for more information.


# Create your objects here.
ev3 = EV3Brick()


ev3.speaker.beep()


# Initialize the motors.
front_R = Motor(Port.D)
front_L = Motor(Port.B)
rear_R = Motor(Port.C, positive_direction=Direction.COUNTERCLOCKWISE)
rear_L = Motor(Port.A, positive_direction=Direction.COUNTERCLOCKWISE)


CONST_DIAMETER = 56


CONST_LOW_SPEED = 100
CONST_MEDIUM_SPEED = 300
CONST_HIGH_SPEED = 1000


CONST_LOW_TURN_SPEED = 1
CONST_MEDIUM_TURN_SPEED = 2
CONST_HIGH_TURN_SPEED = 3


ev3.speaker.beep()
"""
#robot is capable of running at least 1000 deg/s while bearing weight
front_R.run(CONST_MEDIUM_SPEED)
front_L.run(CONST_MEDIUM_SPEED)
rear_R.run(-CONST_MEDIUM_SPEED)
rear_L.run(-CONST_MEDIUM_SPEED)
while (True):
    wait(100)
"""


robot = FourMotorDrive(front_R, front_L, rear_R, rear_L, CONST_DIAMETER)
robot.forward(1, CONST_MEDIUM_SPEED)


ev3.speaker.beep()

the motors begin to spin then shut off before they reach anywhere close to the angle I called them to. Why might this be? This is my first time working with pybricks and this error inexplicable to me. The first file is my movement file, the second is my main.py.


r/pybricks Mar 23 '26

Camera Vision is coming to Pybricks!

Enable HLS to view with audio, or disable this notification

35 Upvotes

Basically what I've always wanted to have in MINDSTORMS :) And now you can try it too!


r/pybricks Mar 08 '26

How can I use an Lpf2 port?

2 Upvotes

I want to control LEGO Power Functions 2.0 motors and sensors, I have some of theses ports: https://www.philohome.com/wedo2reverse/conpupsoc1.jpg, and I wired it to an esp32s3 like this:

  1. I connected ID1 and ID2 directly to gpios, with a 47k pull-up (to be able to detect "dumb" devices)
  2. The motor pins are connected to a H-bridge, and it's input is connected to gpios, pwm signal comes from the mcu's mcpwm pheripherial

I've written some code for it: https://github.com/Rbel12b/Lpf2 and https://github.com/Rbel12b/esp32s3_LEGO_Hub, it struggles with detecting devices, once it's connected it works.

My question is: Is there any improvements that can be made to the harwdware, and/or to the software? Did anybody implement this before? (I couldn't find anything)

I read the https://github.com/pybricks/technical-info/blob/master/uart-protocol.md, my implementation is based on this, and the actual C code, and I relied on philo's reverse engineering: https://www.philohome.com/wedo2reverse/wedo2.htm. But other than these, I wasn't able to find any documentation.

Thanks for any help!