Jump to content
THIS IS THE TEST SITE OF EUROBRICKS! ×
THIS IS THE TEST SITE OF EUROBRICKS!

Recommended Posts

Posted
6 minutes ago, The_Cook said:

There will always be the "double click" to start the hub and then start the python program to then pair with the remote.

Perhaps it is possible to start the program automatically when turning on the hub, I don't know.

But "normally" it is like you described.

And the remote doesn't eally actively pair, the programm waits for a remote to connect.

And the remote doesn't "choose" a color.

Just set it as desired.

 

 

 

  • Replies 359
  • Created
  • Last Reply

Top Posters In This Topic

Posted

I have problem with hub to hub communication, I can read the angle of the motor, but I send only value but I receive value and comma, for example i send (10) but read (10,) which I can´t use as value. Any ideas what I did wrong or it is not possible at this moment send only value?

Posted

It receives a tuple of values even if you just send one value. To get the value out of it, just read the first value like so:

my_value = received_data[0]

 

@The_Cook, since you choose the color for the remote light yourself, you could set the hub light to the same value.

Posted
12 hours ago, Pybricks said:

 

@The_Cook, since you choose the color for the remote light yourself, you could set the hub light to the same value.

No, I haven't chosen the color for the remote, the remote has chosen a colour, perhaps based on whatever Bluetooth channel the remote and hub have negotiated for each other.
That's why I'm interested in whether the current state of LED in the remote can be read, so that I can set the hub to the same value.

I had a quick dig around the git-hub source but whilst I can see the Python that provides the forward facing interface for the various hubs, remotes and motors, I could immediately see any code to link the interface to whatever's going on underneath. Again, I'll fully admit that I was poking around and might not have poked into the right files or might not have realised that a certain bit of syntax links back to underlying code already existing in the various devices.

Posted
9 hours ago, The_Cook said:

That's why I'm interested in whether the current state of LED in the remote can be read, so that I can set the hub to the same value.

But why read it? Just set it.

 You have a "connect" somewhere in your prog:

my_remote = Remote()

 

And after that succesfully established you set:

remote.light.on(Color.RED)
hub.light.on(Color.RED)

 

 

Posted

I understand that I can just set it, but the whole point about asking if the remote LED colour is readable is that the connection process chooses a colour to display on both the remote and the hub so that small children can see which remote is paired to which hub.

I want to replicate that original default behaviour, for the benefit of a small child that is used to the colours matching.  To do that I need to know which colour the remote and hub have negotiated for each other and is displayed on the remote, then I can set the hub accordingly.

I could just create a different python program for each hub in each train with a unique colour set to both remote and hub in each one. It would work but it's a brute force solution rather than the elegance of using information from the existing pairing code that is already present in both remote and hub.
 

Posted

I understand.

But as far as I know:

If you use two hubs and two remotes and connect each hub with one remote, they migtht all for devices show green?

Without interferring with each other.

Except when the remote stores the "channel".

 

Posted

The Lego connection protocol seems to be able to choose a different colour for the different pairings. I have no inisght into whether that is done by assessing what is already paired nearby, or whether it's just some form of hashing on the identifier of the underlying bluetooth channel to generate a number from that can be mapped to a colour. Obviously, if there are enough hubs present then at some point the colors will have to be reused.

I'll see if @Pybricks has anything to add, then I might just have to take the path of least resistance and hard-code the colours. Easy enough to set green for the green train, yellow for the yellow train.

Posted

I don't remember precisely, but I think that, with Pybricks, upon connection the remote's LED always lights up in the same colour.

What you can do is, after connecting, randomly choose a colour and set it for the hub and remote. In case two hub-remote pairs light up in the same colour, you can set the remote's green button to trigger another ransom colour choosing.

  • 2 weeks later...
Posted (edited)

As far as I know it is now

- possible to store data in the hub

That means: program is stored in the hub and running, contains a command "store", an data can be recalled after power off/on?
For technic hub and city hub?

- possible to let two hubs communicate with each other?
For technic hub and city hub and mixed?

If the answer to both questions is "yes":

Run Hub_A with a certain configuration (Maxspeed Port A  = 75) stored in the data area
Connect with pybricks to HUB_B, in the editor, write a small program containing only config string "Maxspeed Port A  = 50" and the send-routine to send to HUB_A

Could that work? Did I explain clearly enough?

Where do I found examples for Hub-to Hub and store data?
I checked docs, but was completely lost ;-)

 

Edit: Ah, found!

class LWP3Device(hub_kind, name=None, timeout=10000)
and
system.storage (128 Byte)

 

