• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

MicroPython Questions

Q&A Forum › Category: ESP32 › MicroPython Questions
0 Vote Up Vote Down
Brad Fayette asked 3 years ago

Greetings:

I am taking the Micropython eBook and I have some basic questions:

  • Are main.py and boot.py magic filenames?  Do you always need both? If so, what is the intended division of labor here?
  • The code in the labs often has the I/O pin instantiation in boot.py, but doing it this way I found that it is not in main.py’s scope.  When I move it to main.py then everything works.  This is confusing because you import socket in boot.py and that seems to be visible in main.py.  So, what am I doing wrong here?
  • Does Micropython tokenize or otherwise preprocess programs, or are  they saved in the target as text? Do comments really burn target memory?
  • Is there a memory map that details what gets stored where on the target?  Also,are there any details on the boot sequence in the ESP target?  I probably do not need to know these things, but just for my own comfort I like to have a handle on them.

That is probably enough for now.  Thanks!

Brad Fayette

1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi Brad.

1. Yes. main.py and boot.py are like magic filenames. When you flash a board with Micropython firmware, it automatically creates a file called boot.py.

Then, you can upload a file called main.py.

boot.py: Runs when the device starts and sets up various configuration options.
main.py: The main script that contains your code and is executed immediately after the boot.py file.

You don’t necessarily need to create both files. You can put all your code in main.py and it will run ok.

You can also upload other files with functions to be called on the main.py file.

2. Answering your second question. That may be happening because you’re not uploading the files to the board. You’re just running the files. Running the files, doesn’t upload them to the board. So, when you run the main.py file, it won’t find the initializations made in the boot.py file. Which IDE are you using? You can check the files that are uploaded in your board and their content.

3. MicroPython is like Python – it is a scripting language. So, your code is not compiled – any comments that you write, will be saved in memory. That’s why you should avoid writing a lot of comments.

4. I don’t think so. MicroPython is responsible for taking care of memory management.

Let me know if I answered all the questions and if my answers are clear.

Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.