Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to save programs on Technic Hub #1664

Closed
eadunes opened this issue Jun 5, 2024 · 16 comments
Closed

How to save programs on Technic Hub #1664

eadunes opened this issue Jun 5, 2024 · 16 comments
Labels
support Request for technical support for a problem that is not a bug or feature request

Comments

@eadunes
Copy link

eadunes commented Jun 5, 2024

Describe the bug
when I have flashed the code to the hub and try to start the program it stays on blue blinking. wether I switch it of before or not. but when I connect the hub the the pc/mac and start the code via website, then stop and disconnect, I can start the program from the hub. this only happens 1 time after flashing the code to the hub. tried also a 2nd hub. same behavior What is the problem?

To reproduce
see above

Expected behavior
The program should be able to run directly after flash.

Screenshots
There is a saying that a picture is worth a 1000 words. Screenshots really help to identify and solve problems.

@eadunes eadunes added the triage Issues that have not been triaged yet label Jun 5, 2024
@laurensvalk
Copy link
Member

Can you share the program you are trying to run?

Perhaps you can start with a simple program that just turns the light on for a few seconds.

Then you'll know that saving works properly.

@eadunes
Copy link
Author

eadunes commented Jun 5, 2024

from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Color, Port, Direction
from pybricks.tools import wait

# Initialize motor for loader
Loader = Motor(Port.A, Direction.CLOCKWISE)
Loader.run_until_stalled(-400, duty_limit=50)
Loader.reset_angle(0)

# Initialize and run motor for conveyor belt
Conveyor = Motor(Port.B, Direction.CLOCKWISE)
Conveyor.run(1250)

# Initialize the hub
hub = TechnicHub(observe_channels=[42])

while True:
    data = hub.ble.observe(42)

    if data is False:
        hub.light.on(Color.ORANGE)
        Loader.run_target(400, 0, wait=False)
    
    if data is True:
        hub.light.on(Color.GREEN)
        Loader.run_target(400, 210, wait=False)
        wait(4000)
    if data is None:
        hub.light.on(Color.RED)
    wait(100)

@laurensvalk
Copy link
Member

What did you mean by flash? Did you run it with the run (▶) button? Did you get any errors in the output window at the bottom when you ran it?

@eadunes
Copy link
Author

eadunes commented Jun 5, 2024

flash = permantly store the program on the hub.

Its necessary the run the code, connect to the PC/Mac, with the play button after it is stored on the hub 1st, otherwise it will not possible to start the program stored on the hub by just pressing the green button.

@laurensvalk
Copy link
Member

Ah, that's not necessary. After you run it with the play button, you can just start it again with the green button on the hub.

No need to re-flash. In fact, that removes your program.

I suppose you may be referring to the video from racing brick - two years ago the steps you described were still necessary, but we've made it a lot easier since then 😄

@eadunes
Copy link
Author

eadunes commented Jun 5, 2024

no no, U misunderstood me.

I write code, store it to the hub. then connect the motors. it wont run the program unless I have run the code one time via the website.

@laurensvalk
Copy link
Member

Can you try it with a simple program that just turns the light on?

For example, copy paste the example from here into a new program:

https://docs.pybricks.com/en/stable/hubs/technichub.html#turning-the-light-on-and-off

That should make it easy to see if saving it on the hub worked or not.

@Debenben
Copy link
Sponsor

Debenben commented Jun 5, 2024

@eadunes If I understand you correctly, you would like to only flash your program to the hub and prevent it from running immediately afterwards.

The step you describe as flashing your program is probably only flashing pybricks "operating system", it no longer flashes any user-program. You only have to do this step once. Your program is then uploaded to the hub when you press the play button on the website and saved permanently when you shutdown the hub.

A solution might be to prevent your program from running properly by disconnecting the motor on port A or waiting for another button press at the start of your program. In case that is inconvenient in your build, you could use the pybricksdev command line tool for uploading. As far as I know you cannot only upload using the website (other than hacking its source code with a custom script).

@eadunes
Copy link
Author

eadunes commented Jun 6, 2024

@Debenben

No. I have to start it once via the website so that I can then start later from the hub. Before that, it cannot be started via the hub.

@laurensvalk
Copy link
Member

Have you tried the suggestion with the program that just blinks the light?

@eadunes
Copy link
Author

eadunes commented Jun 6, 2024

Have you tried the suggestion with the program that just blinks the light?

not yet. will do it later.

@eadunes
Copy link
Author

eadunes commented Jun 6, 2024

https://docs.pybricks.com/en/stable/hubs/technichub.html#turning-the-light-on-and-off

did run your suggested code. exact same behavior.

after saving the program to the hub its not possible to run the program by pressing the green button.
switching the hub off and on again and try the run the program worked either.
connecting the hub to the pc and run the program works.
after disconnecting the hub from pc again its possible to run the program by pressing the green button of the hub.

tried it with two technic hubs.

@laurensvalk
Copy link
Member

Thanks for your response.

after saving the program to the hub its not possible to run the program by pressing the green button

So running it worked and then starting again with the button did not work?

after disconnecting the hub from pc again its possible to run the program by pressing the green button of the hub.

So running it worked and starting with the button did work this time?


I guess I still can't completely follow. Can you describe the difference between these two cases a above?

These are normally the same thing. Did it work once but not the second time?

Or did you mean it is only lost after you reboot the hub? Did you shut it down normally by holding the green button for about 3 seconds until it is off?

I don't seem to be able to reproduce this issue on my Technic hub, so I'm trying to figure out what the difference is :slight_smile:

@eadunes
Copy link
Author

eadunes commented Jun 8, 2024

Hi

this isnt an issue anymore. it's me not knowing that saving the code to the hub procedure change and its not necessary anymore to bootload the hub to save the code inside firmware.

sorry for this.

Daniel

@laurensvalk
Copy link
Member

No worries - Glad it worked!

I hope you'll like this easier method 😄

@laurensvalk
Copy link
Member

Closed as resolved.

@laurensvalk laurensvalk changed the title Technic hub wont run the program right after flash[Bug] How to save programs on Technic Hub Jul 26, 2024
@laurensvalk laurensvalk added support Request for technical support for a problem that is not a bug or feature request and removed triage Issues that have not been triaged yet labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Request for technical support for a problem that is not a bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants