Translation organized by Python Tribe (python.freelycode.com), reproduction is prohibited, forwarding is welcome.
Author: Stéphane Recouvreur October 14, 2015
When it comes to microcontroller boards, these tiny computers allow us to control most DIY electronics projects like robots, drones, and even web servers by running programs. Choosing the right programming language to work with can be quite challenging. There are many boards out there, each with its own specialties and suitable programming languages. You want the language you choose to be easy to learn and use, yet powerful enough to support larger projects. That’s why at Pirates Electronics, we recommend Python.
A Quick Overview of Different Programming Languages for Microcontrollers
Programming languages come in three different types: low-level, mid-level, and high-level.
Low-level languages are similar to how computers “speak,” running directly on the processor: they are difficult to use (almost unreadable for humans), but can be used under limited memory and are very powerful. They can process many instructions per second. Programming languages like assembly, BASIC, Visual Basic, and C fall into this category.
Then there are mid-level languages: the code is easier to write but still requires some time and practice to master. Java, C#, and C++ are good examples of mid-level programming languages.
Finally, high-level programming languages are more similar to how humans speak, reducing the time required for programming microcontrollers and prototyping, making it faster but with lower performance. Here we refer to JavaScript and Python.
The most famous microcontroller on the market, Arduino, is programmed using C/C++. This is also the programming language most people will recommend you use. C has been in use for quite a long time, being similar to machine language, and is relatively easier to learn compared to any other low-level programming language, and it has good support. It is one of the best solutions for limited resources like microcontrollers.
However, while C is the traditional ‘go-to’ language for microcontrollers, new boards have emerged in the market that allow for a wider selection of programming languages while maintaining high performance standards. Therefore, high-selling boards like Intel Edison, which are based on a Linux environment, support Python (among others), and Python has even become the core language for Raspberry Pi.
Robotix
Easy to Use
Another significant advantage of high-level programming languages like Python is that they are easier for beginners to grasp and facilitate programming for microcontrollers.
Python is simple, with an easy-to-learn syntax that emphasizes readability and reduces the cost of program maintenance. And because it uses everyday words, it’s easy to tell the computer what to do. Let’s compare the same instructions in C and Python (from user input).
C:
Python:
It’s faster and simpler to write, right? Using Python, prototyping on microcontrollers now only takes a few minutes instead of several hours of coding and debugging. If you are short on time or lack the patience to wait, and want results quickly, this is perfect.
An additional benefit: Python does not require compilation, making the process of getting the code to work and debugging much faster.
Better Support and Community
How can you ensure a programming language will thrive and be supported in the years to come? Look at its community; envision that back in the 1980s, its popularity has been rising for decades. Since 2003, Python has consistently ranked among the top ten most popular languages and has a huge community supporting it.
Python is also used by some major internet companies (Google, Yahoo, Reddit, Dropbox, etc.) and space agencies (NASA). And for good reason: it’s reliable, flexible, and powerful. As senior project engineer Friedrich says: we can implement code that runs directly in Python much faster than in other languages, which is amazing. Take Java and C for example; they come with more baggage you need to understand, sometimes just to achieve a small piece of functionality for software. When it comes to code maintainability, Python also excels. There isn’t much documentation, making it hard to grasp what Java and C programs are doing, even though Perl has a lot of documentation, it is poorly readable and hard to maintain.
Python has even entered the field of artificial intelligence; if you want to create a robot like the Terminator, Python will be the perfect language to bridge artificial intelligence and microcontrollers.
A Dedicated Board
Recently, some microcontroller boards specifically designed for Python have been presented to the public.
Pytboard is a microcontroller board developed by Damien George that runs Micro Python, a lean and fast implementation of Python that optimizes Python to run on microcontrollers. Using regular Python 3.0, you can effortlessly run your next DIY project.
So how does it compare to traditional microcontroller boards? As its creator said:
Compared to Arduino, Micro Python boards are more powerful, easier to program, and do not require a compiler on your PC. Compared to Raspberry Pi, Micro Python boards are cheaper, smaller, simpler (you can even make one yourself, or modify the design to suit your needs), and consume less power. Most other boards are programmed with C, which is a lower-level language, making it difficult to program correctly. On the other hand, Python is a very high-level language, which means that using it to do the same things will require simpler and less code compared to C.
Conclusion
Although C and C++ may be the preferred programming languages for microcontrollers (at least for now), they will gradually be overlooked due to the emergence of easier-to-use languages like Python, along with the rise of popular microcontrollers like Raspberry Pi and Intel Edison, and the growing and supportive community. Prototyping becomes faster, leaving more space to test ideas rather than controlling hardware. In the way of Pyboard, I believe that in the future, more and more microcontrollers will gradually focus solely on Python.
Original English text: https://medium.com/@stphanerecouvreur/microcontrollers-why-are-we-betting-on-python-2fc9eaaa23fb#.u2yt0b63g Translator: yaoyujia123
Leave a Comment
Your email address will not be published. Required fields are marked *