Learning (embedded) Python

One of the Paul’s that regularly attend the Electronics Meetup asked:

What’s a good program to use to learn Python?

He’d tried https://replit.com/, but hit some frustrations with how it works.

My suggestion was to continue the free Introduction to Python course he had found on https://www.saylor.org/, but to try Jupyter notebooks instead.

Jupyter provides an engineering notebook like experience where you can add notes and code (Python, Julia, C++, …) in cells. Notes are written in Markdown, which is text only with short-hand for formatting. It’s meant to be quick and simple, and avoid distractions fiddling with fonts, colors, etc.

Code cells are executed top-to-bottom. You can go back and tweak a cell and re-run it to see how the results change, and then run all those that follow (as they may need to update their results due to this change.)

It’s a great system for trying things out, and making (just enough) notes to remind you of what you were thinking.

Although easy to use it used to require enough familiarity with the command line and PIP, a Python package manager, to install and run.

Now, it’s a lot easier!

Google Colab

Google offers a free Jupyter notebook based service called Google Colab.

It requires a Google account.

Your notebooks are saved in your Google Drive.

You can also upload data files to your Google drive and access and process them from your Colab notebooks.

Microsoft Visual Code + Jupyter Notebooks Extension

Visual Studio Code is a free, and extremely powerful IDE (Integrated Development Environment) that provides code editing, (very smart) auto completion, contextual help for programming language keywords, debugging, and more.

There is an official Jupyter Notebook extension that lets you create Notebooks directly in VS Code- including graphs and other diagrams.

It does require that you have installed Python already, but it takes care of the rest of the process.

And they have good instructions for setting it up and using it.

A little more work than using Google Colab, but you do have all the pieces under your control, on your computer.

Moving on to Embedded Python

Learning (Micro)Python for embedded microcontrollers can be a little more difficult. Often you’re not only learning Python language, but also the basics of electronics- ie not only what code is needed to turn on a light, but also how to wire it up so that it doesn’t let out the magic smoke!

That’s why makecode for microbit is still my go-to recommendation for all ages. It simulates the hardware in the web-browser so you can try things out BEFORE any wires and electricity are involved.

Tip: When you create a new project, click on the code options button and make sure blocks, JavaScript, and Python is selected. You’ll then be able to switch between the simplified blocks language and the equivalent in Python! It’s a great way to learn, especially when you have an idea but don’t yet have the Python vocabulary to implement it.

Next steps would be either Mu or Thonny IDEs and MicroPython or Circuit Python (my favorite of the two for beginners) on an ESP32 or Raspberry Pi Pico board.

Author

The short URL of the present article is: https://makeit.zone/go/wpe7
Scroll to Top