Skip to main content

Why we need to retire the blinking LED as the entry into embedded programming

Something that was true since 1985 changed in Q4 of 2018 and we are yet to feel all the repercussions.

Every ThinkPad, iPhone, Kindle…every Alexa, Nest, Homepod…every DJI Drone, Go PRO or Tamagochi,  every Fitbit, every Pebble…every Xbox or Nintendo…every Walkman, every Game Boy, every C64, Amiga or Tandy.

Every piece of electronics which we geeked out about, used, abused, eventually bricked then forgot…

Each and every one of them hails from the same embryo.

The blinking LED. 

It used to be the classic “Hello World” of the embedded world.

But for a while now it has been due for an update. An update that would reflect the vanishing boundaries between different domains of software development, as brought on by IoT. Consider Gartner’s prediction: by 2020, 20.4 billion devices will be connected to the Internet. It’s time to replace the LED blink with a “Hello, Cloud.”

We could have spent a few more years debating about it but a major turning point happened in the last quarter of last year, giving us a perfect excuse.

What happened in Q4 of 2018 is that Python became the most popular programming language, according to the 5-minute video below that recently went viral. To become number one, Python toppled Java. Java sat on the top spot since 2000 after dethroning C, which in turn knocked down Pascal in 1985.

C and Java are related so the transition between the two is not as interesting as the rise of Python. How did a scripting language replace a comparatively low-level language as the most popular in the world? Will Python seep into all aspects of programming from supercomputers to embedded systems the way C did? And will it have a 33-year run on the top like the c-family of languages?

It’s impossible to tell, of course. But whatever skeptics and detractors may say, Python is more diverse than given credit for. It has only started to show its potential for programming embedded systems. What it lacks in efficiency and speed of execution, it makes up for in speed of development and deployment. And in the world of 32-bit microcontrollers, and short, Agile-based development cycles, this is often a welcome trade-off. 

To demonstrate the beauty and elegance of Python in embedded applications, I want to show you the “Hello Cloud” example of Zerynth, a company I work with. Zerynth offers a Python toolchain for embedded and IoT programming.

In just 12 lines of readable Python code, you can connect your device to the cloud and send a message.

In this example, I am sending a “Hello Cloud” message from a Xinabox CW02 board  (174-3702) – figure 2, below – to the OKDO Cloud (one of many possible board and cloud vendor combinations supported by Zerynth):

from wireless import wifi
# choose a wifi chip (esp32)
from espressif.esp32net import esp32wifi as wifi_driver
# let's import the OKDO cloud modules; first the IoT module...
from okdo.iot import iot
# ...then the http client
from okdo.iot import http_client
# initialize hardware
wifi_driver.auto_init()
# connect to wifi (replace “SSID” and “password” with your credentials)
wifi.link("SSID",wifi.WIFI_WPA2,"password")
# create a "thing"
thing = iot.Device("lJilHMrRU39spSMoJATGdeVs","maker:4JQTMUt5kNoqW1VeVoeEuiyKAFik6Nek8pDYkGD",http_client.HttpClient)
# connect to the cloud
thing.connect()
# run the client
thing.run()
while True:
   # sleep a bit...
   sleep(1000)
   # ...and Hello Cloud! (you can personalize the message)
   msg = thing.publish_asset("msg","Hello Cloud! :-)")
 

You can see the result here and in Figure 1, below.

image3-1024x696_9a633c5bec172d9b7f92b61771f9b2fa1f278275.png

Figure 1: Screenshot of the OKDO Cloud Dashboard showing the message. In this example, the OKDO dashboard is publically shared. The platform also allows users to configure private dashboards.

Figure 2: The Xinabox set used in this demo


A total of 12 lines of code to connect your device to the cloud! 

Compared to this, the classic LED blinking example of the embedded world looks as feeble as a gesture of a man who just woke up from a coma and is told to blink once if he is conscious.

And to think that back in the ‘90s, I had to learn assembler to blink my first LED. Even if you wanted to do it in C, you’d need to do it differently depending on the target microcontroller. 

In contrast, the Zerynth tool-chain adopts Java’s “write once, run anywhere” approach to the embedded world, through its Virtual Machine firmware.

Does Python provide an equal degree of low-level access to the underlying hardware the way C does?

Certainly not.

But the beauty of Python is that it’s the perfect “glue language.” The Zerynth tool-chain takes advantage of this by implementing a hybrid Python/C approach.

This means that experienced embedded developers sacrifice nothing, while newcomers to the embedded world can put their Python powers to good use in a brand new domain.

In that regard, Python is the glue in more than one way. It breaks barriers and brings together domains of software engineering that have been separated ever since the dawn of the PC revolution. 

If Python can bring us closer to the atmosphere of that homebrew-era of IT, before the compartmentalization and uber-specialization of developers when the biggest innovations took place — then I am rooting for it to keep its top spot among the most popular languages for decades to come.

I’ve learned early on in my career that I love to be at the forefront of innovation. To see new technologies emerge, and be a part of their creation. From the first days on the internet and the Silicon Valley revolution to The Internet of Things — I’ve seen it all, and I’ve done it all. Now, I’m ready to use this knowledge to help young companies thrive. I have over 35 years of experience in driving revenue, encouraging new ideas, and fostering client relationships.
DesignSpark Electrical Logolinkedin