What is Micropython????
Tags: micropython, python, esp8266, esp32
Published: 2021-01-15 18:09:30

 

  Finding how to task my python skills with hardware has not been easy, because I had only microcontrollers. The issue with using a microcontroller to run python is its limited memory to run  python, the only viable option was to get a raspberry pi, but the cost of getting a computer like raspberry pi was way out of my league, but luckily for me, I heard a guy named **Damien George** created a new version of python that can run on very little memory and is great for microcontrollers.

######Why Micropython?
  *  Easy to learn: Python,itself is an easy language to learn, so micropython will not be an exception. Compared to the conventional c++ used for microcontrollers, micropython is easier to write. For example to toggle an led in C++ Arduino ,the code should look something like this
```
const int LED_PIN=2;
const int BUTTON_PIN;
int ledState=HIGH;
void setup(){
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN,INPUT_PULLUP);
digitalWrite(LED_PIN,LOW);
}

void loop(){
ledState=digitalRead(BUTTON_PIN);

if(digitalRead(BUTTON_PIN)==1){
// if button was pressed
digitalWrite(LED_PIN,!ledState);
delay(500); // wait for half a sec
}
}
 ```  
But for micropython it is a simple as this
```
// this example is for a pyboard
import pyb
button = pyb.Switch()

while true:
      sw.callback(lambda:pyb.LED(1).toggle())
```
Yes it that simple

Also when it comes to quoting long strings micro python is way easier.
let assume this is our text

*hjdbkhfknbjkHBKDVDdkdbkbdkbkjkjBJBKDBjkbdkhdbKDBJDBJKFBJDBkjbdkbfjkbJKBJKBbkbfkBFJKBDJBJdbbdjbnLUkegkdbfkbKD,N kdkdkjd KHDHDVNM hhJHbkeBK VDJKvj dljkdbjbbJbhdkavKBFKAdhbkjbfuhfKJBFJBfkBJKDBKbkjkbjBHBDKdhkndjagdfkjadhdbfkhjbdkhfvhvakhbidghfbkbadbjbafhjbvhvhfbkhabahdgyetkfrhfiabfhfkjksbkjf*


To quote this in C++ i will have to quote each line, like this
```
"hjdbkhfknbjkHBKDVDdkdbkbdkbkjkjBJBKDBjkbdkhdbKDB"
"JDBJKFBJDBkjbdkbfjkbJKBJKBbkbfkBFJKBDJBJdbbdjbnL"
"UkegkdbfkbKD,N kdkdkjd KHDHDVNM hJH bkBK VDJKvj" 
"dljkdbjbbJbhdkavKBFKAdhbkjbfuhfKJBFJBfkBJKDBKbkj"
"kbjBHBDKdhkndjagdfkjadhdbfkhjbdkhfvhvakhbidghfbk"
"badbjbafhjbvhvhfbkhabahdgyetkfrhfiabfhfkjksbkjf"
 ```
But for micropython i just have to "triple quote"
```
"""hjdbkhfknbjkHBKDVDdkdbkbdkbkjkjBJBKDBjkbdkhdbKD
BJDBJKFBJDBkjbdkbfjkbJKBJKBbkbfkBFJKBDJBJdbbdjbnLU
kegkdbfkbKD,N kdkdkjd KHDHDVNM hhJHbkeBK VDJKvj        dljkdbjbbJbhdkavKBFKAdhbkjbfuhfKJBFJBfkBJKDBKbkjkb   jBHBDKdhkndjagdfkjadhdbfkhjbdkhfvhvakhbidghfbkbadb     
 jbafhjbvhvhfbkhabahdgyetkfrhfiabfhfkjksbkjf"""
```
  if you are interested in learning micropython, you can visit [micropython.org](https://micropython.org) there are documentations for the most common micro python boards. The most common and cheapest boards that can handle micropython in Nigeria are the  ESP8266 12E and ESP32 boards. 
To learn more about ESP8266 with micro-python click [here](https://docs.micropython.org/en/latest/esp8266/tutorial/intro.html)

To learn more about ESP32 with micro-python click [here](https://docs.micropython.org/en/latest/esp32/tutorial/intro.html)

Note: Although micro-python is very easy to write, I would not recommend in for beginners because it is still a new language and doesn't have a lot of resources to help beginners unlike arduino that has been around for a long time, beginner friendly and has unlimited resources to help both pro's and beginners. In arduino there is a library for almost anything you can think of. so for newbies in the embedded system world I would advice you start with arduino.

   If you are a Nigerian and you are interested with learning micropython you can buy the ESP8266 board [here](https://wa.me/p/3998717593578631/2349047076406)
or the ESP32 [here](https://wa.me/p/3632806690107149/2349047076406)

Thanks for reading.