Timezone: Europe/London

.

AboutContactMicropythonESP32Links
Moonlight Systems

The difference between Python and Micropython

Python is a popular programming language that can connect to database systems and read and modify files.

Python can handle big data and perform complex mathematics and be used for rapid prototyping, or for production-ready software development. Wherever I mention Python, I am refering to Python version 3. Version 2 is largely deprecated now, and many of the functions have different syntax. Often, if you are searching websites for solutions to something you are working on, be sure to check whether the answer that appears to suit your search is up to date and refers to Python 3, as there is still a vast amount of information online that is out of date. Having said that, if the answer seems to fit your enquiry, you will have to go the extra mile to understand it, and convert it to your particular scenario. I say this candidly, as in the early days when I was learning, this situation arised regularly. The temptation is to copy and paste without really digesting the information.

Micropython (often written as uPython) though, is not the same as Python.
Well, it is, but not as we know it.

Like Python, it is open source and has been developed, maintained, updated and supported constantly by many skilled contributors for no profit. However, having said it is not the same, the bits that are the same, are the same. Let me explain......

UPython runs on microprocessors, so has to have a small footprint due to memory constraints. The developers of uPython have taken Python and put it on a severe diet. All the parts that are essential are there, but other parts that might not be needed for a microprocessor application have been left out. So when using uPython and hitting a stumbling block, don't google Python, but limit your search specifically to Micropython.

From the link to the right you can read about which parts of Python have been incorporated into uPython, and which are uPython specific. Also, as these languages are constantly being developed by a large community, it is always good practice to ensure you are using the most up to date stable version of the OS which can be found from the links section.

Some people have asked me why I prefer uPython on the ESP32 to the Arduino C based code.
Its a good question, as the vast amount of information and demo code for the ESP32, and indeed many sensors, breakout boards and add on modules is Arduino based. Indeed, Adafruit, who produce the ESP Feather which I like so much, seem to exclusively promote Arduino code, and include Circuit Python as an afterthought, and none too completely. Circuit Python is another flavour of uPython, but there several differences which I find incompatible with my requirements. I guess its because I never went up that road, a bit like VHS versus Betamax, Sega or Nintendo. (Showing my age there)!

My prefarence for uPython is purely personal.
Arduino is compiled and downloaded as machine code, so once it's there and running, if it works, great, if not it is hard to debug. Once a program is compiled and downloaded, the ESP does not hold any source code. So, if you are not meticulous in organising your development system, it is easy to get confused about which version is which, or even lose the source. You may have a program running on an ESP, then put it to one side for a week or a month, starting work on another board, if you go back to this one and do not know what program is on it, the only way to find out is run it. If it has been a long time, you may not even remember what source code produced it. [That might be an age thing and particular to myself].

With uPython, if you get a board out of your bits box, and plug it in to your PC, you can immediately copy the source code. Debugging is a lot easier. Running the code will show you on screen where is falls over, with a line nuumber and explanation. The only downside is when a new module comes out, for example a GPS breakout or SD card reader, the official docs will point to an Arduino library that is needed to run it. Unless some enterprising developer has uploaded a Python translation of this, you will have to do it yourself.

Links

IDE editors for programming ESP boards.
Micropython editors

Micropython functionality and libraries.
Micropython.org

Find the uPython firmware for your board.
uPython firmware for development boards.

ESP32 uPython modules and function examples.
Quick reference for the ESP32

Finding the MAC address

Scanning and connecting to multiple SSIDs

Using an SD card reader breakout board

ESP32 Real Time Clock

The Deepsleep function

Storing variables in the RTC

RTC Tuning

OTA Updating running software without interuption

Future articles

Communication between ESPs

Using an Adafruit GPS module

Hassle free web communication with urequests.py.