This could solve the configuration issues @vascolp ?

 

Edited by Lok24
Posted
3 hours ago, Lok24 said:

This could solve the configuration issues @vascolp ?

 

system.storage() works very well and it is definitely part of the solution to keep configurations in a general purpose Hub program. This is one side of the equation. But talking with another Hub, in my opinion, is not the other side… guess what would be the other side! :classic:

Posted

I don't know what you mean.

My idea is: flash HUB_A once(!) with the desired public program, which has some parameters (ports, buttons, speed etc), all stored in system.storage

The programmer serves also a website (I use a Excel-Macro) to configure, pressing the button "Finish" all values and a small program are written to the clipboard.

Then
- connect a second hub to the browser
- insert clipboard
- run program

which does nothing but sending the parameter-string to HUB_A where it can be read in main loop and stored.

So: Flash only once, configure as often as desired.

 

 

 

Posted
1 hour ago, Lok24 said:

So: Flash only once, configure as often as desired.

I also don't get why you need two hubs for this. Remote BlaBla already does this with a single hub and a remote.

Posted
4 hours ago, Lok24 said:

I don't know what you mean.

My idea is: flash HUB_A once(!) with the desired public program, which has some parameters (ports, buttons, speed etc), all stored in system.storage

The programmer serves also a website (I use a Excel-Macro) to configure, pressing the button "Finish" all values and a small program are written to the clipboard.

Then
- connect a second hub to the browser
- insert clipboard
- run program

which does nothing but sending the parameter-string to HUB_A where it can be read in main loop and stored.

So: Flash only once, configure as often as desired.

It’s a curious idea, you are using another hub just to avoid flashing the main hub… But hubs do talk BLE with any other device, does not need to be another hub... 

Posted
On 8/7/2023 at 11:15 PM, vascolp said:

It’s a curious idea, you are using another hub just to avoid flashing the main hub

Sorry for explaining it not clear enough, the idea was to use an external editor to configure, and so it could be used with 3.2 too.
Or you create the string for the remote, but even then you have to use a very small program to rename the remote.

So it was meant as an enhancement.

 

Posted
20 hours ago, Lok24 said:

Sorry for explaining it not clear enough, the idea was to use an external editor to configure, and so it could be used with 3.2 too.
Or you create the string for the remote, but even then you have to use a very small program to rename the remote.

So it was meant as an enhancement.

 

Ah doing a helper program to configure Remote Bla Bla for instance. Not a bad idea!... a bit against the idea of not programming but it would be only configuration.

Posted
5 minutes ago, vascolp said:

Ah doing a helper program to configure Remote Bla Bla for instance.

That was the idea, and I had such here.

5 minutes ago, vascolp said:

a bit against the idea of not programming but it would be only configuration

No, a website or Excel or whatever, similar to the GUI of SBRICK, BrickController, or BUWIZZ.

Which you or I or whoever release and publish

And as result when pressing "finish" a program like that in the clipboard

from pybricks.pupdevices import Remote
my_remote = Remote()
my_remote.name("yourblastring")

So user has to

- configure via tool
- click "finished"
- https://code.pybricks.com/
- insert program from clipboard
- connect remote
- run

And that  should work for all hubs, even with 3.1
I can show a quick and dirty example later, have to search, cause I used that last in 2021 ;-)

(And: config could also(!) be stored in system.storage of hub, read, stored in remote and back to GUI)

 

 

 

Posted (edited)

Hi, did'nt find my old stuff

but created something new
Quite simple as an example for two ports
Here is an Excel-Sheet with a button

python1.jpg

Here's the Pybricks-code

python2.jpg

and the result

 

python3.jpg

 

Of course one could also add a formpython4.jpgor do the same with HTML and js .....

But now it''s a little bit off topic, perhaps open a new thread if interested.

 

Edited by Lok24
  • 1 month later...
Posted

Hi,

First, thanks to everyone involved in creating and maintaining PyBricks. It's a fabulous piece of work.

Until recently I've been using RCX units running NQC code. However, the inability for programs to be stored when the unit loses power is a big downside. I'm also finding that the wires on some of the sensors are starting to turn brittle (they are approaching 20 years old).

So I've been playing with Powered Up hubs, and so far having fun with them.

This Q&A is very helpful, and I've already learned a lot about it.

My question: is there a way to send commands to the hub from a program running on a phone or tablet?

Perhaps this could be done with a JavaScript program running in a web browser on the device (over a Bluetooth connection). Hoping this wouldn't be too different from a bluetooth remote.

