Using MicroPython is a great way to get the most of your MicroPython ESP8266 D1 MINI board. And vice versa, the MicroPython ESP8266 D1 MINI is a great platform for using MicroPython. With this board you can learn up MicroPython, getting a prompt, using WebREPL, connecting to the network and communicating with the Internet, using the hardware peripherals, and controlling some external components.
The MicroPython ESP8266 D1 MINI connects to your PC over USB, giving you a USB flash drive on which to save your Python scripts. MicroPython ESP8266 D1 MINI is equipped with a micro USB connector for power and serial communications, 12 GPIO, LED, and reset button.
MicroPython is a complete rewrite of the Python (version 3.4) programming language so that it fits and runs on a microcontroller. It includes many optimizations so that it runs efficiently and uses very little RAM. Additionally, MicroPython runs bare-metal on the board and essentially gives you a Python operating system. The built-in MicroPython ESP8266 D1 MINI module contains functions and classes to control the peripherals available on the board, such as UART, I2C, SPI, ADC.
For additional thinks, you can to add to order, a USB cable and breadboard.
Microsoft MakeCode is a free, open-source platform for creating engaging computer science learning experiences that support a progression path into real-world programming.
Connect your MicroPython ESP8266 D1 MINI to your PC (Windows, Mac or Linux) with a micro USB cable. There is only one way that the cable will connect, so you can’t get it wrong.
Your PC should now recognize the board. It depends on the type of PC you have as to what happens next:
Okay, so you should now have the board connected as a USB flash drive, and a window (or command line) should be showing the files on the MicroPython ESP8266 D1 MINI drive.
The drive you are looking at is known as /flash by the board, and should contain the following 4 files:
main.pyfile in a text editor. On Windows, you can use notepad or any other editor. On Mac and Linux, use your favorite text editor. With the file open you will see it contains 1 line:
# main.py -- put your code here!
This line starts with a # character, which means that it is a comment. Such lines will not do anything and are there for you to write notes about your program.
Let’s add 2 lines to this
main.py file, to make it look like this:
# main.py -- put your code here! import pyb pyb.LED(4).on()
The first line we wrote says that we want to use the module. This module contains all the functions and classes to control the features of the MicroPython ESP8266 D1 MINI.
The second line that we wrote turns the blue LED on: it first gets the
LED class from the
pyb module creates LED number 4 (the blue LED) and then turns it on.
To run this little script, you need to first save and close the main.py file, and then eject (or unmount) the board USB drive. Do this like you would a normal USB flash drive.
When the drive is safely ejected/unmounted you can get to the fun part: press the RST switch on the board to reset and run your script. The RST switch is the small black button just below the USB connector on the board, on the right edge.
When you press RST the green LED will flash quickly, and then the blue LED should turn on and stay on.
Congratulations! You have written and run your very first MicroPython program!