Photo by Vishnu Mohanan on Unsplash
🦄Microcontrollers support modern languages
wanna run Python, Javascript, or Go ... guess what, you got them all. let's explore the advancement in the microcontroller ecosystem
Table of contents
Points to be covered
Lil History.
Modern language support in microcontrollers.
Will my development board support these languages?
Let's blink Leds with a couple of these modern languages.
What has changed in the microcontroller ecosystem?
Before grasping modern advancements in the ecosystem, we should know a little bit about the history around it.
Phase 1: World's first microcontroller
Gary Boone along with Michael Cochran created the first Microcontroller at Texas Instruments around 1970 - 1971. It was given a name similar to some weird codename equals 'TMS1802NC'
Phase 2: Assembly & C
These tiny legacy microcontrollers used to be coded in assembly code. One of the great disadvantages of writing in assembly is that you can't run the same code on different microcontroller architectures like { arm64, arm32, PowerPC, etc } also it's equivalent to writing binary still🥹
Then the 'C' miracle was adopted by the ecosystem and every other vendor was shipping their microcontroller with their own SDK. That made it difficult for developers to quickly hop from one board to another.
Phase 3: Arduino breakthrough
Arduino developed an IDE that supports a wide range of microcontrollers. It's 'C/C++' like syntax with a '.ino' Extention with tons of libraries and built-in support. developers loved the idea of 'write once run anywhere' at least Arduino products for a moment. Later non-Arduino boards start to become Arduino compatible like ESP32.
Phase 4: Modern language integration
How awesome it would be on integrating your most loved programming languages like Python or Golang into your favorite microcontroller board. Guess what it's happening now, & you are a couple of steps away to run blink LED code in your favorite language of choice. Skip to the "Hands-on" section to try it yourself.
For each language brief skip to the "Modern language support" section.
Important dates to compare
Date | Event |
1947 | Invention Of Transistor |
1959 | Invention Of Integrated Circuit |
1965 | Birth Of Moore’s Law |
1971 | First Microprocessor came to Market-4004 |
1971 | Development of First Microcontroller-TMS1802NC |
2011 | Intel announced its first 22 nm microprocessor, codenamed Ivy Bridge, using a technology called 3-D Tri-Gate |
Modern language support
Well, there are multiple modern languages with multiple solutions to bring them into the micro-ecosystem. What exactly do I mean by solution here? lemme give you a real example before taking you into a rabbit hole😅
If you wish to write Python on your development board, then you may need https://micropython.org/ or https://circuitpython.org/ as a solution.
Now lemme give you a list of solutions for a couple of languages.
Python
Javascript
https://kalumajs.org/ { Only for Pi Peco }
Go
Rust
Writing code in Rust is a little more complex than above languages 🥲
The Rust language can be compiled specifically for development boards whose ISA { Instruction set architecture } can be found at https://doc.rust-lang.org/nightly/rustc/platform-support.html.
The Embedded Rust can be written in two ways :
Rust::Unsafe mode - which means direct access to memory for low-level hardware access like timers, interrupts, etc.
HAL { Hardware abstraction layer } - which means, you no longer have to directly communicate bare metal. Now you can get specific 'HAL crates' for your board. Crates can be found at https://crates.io/. These crates are like APIs to access low-level stuff.
Embedded repo resource for Rust - https://github.com/rust-embedded
Will my board run modern languages?
Most language Runtime firmware is open-sourced with diverse communities constantly contributing to the project. As a new dev board pops into the market, the community is there to add support for it.
lemme give you a list of boards for specific languages.
MicroPython - https://github.com/micropython/micropython/tree/master/ports
CircuitPython - https://github.com/adafruit/circuitpython/tree/main/ports
TinyGo - https://github.com/tinygo-org/tinygo/tree/release/targets
JerryScript - https://github.com/jerryscript-project/jerryscript/tree/master/jerry-port
Rust - https://doc.rust-lang.org/nightly/rustc/platform-support.html
NOTE: You can find any other language runtime or language-specific board support in the project repository.
Hands-on
Here I'm demonstrating LED blink fin MicroPython, you can test it out for others, or lemme know if you want a dedicated blog for that.
I'm using Raspberry Pi Pico for the demonstration, you can either go for the same board or use another with maybe a slightly different installation of MicroPython firmware.
Follow the below docs to install MicroPython firmware.UF2 file on it.
After successfully getting your REPL up and running, try running the below code to blink the built-in LED on Pi Pico.
from machine import Pin, Timer
led = Pin(25, Pin.OUT)
timer = Timer()
def blink(timer):
led.toggle()
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
Here is a list of reference articles referred to write this blog :
https://www.raspberrypi.com/news/multilingual-blink-for-raspberry-pi-pico/