There are several ways to program microcontrollers. Some methods are more difficult than others and this can often depend on how much familiarity someone has with programming basics.
This guide is primarily for Arduino developers to learn the ins and outs of using CircuitPython by demonstrating use of program code in both languages. This may be a reference for people as they get comfortable in their CircuitPython skills.
Just as valid could be the Python or CircuitPython programmer who has never used Arduino before. Showing the code that Arduino uses for various things may help to become more comfortable with the Arduino environment.
Interpreted vs. Compiled
Arduino takes a great deal from tools that have been in use for decades. This includes the concept of compiled code. Code is written in a text editor type environment with no debugging. Then, when commanded, it is fed to a series of programs which go about taking the code and in the end compiling it from C or C++ to the machine language of the microcontroller. With a broad variety of microcontrollers on the market, the machine code is unique to that code and that processor.
If the code needs changing in Arduino, the text code must be edited and submitted back through the compile process. Making changes, fixing syntax errors, "dialing in" on optimum values can take a great deal of time in the compile and load processes that happen each time.
Python in general and CircuitPython specifically are interpreted. The code is not turned into machine code until it must be. This has many advantages. The code can give error messages during run time. Any subsequent change does not require recompiling. Loading code is as simple as copying a code text file to a flash drive. CircuitPython program development is often a fraction of the time needed for an Arduino program. The code is also highly portable to other microcontrollers.
The disadvantage to an interpreted code is speed. Converting code to machine code happens on the fly so it takes time. The interpreter also uses RAM and Flash on the microcontroller, more than the equivalent Arduino user code and libraries.
The Reality
Modern microcontrollers are gaining in speed, and memory capacity, often at similar or lower price points than older microcontrollers (which manufacturers will probably want to discontinue at some point). The speed penalty for using Python on microcontrollers is not a concern in modern chips. And the benefits of Python's flexibility and it being taught in schools puts Python in the spotlight.
Providing tools which help migrate Arduino coders to CircuitPython seem particularly appropriate in this age as this is certainly a direction the industry is moving.
You can be slow and still win. And turtles live a very long time.
Text editor powered by tinymce.