I would like to be able to have a simple puzzle solving game on the phone/tablet, that would trigger actions on the model when people complete puzzles at public displays.

Love to hear your thoughts on this.

Again, thanks for the amazing work!

  • 2 weeks later...
Posted

Hi all,

I want to control a motor in 100 steps.
And use run(v) command.

The problem : v is in deg/s

So I have to calculate v to get the max value for v for a specific motor.

using dc(100) and speed() gives something about 1300 or 1600, depending on type of motor.
But: isn't that depending on battery voltage? Are there "standard" values for the different types of motors?

Long story short: how do I get the max deg/s ?

 

 

Posted
3 hours ago, Lok24 said:

Hi all,

I want to control a motor in 100 steps.
And use run(v) command.

The problem : v is in deg/s

So I have to calculate v to get the max value for v for a specific motor.

using dc(100) and speed() gives something about 1300 or 1600, depending on type of motor.
But: isn't that depending on battery voltage? Are there "standard" values for the different types of motors?

Long story short: how do I get the max deg/s ?

 

 

Max deg/s does also depend on the load. Higher loads will result in a lower max possible speed. For my machines I have noticed that the large motor maxes out around 900 deg/s, the medium around 1300 deg/s. If I want a stable rpm I use 800/1200 for large/medium.

Posted
7 hours ago, Lok24 said:

Hi all,

I want to control a motor in 100 steps.
And use run(v) command.

The problem : v is in deg/s

So I have to calculate v to get the max value for v for a specific motor.

using dc(100) and speed() gives something about 1300 or 1600, depending on type of motor.
But: isn't that depending on battery voltage? Are there "standard" values for the different types of motors?

Long story short: how do I get the max deg/s ?

 

 

In Remote Bla Bla I had a similar problem, I wanted to be able to define steps in terms of maximum speed for each motor type.

I got no-load speeds for each motor type from philohome great site, multiplied it by 0.9 and got a list of maximum speeds per device. If the device does not match... it uses 1000deg/s (why not?).  

Device ids are here.

Something like this:

    def get_dev_max_speed(port_p):
        devs_max_speed = { 38:1377, 46:1700, 47:1780, 48:1230, 49:1150, 75:1230, 76:1150 }
        return devs_max_speed.get(PUPDevice(port_p).info()['id'], 1000)

 

Posted (edited)

@vascolp

Thanks for posting my code ;-)

The problem is (example):

- assume the motor is "defined" with 1300
- and the "real" max ist 1000 (battery, load etc)
- remote controls 100 steps (vmax)

Here are the some steps controlled by the remote and the results for run(v):
Step / v
50 800
60 900
70  1000
80 1100
90 1200
100 1300

This has two effects:
with the last three steps there is no change in speed of motor
and even worse:
When reducing the speed with remote nothing happens.....

So I'd had to use the speed() to check the real speed and block the remote for further increase of v, remaining at 70.

Other ideas?

 

Edited by Lok24
Posted
9 hours ago, Lok24 said:

@vascolp

Thanks for posting my code ;-)

...

Wow... I didn't knew your code! I just googled it and found it. It is indeed very similar. So similar that I went to github to see when I first used my code... initial versions are here, from april 2022. The code and  the documentation of it.

Regarding the problem, yes there is no simple solution for it. The maximum speed will always depend on the load. That is why I multiplied by 0.9, an heuristic to cope with that (sort of) ... but in Remote Bla Bla, I use 9 steps at most. You are using 100 steps, that is too fine, so the last steps won’t be distinguishable...

I don't see a way of having a lot of steps and being able to define speed levels a priori... Maybe if you have some calibration mode, that would adjust itself to the MOC load, store it in the hub storage, and go from there. That or monitoring speeds per step constantly and dynamically adjust step speeds. 

 

Posted (edited)
15 hours ago, vascolp said:

Wow... I didn't knew your code! I just googled it and found it. It is indeed very similar. So similar that I went to github to see when I first used my code... initial versions are here, from april 2022. The code and  the documentation of it.

Just wanted to explain that I use this already ;-)

15 hours ago, vascolp said:

That is why I multiplied by 0.9,

So do I ;-)

15 hours ago, vascolp said:

that would adjust itself to the MOC load,

Take a simple loco, adjust and then couple 20 waggons.....

15 hours ago, vascolp said:

That or monitoring speeds per step constantly and dynamically adjust step speeds. 

That's my favoured idea, yes

 

 

Edited by Lok24

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

Announcements

  • THIS IS THE TEST SITE OF EUROBRICKS!

×
×
  • Create New...