You want to enter the microcontroller world but don’t know how to write code. Don’t worry MicroPython is here to program microcontroller boards in a much easier way than conventional languages. It’s so easy that with a couple of lessons you will be building your very own robot in no time. So, let’s dig deep down into the MicroPython for microcontrollers.
This lesson contains following content:
1: What Is MicroPython
1.1: Python vs MicroPython
1.2: CPython vs MicroPython
2: Where MicroPython is Used?
3: Why Use MicroPython?
4: MicroPython Supported Boards
5: Getting Started with MicroPython
1: What Is MicroPython
MicroPython is an efficient way of implementing Python 3 in microcontrollers. MicroPython is a subset of Python 3 with all standard libraries and written in C. It is a lean and efficient programming language that runs on embedded systems such as microcontrollers.
MicroPython is more stable than other languages used for programming microcontrollers. It is strong enough to scale your project to industrial level as it is packed with full advanced features such as interactive prompt, list comprehension, generators, exceptional handling, and error detection. It is compact enough that it only needs 256kB of space and only 16kB of RAM which is mostly available on most microcontrollers.
You might be wondering why MicroPython has a suffix Python in its name so don’t worry we got you.
1.1: Python vs MicroPython
The main difference between Python and MicroPython is that MicroPython is designed to work under some constraints conditions while it doesn’t fully support Python 3 libraries; it has only support for a small subset of standard Python 3 libraries.
Also, MicroPython allows using standard Python libraries to easily access low level hardware such as controlling GPIO pins. Another difference is MicroPython is used for developing desktop and cloud applications while MicroPython is totally designed for targeting embedded system applications.
1.2: CPython vs MicroPython
CPython is a reference implementation of Python. CPython is the byte code interpreter of Python programming language which is written in C. CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it.
On the other hand, MicroPython is for microcontrollers and embedded system applications. Using MicroPython we can execute instructions on microcontrollers boards such as Node mcu, ESP32, PYboard and many others.
2: Where MicroPython is Used?
Like the Arduino programming language MicroPython can also control devices and microcontrollers. It also supports UART, SPI and I2C communication protocols and devices.
Beside MicroPython wide application it also has some limitations. It is not as fast as other programming languages such as C++. Also, it uses more memory than other languages. And it is not entirely like Python 3 so it doesn’t support extensive Python 3 libraries as it runs on tiny boards with only kilo bytes of memory.
3: Why Use MicroPython?
Despite MicroPython limitations it still has a lot to offer. Here we highlighted some main highlight why one must consider MicroPython for microcontrollers:
- Perfect for beginners
- Fast Feedback (REPL)
- Extensive software library
- Support for C++
Perfect for beginners
MicroPython is best for beginners who want to enter the microcontroller world. Thanks to its simplicity and easy to learn and write any one can start programming MicroPython within a couple of hours or days and not to mention if you already know Python then it will be delightful for you to make a transition to MicroPython with some minimal changes.
Fast Feedback (REPL)
REPL (read evaluate print loop) is a system which allows us to write and execute code without need of compiling. Unlike the C/C++ language where we have to compile and upload the code to test it, here, we can learn MicroPython in a more easy and fast way as it allows rapid feedback.
Extensive software library
MicroPython has an extensive in-built support of libraries that helps to do tasks very easily. For example, parsing data from a web server, searching, or finding expressions and socket network programming can be done with prewritten libraries.
Support for C++
MicroPython can be mixed with low level C/C++ language, and we can get maximum output from both. This can be done by writing a clean MicroPython script for main login while the processing or critical part is written in faster low level C++ language.
4: MicroPython Supported Boards
Do you want hands-on experience with MicroPython? So here is some good news! Following is the list of MicroPython supported boards you can buy:
5: Getting Started with MicroPython
So finally, you have purchased a MicroPython board and want to learn MicroPython. Here are a few resources and links to help you out!
MicroPython Tutorials
- Getting Started MicroPython (Python) with Thonny IDE and ESP32
- I2C LCD with ESP32 using MicroPython and Thonny IDE
- How to Flash MicroPython Firmware on ESP32 Using ESPTOOL
- ESP32 Analog Readings with MicroPython Using Thonny IDE
- How to Install uPyCraft IDE to Program ESP32 using MicroPython
- How to Set an ESP32 Access Point (AP) Using MicroPython
Conclusion
MicroPython is an efficient programming language for microcontrollers. Having a prior experience of Python 3 one can transit into MicroPython very easily. This lesson covers the basic guide to MicroPython and shows us the roadmap to MicroPython advanced programming. Read the given tutorial to get hands-on MicroPython experience.