In the previous tutorial, we discussed the Python language, its applications, implementations (including CPython, Jython, IronPython, and PyPy), and IDEs. We also learned how to write Python scripts and modules, and how to run Python scripts through an integrated development environment (or IDLE) and a Bash shell. Before we jump to controlling hardware via Python…
RPi Python Programming 05: Introduction to Python
In the previous tutorial, we successfully set up a Raspberry Pi (RPi) Linux desktop. Now let’s learn Python. We could start with how to control the hardware by using Python scripts, but that would defeat the purpose of using Raspberry Pi and a Very-High-Level-Language (VHLL) — such as Python — to control electronics. Certainly, you can…
How to use Raspberry Pi camera module with Python
One of the main attractions of the Raspberry Pi platform is its camera module. At present, Raspberry Pi Foundation offers three camera modules: • Camera Module 2 • Camera Module 2 NoIR • Raspberry Pi High-Quality Camera The camera module 2 is a replacement for the original camera module in April 2016. The V2 module…
RPi Python Programming 10: Object-oriented Python
In the previous tutorial, we learned about the sequences and unordered collections in Python, including the operations, functions, and methods applicable to them. However, there can be more complex data structures in an application, which are known as user-defined classes and objects. Any application uses data (values/objects/user-defined classes/objects) and code behavior (how the data is…
RPi Python Programming 11: Python GUI with Tkinter
In the previous tutorial, we learned about the object-oriented features of Python, which are important for organizing code and structuring our applications. Now, let’s discuss how to design graphic interfaces in Python. Embedded applications developed on microcontrollers typically have LEDs, character LCDs, or small graphic LCDs as display devices. However, these displays do not have…
RPi Python Programming 12: Tkinter and TTK widgets
In the previous tutorial, we learned about the window widget in Tkinter and designed a blank GUI main window (which is not a child to any other window in the GUI application). Child windows serve as a container for other widgets There is no point of blank windows so there must be other widgets included…
RPi Python Programming 08: Python lists and byte arrays
In the previous tutorial, we learned about basic syntax and several elements of Python’s language. Python offers six types of sequences: strings, bytes, byte arrays, range, tuples, and lists. Importantly, the strings, bytes, range, and tuples are immutable sequences that cannot be modified once defined. It’s only possible to create or destroy these sequences. This…
RPi Python Programming 09: Python sets and dictionaries
In the previous tutorial, we learned about manipulating data values in lists and byte arrays. Python also has mutable unordered collections, including sets and dictionaries. Let’s review these two and learn how to manipulate the data values/objects in sets and dictionaries. Sets Sets are unordered mutable collections of items. The items in a set can…
How to build a MicroPython-based sensorless, weather station
Is it possible to update the weather on an embedded device or a wearable without interfacing with any temperature or humidity sensor? With Internet of Things (IoT) access, devices can connect to a variety of web services with the help of APIs and extract several useful insights and information through simple HTTP requests. In response,…
How to use MicroPython’s watchdog timer in ESP8266 and ESP32
A watchdog timer is an internal or external timer that monitors a microcontroller’s program to ensure the application remains operative without failure. It serves as a safety feature in critical applications by monitoring the microcontroller’s output signal. The watchdog can operate in two modes: Timeout mode – the timer establishes the microcontroller is not working properly if it…
MicroPython: How to program a real-time clock (RTC) in ESP8266 and ESP32
A real-time clock (RTC) is a computer clock to keep time and is one of the more popular microcontroller features. Microcontrollers without a built-in RTC require an external RTC chip for keeping time. Typically, mid-segment to high-end microcontrollers have a built-in RTC because time-keeping is necessary for several embedded applications. RTCs count seconds, minutes, hours,…
MicroPython based online weather station on ESP8266 and ESP32
MicroPython is one of the best microcontroller firmware that supports a variety of embedded platforms. The WiFi development boards like ESP8266 and ESP32 are among the MicroPython-supported ports. With MicroPython, it is extremely simple to implement top-notch IoT applications. MicroPython has wide support for network programming along with implementing all basic hardware functions. It combines…
How to animate text on SSD1306 using MicroPython and ESP8266
Organic light-emitting diode or OLED displays have become essential for many embedded devices. OLEDs are considered one of the highest-quality displays to showcase device information. Typically, embedded devices use single-screen graphics, but complex interfaces are required when there are several user interactions. For example, such interfaces might use menus or other graphical navigation. Adding a…
MicroPython: How to write and read text files on a MicroSD card using ESP32
Data logging is an integral part of many embedded projects. Typically, data logging is used to record sensor readings, with or without a timestamp. For example, many IoT applications use data logging to store network changes or data for troubleshooting or verification. The ideal way to log data locally is using an SD or MicroSD…
ESP8266/ESP32-based WiFi access point using MicroPython
Many IoT applications are controlled with the help of a webpage or an HTML website running within a Local Area Network (LAN) or Wireless Local Area Network (WLAN). Some examples of such IoT applications include home automation, office automation, and smart farming. The HTML webpage or website controlling the things is hosted on a microcomputer…
Getting started with MicroPython on ESP8266
MicroPython is an implementation of Python 3 for microcontrollers. It’s an awesome firmware that combines the powerful features of Python programming language with the low-level access of microcontrollers. Following is a list of microcontrollers supported by the MicroPython framework. Arch Mix, Actinius icarus, Arduino Nano RP2040 Connect, Arduino Primo, B_L072Z_LRWAN1, B_L475E_IOT01A, blueio_tag_evim, C3 mini, CERB40,…
Using MicroPython SSD1306 driver to interface an OLED display with ESP8266 & ESP32
You’ve likely heard about SSD1306 or SSD1315 organic light-emitting diode (OLED) displays. These monochrome screens are typically in a similar price range as character displays, providing a more aesthetic appeal. More significantly, they provide a truly graphical interface for an embedded device. The OLED displays are available in ready-to-use breakout boards that can easily push…
How to use ESP8266’s sleep modes in MicroPython
Networking applications consume a lot of power. If such applications are battery-powered, there’s a risk the battery will exhaust because of the high power demands of networking functions. Frequently, power is also wasted in non-essential microcontroller activities. For example, the power might remain on for various built-in peripherals irrespective of their use or relevance in…
MicroPython: Time-related functions, timers & interrupts in ESP8266 and ESP32
Timers are one of the common hardware features in all microcontrollers. Timers and timer interrupts are of great use in microcontroller applications. The timer interrupts are often used when precise timing is required without a fraction of error. All MicroPython ports have one or more timers. Some of these timers may be reserved for specific…
MicroPython – Reading analog signals in ESP8266 and ESP32
The majority of sensors have an analog output. Few sensors come with a built-in controller and can stream the output measurements over a digital protocol. That is why analog to digital conversion is one of the basic features that every microcontroller/port has. The other basic features include digital input/output, analog output, PWM generation, and serial…