How to Get Started with MicroPython for ESP8266 Microcontrollers

How to Get Started with MicroPython for ESP8266 Microcontrollers

For anyone interested in using cheap, Wi-Fi-connected microcontrollers like the ESP8266, the Arduino programming language can be a barrier to entry. Based on C++, Arduino requires knowledge of more computer science than languages like Python. Fortunately for beginners, setting up MicroPython on an ESP8266 allows anyone to write Python on affordable microcontrollers in a matter of minutes.


Cheap Prices Come with a Learning Curve


One of the first languages many people learn for programming electronics is Arduino, which requires knowledge of the specific structure needed to make a sketch work. Because of the way microcontrollers run code, even a simple Arduino sketch will typically consist of two functions: setup and loop.


To write a sketch that blinks an LED attached to pin D1 (also called GPIO pin 5), we can use the following sketch in Arduino to set the LED to output, turn it on for a second, and then turn it off for a second.


void setup() { pinMode(D4, OUTPUT);
}
void loop() { digitalWrite(D4, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for one second digitalWrite(D4, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for another second
}

For this seemingly simple action, we have a lot of code that seems pretty unintuitive for a beginner to understand. What's happening in this program is that the setup function runs once, turning our D4 pin to output mode, and then the loop runs continuously to turn on and off the LED. While this is a simple sketch, MicroPython can make it even easier.


MicroPython to the Rescue


In MicroPython, we can do the same in a ..

Support the originator by clicking the read the rest link below.