Skip to content

Mixing micropython projects #170

Answered by BrianPugh
kc64 asked this question in Q&A
Sep 24, 2024 · 2 comments · 6 replies
Discussion options

You must be logged in to vote

Here's another solution that might work without writing to the microcontroller's filesystem:

from belay import Device
from pathlib import Path

class MyDevice(Device):
    def __pre_autoinit__(self):
        micropython_code = Path("micropython-code.py").read_text()
        self(micropython_code)  # Executes the contents of "micropython-code.py" on device in a global context.
        
    @Device.task
    def read(self):
        return my_instantiated_pio_thing.get_some_value()

A similar technique is used internally (see the private Device._exec_snippet method) to send over functions and other startup code for belay.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@BrianPugh
Comment options

@BrianPugh
Comment options

@kc64
Comment options

@BrianPugh
Comment options

Answer selected by BrianPugh
Comment options

You must be logged in to vote
1 reply
@BrianPugh
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants