This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:scriptingprogramming:pythonfundamentals [2023/09/06 11:31] – external edit (Unknown date) 127.0.0.1 | en:iot-open:scriptingprogramming:pythonfundamentals [2023/11/23 12:25] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Python Fundamentals for IoT ====== | ||
| + | {{: | ||
| + | A program in Python is stored in text files on the device' | ||
| + | In the context of IoT programming, | ||
| + | Python is simple and efficient in programming the not-so-complex IoT algorithms but does not offer the level of control needed in real-time applications. It can be easily used for prototyping, | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | < | ||
| + | |||
| + | Nowadays, Python interpreter usually comes with OS (Linux) preinstalled. | ||
| + | The sample installation procedure for Raspbian OS is presented in the manual maintained by the Raspberry Pi manufacturer ((https:// | ||
| + | In the case of the popular Raspbian or Ubuntu for Raspberry Pi, there are usually 2 versions of Pythons preinstalled: | ||
| + | Python version can be started from the terminal simply by calling: | ||
| + | <code bash> | ||
| + | ~$ python --version | ||
| + | Python 3.8.10 | ||
| + | </ | ||
| + | In the case one needs to use a specific version, you can start the interpreter explicitly referring to Python 2 or Python 3: | ||
| + | <code bash> | ||
| + | ~$ python2 | ||
| + | Python 2.7.18 (default, Jul 29 2022, 09: | ||
| + | [GCC 9.4.0] on linux2 | ||
| + | Type " | ||
| + | >>> | ||
| + | |||
| + | ~$ python3 | ||
| + | Python 3.8.10 (default, May 26 2023, 14: | ||
| + | [GCC 9.4.0] on linux | ||
| + | Type " | ||
| + | >>> | ||
| + | |||
| + | </ | ||
| + | |||
| + | Python can be executed via a desktop graphical interface (in the graphical terminal), in a text-based Linux installation via terminal, or remotely via ssh. As it is possible to write applications with visual GUI, starting them in a non-graphical installation of the Linux OS will throw an error. To execute a Python script (program), one needs to execute the following: | ||
| + | <code bash> | ||
| + | ~$ python mypythoniotapp.py | ||
| + | </ | ||
| + | |||
| + | Linux, Windows and Mac systems used to bind a '' | ||
| + | <code bash> | ||
| + | ~$ ./ | ||
| + | </ | ||
| + | |||
| + | <note tip> | ||
| + | |||
| + | The following chapters present Python coding elements specific to the microcontrollers. A complete Python course is beyond the scope of this publication, | ||
| + | |||
| + | ==== IDEs for Python ==== | ||
| + | A dozen of IDEs can be used to program in Python. The most common are: | ||
| + | * IDLE Editor, formerly delivered with Raspbian OS in the bundle, requires GUI. It is currently obsolete but still popular among hobbyists. | ||
| + | * Thonny Python IDE, which comes with Raspbian OS, recently took over IDLE. | ||
| + | * Visual Studio Code with plugins for Python, standard with Arduino framework, that also easily integrates remote Python development - it provides two development scenarios: local on the IoT device (Raspberry Pi, requires GUI) and remote from the PC to the IoT device, that works with headless Raspberry Pi OSes installations. | ||
| + | * PyCharm Community Edition requires additional installation ((https:// | ||
| + | * Simple code can be authored in the terminal using any text editor (e.g. Nano), as Python source files do not require compilation and are plain text ones. This is not very convenient, but it can help if no dedicated IDE and GUI are available, e.g., for rapid work remotely. | ||
| + | |||
| + | <WRAP excludefrompdf> | ||
| + | The following subchapters present some IoT and embedded systems-specific Python programming and an elementary introduction: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | * [[en: | ||
| + | </ | ||
| + | ==== Additional Resources for Python programming for beginners ==== | ||
| + | For in-depth Python courses and more, follow the links: | ||
| + | - The Python syntax and semantics: [[https:// | ||
| + | - The Python Package Index (PyPi): [[https:// | ||
| + | - The Python Standard Library: | ||
| + | - Free online Python course: [[https:// | ||