Micropython and new horizons.

I have almost no real programming experience. I am ‘okay’ with computers, but most of it was all high-level UI kind of stuff. When I decided to get into Arduino as a hobby, it was because I knew that there were open source options for all of the IoT stuff coming to market, but I had no idea how to engage or hack any of those products. It seemed to me that a Google Home couldn’t be that complicated – or that a smart light was essentially just a wifi enabled on/off switch, which should be similarly simple.

I wasn’t wrong, but I wasn’t exactly right. Figuring out something as easy as a wifi controlled relay leads you into this world of computer science, programming languages, hardware compatibility and github (which I knew of, but was fairly intimidated by). I don’t know if diving into this rabbit warren was a necessary step or something particular to my personality (I am often confused by things until I can begin to understand their context.), but dive in I have been.

Arduino is a language based on C and C++. The underlying structure of the language is widely used and the Arduino language was developed by a helpful and dedicated community of people. Because of its legacy as one of the first hobby accessible microcontrollers, there was a concentration of people developing the language. But there are two limitations that I have encountered.

  1.  Because Arduino is based on a more complicated low level language (C, C++), writing new libraries and such requires substantially more ability and know-how than the casual hobby-ist. Luckily, the number of people more talented than I writing these libraries and code provides a wealth of examples and templates.
  2. The arduino IDE where you write the code needs to compile everything and translate it before loading it on the board and running it. This means that your workflow goes like this – code > compile > upload > run > error/unitended things > back to code > compile > upload > run > error/unitended things > back to code > compile > upload > run > etc etc. This means that it is difficult to quickly test and problem solve issues in your code, it also means that you spend a significant amount of time waiting to compile and upload code only to discover you made a typo somewhere.

This is where Micropython comes in. I came across micropython while experimenting with the ESP32 from Espresif. What an amazing little chip! I learned that Micropython is an implementation of Python 3 that was designed for the specific hardware constraints of microcontrollers.

Python and in this micropython has this wonderful little thing called a REPL. It allows you to pass code to the chip in real time and test out a section.like this:

>>> print(‘I am writing this in the REPL’)
I am writing this is the REPL

Python really is an elegant language. Very intuitive. The visual syntax of it is very clear and easy to read. For someone without much experience programming, it has an easily graspable internal logic.

The problem is that although its quite beautiful, it is far less common than Arduino and the number of libraries is far smaller. Now, you can leverage the huge python community for help, but there is going to be some stuff that doesn’t line up in the transition between a Python 3 and Micropython. Add to this the large number of hardware specific (relative to the size of the language) that have been made for various hardware… pyboard, circuitpython, microbit etc.

So, in a sense I am extremely excited by this new direction while also cautious … I think this will make me better at coding, but it might slow down the riparia project a bit.

So far I’ve written a few rudimentary scripts – a water level sensor that triggers a pump to top off the tank, a rudimentary light timer and a very basic thermostat/incubator for a horticultural project. All are just practice and proof of concept kind of things, but its exciting.

As always, the next big step (aside from adding more complexity to the operations) will be linking them to the net and getting wifi control, IFTTT hooks and wifi data-logging.

I really want micropython to surge, but also wondering if it makes more sense to run Python on a Pi Zero or something else.

Leave a Reply

Your email address will not be published. Required fields are marked *