Dreamstime_Maciek905_269118891
Code Dreamstime Maciek905 269118891 643d5aab8ed10

What’s the Difference Between Python and MicroPython?

April 17, 2023
The differences between the Python and MicroPython programming languages are minute, but they make a powerful difference.

What you’ll learn:

  • What exactly is Python and what is MicroPython?
  • The major differences between both languages.
  • Some use cases for each.

As difficult as it is to imagine, the Python programming language made its initial release back in the late 1980s as the successor to the ABC general-purpose platform. Interestingly enough, Guido van Rossum, who created Python, stepped down as lead developer in 2018 after almost 30 years when he announced he was going on a permanent vacation.

Guido’s entire career is impressive to say the least. Before creating Python he wrote a glob() routine for BSD Unix and even helped develop the ABC programming language. He also created Grail, an early web browser written in Python, as well as the Mondrian web-based code review system while working at Google. Guido also had stints working at Dropbox and joined the Developer Division at Microsoft, where he earned the title Distinguished Engineer.

For those unfamiliar, Python is a general-purpose programming language that supports multiple programming paradigms, such as structured, object-oriented, and functional programming. Python has become one of the most popular programming languages over the last decade, finding homes in everything from machine-learning applications to building websites. It’s also been used to create Netflix's recommendation algorithm and even within the software that controls autonomous vehicles.

MicroPython, on the other hand, is a lean and efficient use of the Python 3 (aka Python) programming language that's optimized to run on microcontrollers and embedded systems. It’s been used to control hardware and IoT devices. Created by Australian theoretical physicist Damian George, it was released on a successful Kickstarter campaign where it was bundled with a STM32F4-powered development board.

While Damian’s career doesn’t encompass creating programming languages, it’s no less impressive as he’s co-authored over 20 papers in the theoretical physics field and gave numerous presentations at academic institutions around Australia. That said, this article will discuss the differences between the two programming languages and their notable features.

Syntax Differences

Python was designed to be easy to use and takes advantage of English keywords rather than punctuation (Fig. 1). That said, it doesn't use curly brackets to delimit blocks, although semi-colons after statements are allowed but rarely utilized. The syntax itself makes employs whitespace to indicate blocks of code, making it easy for programmers to write clean and organized code for any number of applications.

MicroPython, on the other hand, uses a syntax similar to Python but doesn't have the advantage of the extra features found in its larger cousin. For example, MicroPython can’t access the extensive libraries available to Python, meaning specific programming tasks may be more challenging to accomplish.

MicroPython also requires spaces between literal numbers and keywords, which isn’t the case with Python. For example, in Python, users can forget to place a space between a number and a keyword to form an acceptable expression that won't cause issues. The same mistake in MicroPython will generate syntax errors due to the diminished logic needed to handle typos. This is due to its limited footprint, as it's designed to run on just 256k of space with 16k of RAM.

One of the key differences between the two programming languages is their memory management. While Python leverages garbage management to free up memory that's not being used automatically, MicroPython requires manual management, meaning the user must allocate the memory manually.

Feature Differences

Python comes equipped with a host of features designed to make it easy for engineers to code their projects. To that end, Python is easy to learn with its simple syntax and the use of indentation instead of curly brackets. It's also an interpreted language, meaning the source code is executed line by line, so compiling the code is unnecessary.

It's portable, too, allowing the language to run on different machines. For example, users can create code and execute it on a Mac or Windows system without making compatibility changes. Moreover, Python supports both object-oriented and procedure-oriented programming, can be written in other languages, and is expressive, meaning users only need to write a few lines to perform complex tasks.

On top of that, Python has support for GUIs, making it easy to navigate and interact with the program, and provides several toolkits, such as Tinkter, JPython and wxPython, for efficient and fast development. It also incorporates some advanced features, including generators to create iterators, and list comprehensions to create lists from other iterables. Python has an extensive community as well, including those on StackOverflow and Meetup, that offer myriad libraries and can help provide insights and even code for similar projects.

MicroPython also provides a host of features and is able to take advantage of the same libraries available for Python. In addition, it’s portable and can be used on a variety of microcontrollers with different operating systems (Fig. 2). A unique feature of MicroPython allows users to create new code, freeze it as a module, and use it as a library, which can be part of a developed firmware. This basically enables users to avoid repetitive downloading of the same error-free code in a MicroPython environment.

Moreover, the programming language is equipped with REPL (Read-Eval-Print-Loop), making it possible to enter lines of code that can be immediately read on a terminal. This handy feature lets users test parts of their applications and visually see the results. MicroPython also comes equipped with a set of core libraries that provide some basic functionalities, such as networking, file I/Os, and limited data types.

Performance Prowess

Other differences between the two languages involve performance. Python is generally slower to execute than other languages, including C and C++, although its performance can be increased by utilizing code optimizations. It also depends on the hardware running the language and the code's complexity.

MicroPython wins the performance crown, though, as it's designed to run on limited resources and hardware-constrained devices. That said, both are excellent programming languages and are ideal for their designed purposes. They have a trove of dedicated users that provide insight and helpful resources for both beginner and advanced users alike.

About the Author

Cabe Atwell | Technology Editor, Electronic Design

Cabe is a Technology Editor for Electronic Design. 

Engineer, Machinist, Maker, Writer. A graduate Electrical Engineer actively plying his expertise in the industry and at his company, Gunhead. When not designing/building, he creates a steady torrent of projects and content in the media world. Many of his projects and articles are online at element14 & SolidSmack, industry-focused work at EETimes & EDN, and offbeat articles at Make Magazine. Currently, you can find him hosting webinars and contributing to Electronic Design and Machine Design.

Cabe is an electrical engineer, design consultant and author with 25 years’ experience. His most recent book is “Essential 555 IC: Design, Configure, and Create Clever Circuits

Cabe writes the Engineering on Friday blog on Electronic Design. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!