Recommended Posts

Hi everyone --- Pybricks here!

Q&A

We've seen a lot of forum members occasionally mention Pybricks. We've seen a lot of cool projects around here as well! We're excited to join the discussion, so we hope it's okay that we open a dedicated topic.

To make things easier for you, we're happy to answer all your questions about Pybricks. Questions about Powered Up and MINDSTORMS are welcome too.

You're also welcome to post ideas and requests for new Pybricks features. Feel free to get creative here!

We're currently working hard to make Pybricks more accessible for beginning users. This is another reason we want your feedback.

What is Pybricks?

If you haven't heard about Pybricks yet, here it is in a nutshell:

Pybricks lets you run MicroPython scripts on all Powered Up and MINDSTORMS hubs. MicroPython is like Python, just smaller and faster so it can run on the hubs.

Your script runs autonomously on the hub, and you can even save it permanently. This means code runs much faster, and you don't always need to be connected to a smart device.

We've also made it really easy to use many of the hidden features of all hubs, motors, and sensors. For example, it's really easy to calibrate your color sensors, or adjust the control settings of your motors.

You can write your code on Windows, Mac, Linux, Chromebook, and Android. There's no need to install complicated tools; all you need is a browser with Bluetooth support, like Google Chrome, Chromium, or Microsoft Edge.

You can try Pybricks via https://pybricks.com/

Share this post


Link to post
Share on other sites
  1. The major drawback with Powered Up is, that I have to use a phone. I would like to use my PS4 Controller instead, to get rid of the phone. So, does Pybricks support Controllers in general? If not, is that somewhere in your backlog? If it is, when will the support be roughly available?
  2. Does Pybricks currently support connections between hubs so they can communicate with each other? If not, is that feature in your backlog? If yes, when will it be roughly available?

Share this post


Link to post
Share on other sites
Posted (edited)

Hi,

thanks for your post.

There are the two essential questions from @Andman

- How to connect a gamepad?
- How to connect Hubs? How many? How?

And
- how will they communicate?

Or, in general: how to connect something to get control of the Hub(s) , i.e the remote.

An that leads me to the next point:
I now these points are on the roadmap (Step 4?), but being not very familiar with github I lost the current state of developement.
There for it could be useful to have a info on pybricks.org what is current, what is new, what is planned (all with dates :wink:)

By the way I saw the "class remote", but that seems to work only with beta and only for Spike/RI?
Even having  an example and changing the path in the include it could not be included, I'm to early?

The new "control center" with "Download coding page" and "include this program" works fine, but same as above:

Seems, that is not mentioned on pybricks. com (or I did not find....)

But in general: great work, wonderful layout, very good coding documentation.
Thanks!

 

Edited by Lok24

Share this post


Link to post
Share on other sites

The City Hub, Move Hub and Technic Hub only have Bluetooth Low Energy (BLE). This means that connecting to a PS4 controller (Bluetooth Classic) is not possible. The latest Xbox controller has BLE, so this could theoretically work. This is a bit further down the backlog, though. You can see our plans for Bluetooth here.

But if the goal is to get rid of the phone, how about the Powered Up remote? We are currently working on this. It's already working on one hub --- three to go.

Hub-to-hub communication is planned as well. We're hoping to get that done this year.

Quote

what is new, what is planned (all with dates)

By the way I saw the "class remote", but that seems to work only with beta and only for Spike/RI?

To keep things simple, we only "support" everything that you can find in the documentation panel in the Pybricks Code app. New features will eventually be added there, along with a changelog.

So there's no need to keep track of GitHub unless you are super curious, but you're definitely welcome to.

Quote

what is planned (all with dates)

This would be nice, but it's hard to provide exact dates when we're all volunteers :)

Share this post


Link to post
Share on other sites
17 minutes ago, Pybricks said:

This would be nice, but it's hard to provide exact dates when we're all volunteers :)

You missed to qoute the ":wink:" behind my "request".

