After uploading the MicroPython firmware on ESP8266, we can use it run MicroPython scripts.
We can execute the python scripts directly in the interpreter.
The NyBoard WiFi module ESP8266 uses the IO2 pin to connect with a red LED to indicate the connection status. This LED is programmable. Write a simple python blink script:
Press the green start button on the toolbar, and the script will be sent to the WiFi module through the serial port, and then run after being interpreted by the built-in MicroPython interpreter of ESP8266. Because the Blink script is an endless loop when it needs to stop, press the red stop button to end the program interruption and reset.
We can click View -> File to open the file toolbar, and the file is displayed on the left side of Thonny. The upper part is the directory of the local machine, and the lower part is the files stored in the MicroPython device. By default, there is only one boot.py file, please do not delete this file, it is the startup file of the MicroPython device.
We save the script as blink.py and save it on the machine, right-click on the file and select Upload to /
:
Select the MicroPython device
in the pop-up window:
There is a blink.py
file on the device. So the file is saved on the device.
ESP8266 can send commands to NyBoard through the serial port. We only need to write a simple serial port sending script to send a series of serial port commands to NyBoard, and then the robot can execute sequence actions.
When the actSeq() function is executed, It can output a series of commands through the serial port. Using the serial monitor we can debug. Use the serial port monitor to monitor the output as follows (for the convenience of reading, please use the automatic frame break of the serial port debugger, in fact, there is no automatic line break).
After we debug the sequence action, unplug the ESP8266 and plug it into the NyBoard, the robot dog does not respond because the actSeq()
function is not running. We want to run the scripts automatically after power on. There are two methods:
Please change the file name to "main.py
" and save to the device (Recommend)
Modify the Boot.py