Python for NodeMCU / ESP8266
Buy NodeMCU From Aliexpress
It also includes a small subset of the Python standard library and
MicroPython is packed full of advanced features such as an interactive prompt, arbitrary precision integer, closures, list comprehension, generators, exception handling and more. Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM.
In the config, tab pastes the location of the downloaded firmware file (i.e file location of .bin file).
In Advanced tab set baud rate to 115200.
Finally, in Operation Tab Select the port and Flash.
Two ways to access REPL
And set the baud rate to “115200” and line ending to "Both NL & CR"
Just like Python
Want to program ESP8266 in glorious python language.
Intro
MicroPython is an implementation of Python 3 programming language Optimised to run on microcontrollers and in constrained environments.It also includes a small subset of the Python standard library and
MicroPython is packed full of advanced features such as an interactive prompt, arbitrary precision integer, closures, list comprehension, generators, exception handling and more. Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM.
MicroPython on ESP8266 Boards
Step 1: Download Firmware
Download MicroPython for ESP8266 board https://micropython.org/downloadStep 2: Download NodeMCU flasher
https://github.com/nodemcu/nodemcu-flasherStep 3: Flashing Firmware
Open NodeMCU flasher located in folder "downloaded zip\Win64\Release\ESP8266Flasher.exe"In the config, tab pastes the location of the downloaded firmware file (i.e file location of .bin file).
In Advanced tab set baud rate to 115200.
Finally, in Operation Tab Select the port and Flash.
Programming
MicroPython REPL prompt
REPL stands for reading Evaluate Print Loop. It is an Interactive MicroPython prompt that you can access on the ESP8266.Two ways to access REPL
- wired connection through the UART serial port
- via WiFi
And set the baud rate to “115200” and line ending to "Both NL & CR"
Using REPL
Remember type this is Serial MonitorJust like Python
>>> print('hello esp8266!')
hello esp8266!
>>> 1 + 2
3
>>> 1 / 2
0.5
>>> 12**34
4922235242952026704037113243122008064
To make a pin output# GPIO 2 is internal LED Pin on NodeMCU
pin = machine.Pin(2, machine.Pin.OUT)
# Set its value by
pin.value(0)
pin.value(1)
# OR
pin.off()
pin.on()
No comments