This all is good news, but this is exactly what would be nice to have (from my point of view) on "pybricks.com" in the menu as i.e. "News".
A short information what is new and what is planned.

Thanks for the information, I'll stay tuned.

 

 

Share this post


Link to post
Share on other sites

Hi,

among all my projects it always found it very useful to save parameters for a specific program.

Normally I use a ESP32, which has a file system and allows me to configure a model via WLAN/HTML.
How could such a szenario be combined with pybrick hubs?

Might it be possible to add it to a pybrick network of Hubs, is it necessary  that it acts and behaves like a PU Hub?

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

We are planning to let the hubs communicate between each other and with other devices (phones, PC, etc.) using the standard Nordic UART Service.

There are a lot of tools for this already out there, which should make it a little easier to integrate with tools like you mentioned.

Of all the hubs, only the SPIKE Prime Hub and MINDSTORMS Inventor Hub have a file system, by the way. But you can still give each hub a unique name to tell them apart.

Edited by Pybricks

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks for doing this Q&A!

Are there generic timers and counters in Pybricks? I looked through the API docs and didn't see anything.  Specifically, a counter you can read that returns a monotonically increasing counter at a fixed frequency would be useful.  That could be the number of ms that the hub has been turned on or perhaps a counter running at the clock frequency of the CPU. Also, a wait_until(count | time) would be very useful.  There is a wait(ms) function but that's not quite what's needed.  Being able to configure an event to be received at a specific time in the future would also be helpful.

An example project that could be made with this is a clock.  Say you want to update a display every second.  You wouldn't want to put an update_display() and wait() in a loop because you would get cumulative error.  If you instead used wait_until(), you could calculate the time to wait for to be exactly 1 second after the last one no matter how long the other processing takes.

Edited by Glaysche

Share this post


Link to post
Share on other sites

Thanks for explanation.

 

13 hours ago, Pybricks said:

But you can still give each hub a unique name to tell them apart.

Yes, I use that already. So there is a method to store value(s) permanently. How many bytes, does this depend on HW?

Share this post


Link to post
Share on other sites
14 hours ago, Glaysche said:

Thanks for doing this Q&A!

Are there generic timers and counters in Pybricks? I looked through the API docs and didn't see anything.  Specifically, a counter you can read that returns a monotonically increasing counter at a fixed frequency would be useful.  That could be the number of ms that the hub has been turned on or perhaps a counter running at the clock frequency of the CPU. Also, a wait_until(count | time) would be very useful.  There is a wait(ms) function but that's not quite what's needed.  Being able to configure an event to be received at a specific time in the future would also be helpful.

An example project that could be made with this is a clock.  Say you want to update a display every second.  You wouldn't want to put an update_display() and wait() in a loop because you would get cumulative error.  If you instead used wait_until(), you could calculate the time to wait for to be exactly 1 second after the last one no matter how long the other processing takes.

Yes, you can read about the StopWatch class here. It can read the time since the program started. You could use it to wait for a certain amount of time too.

So a simple clock example could look like this:

image.png.99aa6a339429a6b862803f89935b9080.png

 

 

 

2 hours ago, Lok24 said:

So there is a method to store value(s) permanently. How many bytes, does this depend on HW?

We might add a menu where you can choose a hub name while you installl the firmware.

To store more than a name, you could just store any arbitrary program on the hub and start it with the button.

Share this post


Link to post
Share on other sites

Hi , thats good news, thanks!

Works fine.

 

Share this post


Link to post
Share on other sites
On 6/20/2021 at 2:16 PM, Pybricks said:

We might add a menu where you can choose a hub name while you installl the firmware.

To store more than a name, you could just store any arbitrary program on the hub and start it with the button. 

Hi,

My idea was to read and write from and to a variable in the program during execution.

Motor runs with speed v

Speed ist adjusted to v=500  via FB - and stored in the "Hub Name" as "Hub no 7 - 500"

When starting program next name is read and v set to 500 - without any FB

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

You can read the hub name within your script as

