- Python and MicroPython — Compare and Access
- Languages Overview
- MicroPython Compatible Boards
- Download Links and Browser-Based Online Emulator
- Deep Dive on Differences Between Python and MicroPython
- What is the difference between Python and MicroPython?
- What is Python?
- What is MicroPython?
- Python vs. MicroPython
- Conclusion
Python and MicroPython — Compare and Access
Programming is the implementation of logic to facilitate specified computing operations and functionality. Simply put it is a way to instruct computers to perform various tasks using a programming language. A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. A microprocessor is an integrated circuit that contains all the functions of a central processing unit of a computer which includes an operating system. Both these devices can easily fit on the palm of your hand and encourage in makers rainbows of creativity.
There are several related tutorials on our website and if you’ve got any questions, queries or things to add please let us know your thoughts!
Languages Overview
The syntax of Python presents itself with high human readability. Compared with other programming languages, such as C++ or Assembler, it is easy to learn and faster to write. Furthermore, the total length of code to perform a task tends to be shorter when compared to other programming languages. Programmers can often become preoccupied with minimising the execution time of code however it is worth realising that development time usually takes the longest. Python is growing particularly in the data sciences with large developments occurring in machine learning, physical modelling, geographic information systems (GIS) and computer vision.
Python comes with an extensive standard library and gives a huge number of object types, functions and modules. All of these are available for use without importing any external modules. There is more than hundred-thousand external Python packages available for download and use. A great repository for this is the Python Package Index. No matter what direction the project takes, almost always, you can hit the ground running and program.
MicroPython is a port of Python designed to run on microcontrollers and microprocessors. These are devices that are much smaller, less powerful and significantly cheaper than a desktop computer. A regular version of Python would not be able to run on a microcontroller as it requires too much processing power and RAM energy. To run on these devices Python has to undergo several streamlining changes. This was done by the Australian programmer and physicist Damien George who originally created MicroPython. It is effectively a stand-alone, stripped-down version of Python. As a programming language, MicroPython is very similar to Python and any previous experience translates across very efficiently.
MicroPython contains only a subset of all the standard library modules included with Python. A module is a Python object with arbitrarily named attributes that you can bind and reference. A library is a collection of a whole bunch of these modules. Furthermore, some of the included MicroPython libraries do not have the full set of functions and classes that come with Python. A function is a block of code which only runs when it is called. Classes are essentially a template to determine variables and functions of objects. Objects are simply a collection of data. Python and MicroPython are both object-oriented programming languages. These changes turn MicroPython into an extremely compact programming language. It takes up less than a megabyte of storage space and under load utilizes around 16k of RAM. Learning the programming language of MicroPython will present an immense amount of freedom and power.
MicroPython Compatible Boards
Projects you can do with MicroPython running on small, low-cost boards are unlimited. Want to make a motor spin, light a bouquet of LED lights, create a weather station, receive feedback from a weather-balloon, control a quadcopter, create a micro-satellite, control robots or build a deep-sea submarine? Then MicroPython is the perfect backbone to your venture and the programing language to choose.
Some boards that MicroPython would be excellent for are seen below. This is by no means an exhaustive list.
Download Links and Browser-Based Online Emulator
Both Python and MicroPython programming languages are free to download and use. They are also open-source giving individuals the freedom to modify, contribute and propose improvements. Download locations can be seen below.
There are also online browser-based emulators for both Python and MicroPython. The MicroPython emulator will show command results on a virtual microprocessor. This means you don’t even need to download to test out and run commands using each of these programming languages. The locations to access these emulators are seen below.
Deep Dive on Differences Between Python and MicroPython
Here are the nitty-gritty differences that happens when you turn a powerhouse programming language into one that takes up a fraction of processing power. This will be a high-level comparison of Python and MicroPython programming languages.
MicroPython is intended for constrained environments which have orders of magnitude less performance and memory than a desktop system. This means by design there will be various changes between Python and MicroPython programming languages which are explored below.
— MicroPython does not support the entire Python standard library. If a module is missing it will be due to the poor applicability of that module for use in a small board. If high memory consumption or a lack of a certain required hardware feature, such as multiprocessing, then associated modules were excluded.
— MicroPython is less forgiving in regards to syntax. An example of this is it requires spaces between literal numbers and keywords.
— MicroPython uses garbage collection as the primary means of memory management.
— Metaclasses and complicated Multiple Inheritance won’t work in MicroPython because of a lack of complete object data models. Metaclass in Python is a class of a class that defines how a lower-level class will behave. Multiple Inheritance is a feature that makes all the base class features be inherited into a derived class.
— MicroPython design does not allow descriptor implements. Descriptors are Python objects which give you the ability to create objects that have special behaviour when they’re accessed as attributes of other objects.
— MicroPython implements only a subset of functionality and a subset of parameters of particular functions and classes. If these are required you will need to manually import them.
— MicroPython supports a minimal subset of introspection and reflection features such as object names and docstrings. Introspection is the ability to determine the type of an object at runtime. Reflection refers to the ability for code to be able to examine attributes about objects that might be passed as parameters to a function. A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. A string literal is where you specify the contents of a string in a program. Strings are arrays of bytes representing Unicode characters. Unicode is an international encoding standard for use with different languages and scripts, by which each letter, digit, or symbol is assigned a unique numeric value that applies across different platforms and programs.
— MicroPython does the | print() | function differently. It does not check for recursive data structures in the same way. Checks are done so printing recursive data structure will not lead to stack overflow. A stack overflow is an undesirable condition in which a particular computer program tries to use more memory space than is available causing crashes.
— MicroPython optimizes local variable handling. It does this by not recording or providing introspection information. In programming, introspection is the ability to find out information about an object at runtime.
Compared to a desktop computer a microprocessor or microcontroller can be viewed as a constrained system. Some features of Python do not cater well for constrained systems and/or are not easy to implement efficiently or at all. Therefore there are differences between Python and MicroPython programming languages that have to do with implementation which can be seen below.
— MicroPython has only some Unicode Support.
— In MicroPython Object finalisation is not supported for user-created Classes.
— Subclassing of Built-in Types is partly implemented on MicroPython. Principal Built-in Types are numerics, sequences, mappings, classes , instances and exceptions . Others Built-in Types are used during program execution and are of little practical use to most programmers.
— Buffered I/O streams are not supported in MicroPython. Using this technique you can minimise the number of system calls and can block-align I/O operations, which may improve the performance of your application. I/O operations (also referred to as input/output operations) is the communication between an information processing system, such as a computer, and the outside world.
— The | async def | Function is implemented with simplifications into MicroPython. This keyword introduces either a native coroutine or an asynchronous generator. A coroutine is a specialized version of a Python generator function. Generator functions allow you to declare a function that behaves like an iterator. An iterator is an object that can be iterated upon which means that you can traverse through all the values. An example of this would be a For loop. Asynchronous programming or operation is a type of parallel programming in which a unit of work can run separately from the primary application code.
— There’s no support for Future- esque Objects in MicroPython. A Future Object is a special low-level awaitable object that represents an eventual result of an asynchronous operation. An object is an awaitable object if it can be used in an asynchronous operation. There are three main types of awaitable objects which are coroutines, Tasks, and Futures.
— In MicroPython the | __dict__ | keyword is read-only and either disabled or optional. This keyword is referred to as the dictionary and contains all the attributes which describe the object in question. It can also be used to alter or read the attributes.
Have a question? Ask the Author of this guide today!
What is the difference between Python and MicroPython?
Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2023 with this popular free course.
What is Python?
Python is a high-level, interpreted, general-purpose, object-oriented programming language. It is used to build websites and software applications, automate tasks, machine learning, and artificial intelligenc. It is also used to conduct data analysis.
What is MicroPython?
MicroPython is a version of Python programming language that is written in C and optimized to run on small embedded environments such as a microcontroller. It is the implementation of the Python 3 language that can work effectively on less expensive embedded development boards.
Python vs. MicroPython
MicroPython
Python is an object-oriented programming language, and it contains modules of a standard library.
MicroPython is also an object-oriented programming language, but it contains only a subset of all the standard library modules in Python.
It is used for developing desktop and cloud applications.
It is used for developing embedded applications.
It uses a lot of space on the hard disk and uses more memory.
It takes up less space on the hard disk and uses less memory.
Python is designed to run on larger and more powerful processors such as a desktop or a laptop computer.
MicroPython is designed to run on smaller, cheaper, and low power microcontrollers such as PyBoards, Raspberry Pi Boards, and Arduino Boards.
Conclusion
It is safe to say that Python and MicroPython are both similar as programming languages, but they contrast as they are different in their syntax. MicroPython is used in more constrained environments with lesser power, such as a microcontroller, while Python is used in larger environments, such as the desktop.
Learn in-demand tech skills in half the time