Skip to content

LOLIN D1 MINI PRO Introduction tutorials for Windows

Lolin1

File system and uploading files

Summary

This is a simple tutorial of how through the micro python terminal we can create, write and read files from our board. Also the board has the ability to store files in internal storage since this tutorial. Is all about creating, writing and reading. Also within this tutorial we will upload a file using a network directly to our board.

Requirements

  • 1 x LOLIN D1 MINI PRO board
  • 1 x Micro USB

File system

Connect your board to your computer

This step should be easy if you completed the first tutorial.

  • Connect the one end of your micro usb on your board and the other end to your computer.

  • Open PuTTY and select Serial connection type.

  • Use the appropriate Serial Line COM5 (same you did on Tutorial 1, if you don't remember it you can find it through device manager) and speed 115200 and click open.

Ports

Putty

Input commands

Now you should be looking at the PuTTY terminal. First thing we must do, is check the list of files stored in the storage

  • Use the following command to check the list of files in the storage of the board

    1
    2
    import os
    print (os.listdir())
    
  • At this stage we should be able to see something like “[‘boot.py’]”, which is one of the special files executed when the board starts.

  • You can create, write and read from files as you would with normal Python. Using the code below create a new file called “myfile.txt” and type the text “Hello World” in it (also last line prints the list of files to show you that the file was created):

    1
    2
    3
    with open("myfile.txt", "w") as f:
            f.write("Hello worl")
    print(os.listdir())
    
  • The following code now opens our existing file and prints on the command line its contents.

    1
    2
    3
    with open("myfile.txt", "r") as f:
    
        print(f.read())
    

NOTE: If you are doing copy & paste you must use the mouse right click to paste the code. I would suggest typing the code by yourself to avoid any issues and for better practice.

Uploading files

NOTE: Download WebREPL pack from GitHub and unpack.

You can use the WebREPL to upload files to the board from your computer.

  • Get the file from GitHub

  • Unpack it somewhere on your computer.

  • Open webrepl.html with your browser.

If you haven’t done the Wi-Fi tutorial please go through it now in order to connect your device to the network.

From this point we need to connect the device with the Repl. In order to do that we need to run the following command:

1
2
3
    import webrepl

    webrepl.start()

Now you can go back to the browser and click "connect". On the first connection you will be asked to setup a password - later you will use that password to connect to your board.

Webrepl1

Webrepl2

Webrepl3

Webrepl4

Now we are successfully connected to the board and using the Repl we can send or get a file to and from it. In order to get a file from the board click on the choose file button and select the file you want to send. If you want to get a file from the board, type the files name and then click get from device in order to choose where to save it.

Run the following command to check if the file/files you added have successfully transferred to our board:

1
2
3
    import os

    print(os.listdir())

This is the end of Tutorial 5 for LOLIN D1 Mini Pro, now you should be able to upload and fetch files through webrepl.