Microcontroller specifications have changed little over the last few decades, but the expansion of languages and supporting software has opened up many paths for application development.

For years, programming microcontrollers involved a choice between two languages: C and Assembly. But with new languages now available for microprocessors, users face more decisions in their application design.

Which language is best? There's no clear answer because it depends on the application you're working on. To help you plan your development, here's a high-level exploration of different languages available for microcontroller use, as well as resources for further learning. You can also check out our previous article on languages for embedded systems, which covers Rust, Python, and VHDL and Verilog.

 

C and Assembly

Before new languages became available for microcontrollers, the two choices available were C and Assembly. Let's look at them briefly before covering new languages in depth. 

C is a popular microcontroller language even though it was developed in the early 1970s. For use with microcontrollers, C functions well because it has the ability to handle memory allocation while also performing complex functions like if statements, loops, and mathematical expressions.

Assembly offers an alternative to C with a few advantages. Assembly is an older language that often uses code specific to the device, which is converted using an assembler utility program. Using this language, the user has direct access to the CPU where routines can be carefully adjusted for precise timing applications. Assembly offers better CPU usage, as well as further sets of instructions that C does not support such as bit manipulation with specific BIT instructions.

Learn More:

 

MicroPython

Python is a feature-rich interpreted language, known for its simplicity, clarity, and general-purpose adaptability. These features also make the language too large for microprocessors. However, with the help of a Kickstarter campaign in 2013, physicist Damien George was able to adapt Python into a smaller version, MicroPython, that is suitable for use on a microcontroller.

MicroPython code is open-source under the MIT license. The language runs on the bare metal of the microprocessor using a small subset of the standard Python library. It can operate using only 256k of space and 16k RAM, yet it is designed to be as fully compatible with regular Python as possible.

 

A diagram of the PyBoard, MicroPython's official microcontroller board. Image courtesy MicroPython

 

Originally designed to run on ARM-based systems including the BBC micro:bit, Adafruit Circuit Playground Express, and the MicroPython PyBoard, it has also been made available for other processors including the ESP8266 and ESP32.

MicroPython shines in prototyping complex projects. On the ESP8266, for example, creating IoT projects can be done with a few simple function calls to get a MicroPython project connected to a local Wi-Fi point and start streaming information to a MQTT broker.

Learn More:

 

Blockly

Blockly is an open-source programming library supported by Google, aiming to make code visually logical by using drag-and-drop blocks.

Rather than relying on words and phrases that make no sense in normal conversation, users place blocks into an environment and connect them together to define how a program flows. For example, instead of writing an IF statement, users drag the IF block into the workplace and resulting actions are also dragged inside the IF statement block.

 

Screenshot of Blockly interactive demonstration, courtesy of Google for Education

 

After building a block, users can export their Blockly code in a number of languages, including JavaScript, Python, PHP, Lua, and Dart. One of the advantages of the Blockly system is that it is almost impossible for errors to occur (not bugs or mistakes, just plain old errors), as blocks require specific connections and won't allow incompatible blocks to connect.

While this programming method is available on many platforms including the Micro Bit and the Adafruit Circuit Playground Express, it is not designed to be used for a final commercial product. However, it is very useful in prototyping stages, especially if a proof-of-concept is needed and learning a device's specifics would take too long (such as registers, configuration bits, and IDE configuration).

Learn More:

 

Arduino C++

While it's often referred to as the "Arduino programming language", Arduino is actually programmed in good old C++ and uses a subset of libraries specific to the Arduino.

The differences in Arduino C++ from regular C++ include generic routines for microcontrollers, since standard library C++ functions can't operate on their limited power and memory.

 

The Arduino Uno board. Image courtesy of Arduino.

 

Using this smaller version of C++ makes this language highly accessible, as many designers are already familiar with regular C++. In fact, by using a compiler, code can be written in C++ and then interpreted into code that is usable by the Arduino.

The advantage of using Arduino C++ is that it is suitable for commercial environments, is faster than larger languages such as Python, and is highly portable. Compiling code on an ARM core originally for the Uno is automatically handled by the library with the use of generic functions.

Learn More:

 

BASIC

