Boot.py and main.py mystery

I have played Ardupy for the whole day. Now, I realized that the main.py cannot start itself after boot, which is said in the documentation of MicroPython. I have tried to add boot.py, whose content is simply import main, but it does not run main.py after booting as expected. How could I make main.py run after booting, or triggered by a button press?

1 Like

Sorry, Iā€™m late to the party :wink:

Try this:
main.py

from machine import LCD

class Myclass:
    def main(self):
        lcd = LCD()                            # Initialize LCD and turn the backlight
        lcd.fillScreen(lcd.color.BLACK)        # Fill the LCD screen with color black
        lcd.setTextSize(2)                     # Setting font size to 2
        lcd.setTextColor(lcd.color.GREEN)      # Setting test color to Green
        lcd.drawString("Another test", 10, 5)   # Printing Hello World at (0, 0)

if __name__ == "__main__":
    myclass = Myclass()
    myclass.main()

boot.py

from main import Myclass

myclass = Myclass()
myclass.main()
2 Likes