hub = TechnicHub()

name = hub.system.name()

print(name)

And then use it as you like.

Edited by Pybricks

Share this post


Link to post
Share on other sites
Posted (edited)
4 minutes ago, Pybricks said:

You can read the hub name within your script as

And then use it as you like.

Thanks, didn't find in the docs

I'll try right now.

Edited by Lok24

Share this post


Link to post
Share on other sites

The hub name is a new feature that will appear shortly. We will make it visible in the documentation once it is actually possible to change the name.

Share this post


Link to post
Share on other sites
6 hours ago, Pybricks said:

We're excited to share that the Powered Up remote now works with all hubs. This will come to the official Pybricks release eventually, but you can already try the next beta release if you're curious. 

Yahoo! It' great that you guys put in so much work to operate and intergate Lego hubs with a decent written language. Thank you.

Share this post


Link to post
Share on other sites

Just playing with pybricks recently and have a question.

How do I set the max speed for motors? I know the speed (deg/s) command. But whats the max deg/s per motor? Haven't found anything in the docs.

Is there any percentage command ?

br

Share this post


Link to post
Share on other sites

With the run_until_stalled you can give it a limited % of power, otherwise you will be giving deg/s, which to me is much more usefull. As battery % decreases a % speed will never be the same. For some machines I use a timer to calculate length etc, then it's good to know a belt is running at 700deg/s constantly. I think a Large EV3 motor tops out around 800, that's why I use 700 as it will even do that with a low battery. Medium motor is around 1000 I think. What you would do is just send a .run() command and then measure the deg/s with .speed() command. It should give the maximum speed the motor can do.

 

More information to be found here: https://pybricks.com/ev3-micropython/ev3devices.html

Share this post


Link to post
Share on other sites

thanks, it worked well.

PU XL motor max is around at 1000 deg/s.

Now it's easy for me to set the limit for my application. 20% speed is around 200 deg/s.

Share this post


Link to post
Share on other sites

Thanks @dunes for the question and @Mr Jos for your quick response.

Indeed, the default maximum speed is currently 1000 deg/s for the Powered Up XL motor. To find out, you can do this:

from pybricks.pupdevices import Motor
from pybricks.parameters import Port
from pybricks.tools import wait

# Initialize your motor.
my_motor = Motor(Port.A)

# Read the default limits for this motor.
speed_limit, acceleration_limit, duty_limit, torque_limit = my_motor.control.limits()

# Print the speed limit.
print("speed limit:", speed_limit)

# You can change the limits like this:
my_motor.control.limits(acceleration=200)

Changing the acceleration like this is nice if you want realistic behavior for some Technic vehicles. 

I think we have to add a documentation page where you can conveniently read this information. Thanks for the suggestion.

Share this post


Link to post
Share on other sites
6 hours ago, Pybricks said:

 


# You can change the limits like this:
my_motor.control.limits(acceleration=200)

 

Yes but not any time?

FB = Remote()
MotorA = Motor(Port.A)
MotorA.control.limits(acceleration=500) # < --- works

while True:
    pressed = FB.buttons.pressed()
    if Button.LEFT_PLUS in pressed:
        v = 1000
    if Button.LEFT_MINUS in pressed:
        v = 0
        MotorA.control.limits(acceleration=1000) # <------- Errno 16 Device or resource busy
    wait(100)
    MotorA.run(v)  

 

Share this post


Link to post
Share on other sites

Yes that's correct;

You can only change the settings while the controller is stopped. For example, you can set the settings at the beginning of your program. Alternatively, first call stop() to make your Motor or DriveBase stop, and then change the settings.

Source: https://pybricks.com/ev3-micropython/motors.html#control

(I have read the complete website from pybricks so many times to program my machines that I now know it from my head haha)

Share this post


Link to post
Share on other sites

Thanks @Mr Jos

I see. The idea was to accelerate slow, but to "brake" faster.
Perhaps I could add a stop and then immidiately the run commend again, we'll see,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.