board.py Files

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
quiltyja
Posts: 7
Joined: Sun Jul 10, 2022 12:10 pm

board.py Files

Post by quiltyja » Fri Jul 29, 2022 5:57 am

Edit: correct typo in subject and body, board.py is the file I'm enquiring about!

Hi everyone,

I connect with rshell to an ESP32 and rshell looks for via the function below which, because my code doesn't contain a file 'board.py' and thus always defaults to "pyboard". I can change that in a simple-minded kind of way by creating a 'board.py' file, but I'd prefer to adopt any standard or convention for 'board.py' if one exists. It turns out that ''board.py' and 'import board' make really poor search terms, so I'd like to ask if anyone knows where this file is found in the MicroPython ecosystem and whether there's a standard or convention for its contents?

Code: Select all

def board_name(default):
    """Returns the boards name (if available)."""
    try:
        import board
        try:
            name = board.name
        except AttributeError:
            # There was a board.py file, but it didn't have an name attribute
            # We also ignore this as an error
            name = default
      ...
      return repr(name)
Last edited by quiltyja on Fri Jul 29, 2022 6:08 am, edited 1 time in total.

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: boot.py Files

Post by davef » Fri Jul 29, 2022 6:04 am

For the ESP32 I always have the boot.py that comes with the image. So, a blank boot.py should be enough. Also, I find it useful to have a file called main.py, which at least contains:

Code: Select all

import my_application
A short delay in main.py, ie

Code: Select all

utime.sleep(5)
gives you a chance to do a CTRL-C in rshell and edit stuff.

quiltyja
Posts: 7
Joined: Sun Jul 10, 2022 12:10 pm

Re: board.py Files

Post by quiltyja » Fri Jul 29, 2022 6:11 am

Thanks, davef, for the quick reply! I'm sorry to say that I was interrupted while writing a question about board.py and when I returned to complete the post I'd just been working on boot.py... and thus made a typo in the subject and body :oops:. I've corrected that now and the subject and body both consistently refer to board.py.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: board.py Files

Post by dhylands » Sat Jul 30, 2022 3:24 am

The documentation for rshell is here: https://github.com/dhylands/rshell and the specific stuff about board.py is here: https://github.com/dhylands/rshell#file-system

quiltyja
Posts: 7
Joined: Sun Jul 10, 2022 12:10 pm

Re: board.py Files

Post by quiltyja » Sat Jul 30, 2022 4:26 am

Thanks for the refs to the docs dhylands, I very much appreciate your writing rshell it's been very useful! What I'd like to know particularly is whether there's a convention, however loose, for the content of 'board.py' files?

For example, the Adafrult Blinka uses a board.py file, which makes me think that there's somewhat of a convention regarding 'board.py' files... ?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: board.py Files

Post by dhylands » Sat Jul 30, 2022 2:39 pm

I'm not aware of any convention per-say. When I create them they just look something like this:

Code: Select all

name = 'custom'
I'm also not familiar with whats in Adafruit's board.py file.

Post Reply