BASIC is a language that first appeared in the 60s and saw its heyday with the rise of the personal computer in the 80s. BASIC (an acronym for Beginner's All-Purpose Symbolic Instruction Code) still remains in use still today due to its simplicity and interpreted nature, which allows a designer to focus more on the hardware and less on the software.

When used on a microcontroller, BASIC is interpreted which causes a performance penalty. However, the language has an advantage in that it is highly portable. Any code written in BASIC will work on any device that has a BASIC interpreter. 

 

Image courtesy of Charles R. Hampton.

 

Two examples of BASIC being used on microcontrollers are BASIC Stamp (produced by Parallax) and PICAXE which are produced by PICAXE and use Microchip PIC microcontrollers. BASIC is a good language for prototyping and even hardware development but should be avoided in commercial products due to its slow speed and energy consumption.

Learn More:

 

Conclusion

When working with microcontrollers in the past, a designer had to choose their preferred platform and then learn the language it uses. With advancements in languages and software, these days the language can decide which platform a designer uses. If a designer is looking for a specific feature, such as GPIO support, networking, ability to communicate over SSH, or others, then the choice of language and systems can be important factors in finding the best development path.

The language that users choose is important, but it's always good to remember that there is no such thing as “the single best language” or “the single best microcontroller”. In the end, the best choice is whatever the application calls for.

 

Comments

8 Comments


  • yerpj 2019-02-06

    Great article !
    However it is not talking about embedded Javascript, which is being more and more adopted everyday. Among embedded javascript, the one which seems to be the most suited for microcontrollers is Espruino (http://www.espruino.com/Reference). From a user perpective, features are almost similar to Micropython, but with a more user-friendly language syntax grin

  • withoutego 2019-02-08

    This feature is excellent - helps us old farts get over ASSY and bypass C++ in writing embedded code for PICs etc.
    I will make the leap I think to micropython. The learning curve is steeper for the old vs young mind but always a great mental exercise program! “All About Circuits” is super….keep it balanced, ie, working engineer vs student. You are doing well now. KC1CCG

  • jbandy1564 2019-02-08

    In addition to interpreted BASIC, it is possible to use a BASIC compiler, Great Cow BASIC, to develop for the Arduino Uno and others. It maintains the core syntax of interpreted BASIC, but can be used to produce a .hex file which can be programmed onto an Arduino in that form.

  • swr999 2019-02-08

    Regarding versions of BASIC available for microcontrollers, meLabs provides PBP3 (PIC Basic Pro version 3), a version of BASIC developed for the Microchip PIC family of MCUs. It compiles to object code for loading and running on the target PIC. Most of the PIC MCUs are supported. I have no affiliation with the company, just a PBP3 user and have done many projects using PBP3 for a number of years. meLabs has very good support and there are good online user forums as well. If interested, more info at: http://www.melabs.com

  • tampinyeo 2019-02-08

    great article!

    i’m still trying to find a platform/language that can support programming a hardware capable of handling 80mhz of i/o data. FPGA and VHDL still seems like the only option.

    any other suggestion? it doesn’t look like arduino, c++ nor other platforms are fast enough. these are user-friendly but not fast enough for this sort of application.

    thx!

  • adx 2019-02-11

    I’ll second some of the other comments and say I suspect compiled BASICs now outnumber interpreted ones. But it’s an unavoidable fact that BASIC suffers severe prejeudices, which makes it a hard language to use commercially, and quite fragmented in its implementations, which is a shame, as it suits embedded quite well. Maybe one day it’ll have its (third) day in the sun. The oft-cited disadvantages (like interpreted slowness) apply even more to things like MicroPython. Lua’s ‘basic’ syntax is nearly identical!

    About Arduino though, at last check, you can’t use it in commercial projects unless you are prepared to publish your code (object code, but easy enough to reverse engineer). That relegates it to the land of hobbyists and startups who don’t care (or who are already on the open source bandwagon) - which is a shame given its solid GCC foundation and moderately good field testing. Yes you can replace the libraries, but that removes the advantages of prototyping quick, cheap and easy for a small jobs.

  • chrisbaron 2019-02-13

    There are quite a few visual programming systems available for microcontrollers:
    - FlowCode has been around for years and has multiple target platforms
    - NodeRed - popular on Raspberry Pi
    - XOD - interesting newish for Arduino
    - MicroFlow - also been around for years

    Note, microPython is semi-compiled into byte codes which take less space and has faster execution than a source text program interpreted at run time a-la the 80s BASIC systems.

    Finally the years of BASIC language interpreters on personal computers is long over.  Almost all microcontrollers have no file system and no permanent storage except for their internal FLASH so compiled BASIC is far more common than interpreted for embedded applications.

  • keystoneclimber 2019-02-14

    Add Crownhill Proton Basic as yet another (and probably the best) compiled basic.  I’ve used it for countless commercial products.  What is this interpreted basic that you speak of?