Run Script Automatically when First Turned On



  • I would ideally like to load a bare metal MicroPython firmware with the M5stack libraries tagged on - but since the latter bit of code is not forthcoming (:( I have resorted to using the standard UIFlow 1.6.6 firmware and:

    1. Connect M5SticKC to computer via USB
    2. Turn the Stick on
    3. Start Thonny
    4. Stop/Restart the Stick via Thonny Ctrl-F2
    5. Open my.py file with Thonny
    6. Run my.py via Thonny F5

    Except that what I would really like to do is just turn on the Stick and have it run my.py automatically, independently of Thonny or any computers. How can I do that?

    You'd think someone else would have had a similar question but I have searched far and wide for variations on the title of this post to no avail.

    Thanks,
    Jack



  • Upload the file to the device. While turning the device on hold the A Button (the one with "M5". This opens a special menu. Click the other button to go to app list. There you can choose your file. The file you chose should now start every time you turn the device on.

    If you want to change this again, you can do this in setup in the same menu.



  • Excellent, I will try that, thank you very much.



  • OK it works. So for future reference this is what I did:

    • Turn on the unit (mine is an M5StickC with UIFlow 1.6.6 firmware)
    • press the M5 button quickly after that to enter setup mode (my screen shows <code>)
    • side button to get the Setup menu
    • M5 again to select it
    • Switch Mode
    • M5 again
    • side button to select APP
    • side button to select '..' at top
    • M5 to go back to previous menu
    • side button to select Reboot
    • M5 to reboot

    From now on whenever you turn it on the Stick will run boot.py and then main.py in the /flash directory.

    If when it's so running you attach the device to a computer via the USB cable, you can interrupt whatever it is doing by starting Thonny and hitting ctrl-F2 (Stop/Restart Backend), which will bring up the MicroPython REPL prompt. Cool.