Tags:
create new tag
view all tags

L'exemple Boot

Je préfère ne pas installer ce programme dans le flash.

MicroPython installe déjà une version de boot.py (seulement des commentaires, mais qui montrent comment on peut mettre en route WEB REPL) et je ne veux pas détruire cette version.

On peut part contre l’essayer avec thonny.

Avant de le faire nous allons créer un classeur /lib dans le système de fichier du ESP32. Dans ce classeur on peut mettre des scripts à importer ou à exécuter.

Avec le HelloWorld.py transféré dans /lib de l'ESP32 on peut l’exécuter avec un « import » :

esp32_fs.png

Le système de fichier sur l'ESP32 avec le classeur "/lib" et HelloWorld.py copié dedans.

helloImport.png

Si maintenant j’exécute le programme boot.py dans 00.1_Boot de Freenove, voila le résultat :

booterr.png

J’ai réécrit le programme boot.py. Dans ma version, je regarde si les fichiers sont des classeurs ou des fichiers standard et j’imprime le contenu seulement pour les fichiers standard.

Voilà ce qu’on obtient si on tourne le nouveau programme boot.py ré-nommé myboot.py :

MicroPython v1.14-121-g4fc2866f4-dirty on 2021-03-21; ESP32 module with ESP32
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT

MicroPython v1.14-121-g4fc2866f4-dirty on 2021-03-21; ESP32 module with ESP32
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
===============================
HelloWorld.py
===============================
Contents:

print('Hello World!\n')
===============================
lib, File is a directory
===============================
===============================
myboot.py
===============================
Contents:
#!/opt/bin/lv_micropython
import uos as os
import uerrno as errno
iter = os.ilistdir()
IS_DIR = 0x4000
IS_REGULAR = 0x8000

while True:
    try:
        entry = next(iter)
        filename = entry[0]
        file_type = entry[1]
        if filename == 'boot.py':
            continue
        else:
            print("===============================")
            print(filename,end="")
            if file_type == IS_DIR:
                print(", File is a directory")
                print("===============================")
            else:
                print("\n===============================")
                print("Contents:")
                with open(filename) as f:
                    for line in enumerate(f):
                        print("{}".format(line[1]),end="")
                print("")
                # exec(open(filename).read(),globals())
    except StopIteration:
        break

>>> 

On trouve le programme myboot.py sur https://github.com/uraich/mpy_ucad/tree/main/Alternate_Python_Codes/00.1_Boot

-- Uli Raich - 2021-07-03

Comments

Topic attachments
ISorted ascending Attachment History Action Size Date Who Comment
PNGpng booterr.png r1 manage 23.3 K 2021-07-03 - 10:25 UliRaich  
PNGpng esp32_fs.png r1 manage 7.4 K 2021-07-03 - 12:06 UliRaich  
PNGpng helloImport.png r1 manage 12.2 K 2021-07-03 - 12:06 UliRaich  
PNGpng lib.png r1 manage 31.6 K 2021-07-03 - 10:25 UliRaich  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2021-07-03 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback