If you buy something from a this link, myelectricsparks Media may earn a commission. See our Read More.

Outline
Introduction
PYTHON INVENTION:
What is MicroPython?
MICROPYTHON USES :
- If a software developer who had never on hardware but still wants to write libraries for Microcontroller embedded systems for personal or professional projects then MicroPython should be used.
- The MicroPython working method is similar to that of Python. So if the software developer is familiar with Python working systems then controlling MicroPython will be easier for him/her.
- But if the software developer is working the first time then don’t worry it’s an easy language and can be easily learned
How is Computer to use for Raspberry Pi Programming?
RASPBERRY PI PICO DOCUMENTATION:
RECOMMENDATION:
NOTE:
How to Install MicroPython on Raspberry Pi Pico?
Download MicroPython Binary
STEPS:
- At the download the Prebuilt Binary from the Official Raspberry Pi Pico’s Foundation or Website. This program makes it easy to run MicroPython on Raspberry Pi Pico and also it’s the fastest way.
- Now visit the documentation page of Raspberry Pi and click On the “Getting Started MicroPython ” tab.
When the “Getting Started MicroPython” tab is clicked, All the text below the tab changes according to the chosen tab.
Text related to Getting started with MicroPython appears along with a few animated steps on “how to install MicroPython on Raspberry Pi Pico”?
Note:
Install MicroPython on Raspberry Pi Pico
STEPS:
- First of all, convert Pico into Bootloader mode. For converting purposes, plug in a micro-USB cable to a micro-USB port of Raspberry Pi Pico. Then hold the BOOTSEL BUTTON on the Pico and attach the USB cable to the USB port in the host computer while holding the button.
- When Raspberry Pi Pico appears with “RPI-RP2 then release the button after few seconds.
- Now, After opening the file, you’ll see an HTML file.
Downloading Thonny
For better understanding first, know about “what is Thonny “?
It’s a simple Python IDE program available for Windows, Mac, and Linux but the Raspberry Pi OS comes along with Thonny preinstalled.
While using Windows systems versions of Thonny should be downloaded. “thonny-3.3.5.exe” is added, now double click on it then it will start downloading and Thonny will be installed.
NOTE:
Configuring Thonny for Raspberry Pi Programming
- The Toolbar: Work as saving, running, and stopping the programs. The Script Area: It is for writing Python Programs.
- The Shell: It is an interactive REPL (Read-Evaluate-Print-Loop) block it works when an individual command is given to the interpreters and then they will execute them.
- The Interpreter: It works as Selecting the right interpreter from the IDE on the bottom right side.
Thonny IDE is a desk designed to interpret Python 3.x.x. automatically.
Now, Click on Python and select MicroPython (Raspberry Pi Pico) interpreter. When the MicroPython interpreter is selected, the shell ???? changes to MicroPython at the bottom.
As the MicroPython supports REPL, now when the command is written in the shell, the Raspberry Pi Pico will complete the command. (source)
The example is given below.
Programming Raspberry Pi Pico with MicroPython
In the Shell, any command can be written with these“>>>” symbols. For example, writing “HELLO WORLD”.
When the command is given in the shell of MicroPython interpreter whose working systems are based on Raspberry Pi Pico. When the command is received the MicroPython will respond will a “Hello, World!” reply and will automatically print it in its the shell.
If the layout of the Raspberry Pi Pico, an LED is attached to GPIO 25. Then this LED can be turned ON and OFF from the shell.
For trying to ON and OFF the LED light. For this purpose at first, a special library is imported known as a ” machine”. This library’s function is to control the hardware of the Raspberry Pi pico board. Also, the Machin module when used on Microcontroller, it is reset, enabled or disabled, put to sleep ???? ???? , etc.
CLASSES OF MACHINE MODULE:
Some of the machine modules are given below:
- Pin Signal
- ADC
- UART
- SPI
- I2C
- RTC
- Timer
- WDT
- SD
- SD Card
For using the GPIO block, follow the following steps:
Blink an LED in Raspberry Pi Programming
STEPS :
#Import Pin class from machine library to configure GPIO Pins. from machine import Pin #Import utime library to implement delay import utime #create an object of Pin class and set GPIO Parameters (GPIO Pin, Direction). led_gpio16 = Pin(16, Pin.OUT) #Create an infinite loop. This is similar to while(1) in C. while True: #Set value to 1 to turn ON LED. led_gpio16.value(1) #sleep_ms function provides delay in milliseconds. utime.sleep_ms(100) #Set value to 0 to turn OFF LED. led_gpio16.value(0) #Provide another 100ms delay to see the LED Blinking. utime.sleep_ms(100)
#Import Pin class from machine library to configure GPIO Pins. from machine import Pin #Import utime library to implement delay import utime #create an object of Pin class and set GPIO Parameters (GPIO Pin, Direction). led_gpio25 = Pin(25, Pin.OUT) #Create an infinite loop. This is similar to while(1) in C. while True: #Toggle the status of LED. led_gpio25.toggle() #sleep_ms function provides delay in milliseconds. utime.sleep_ms(100)
Reason for Naming main.py in Raspberry Pi Programming
- Python program can be given any name but when “blinky.py” is given. It will not be interpreted if the power is removed and then reconnected. These are the few reasons for which you have to name the file or script “main.py”.
- The Python script will only be interpreted when it’s named ‘ main.py ‘. If there are Multiple Python scripts then only scripts with mentioned names will be executed by MicroPython.
Read from Button
#Import Pin class from machine library to configure GPIO Pins. from machine import Pin #Import utime library to implement delay import utime #create an object of Pin class and set GPIO Parameters (GPIO Pin, Direction). ledPin = Pin(16, Pin.OUT) buttonPin = Pin(15, Pin.IN, Pin.PULL_DOWN) #Create an infinite loop. This is similar to while(1) in C. while True: if buttonPin.value() == 1: utime.sleep_ms(20) ledPin.toggle()
Conclusion
FEEDBACK:
About Author
Aizaz khan
Aizaz was the first person to get a byline on his blog on technology from his home in Bannu in 2017. Then, he went on to a career in breaking things professionally at my electric sparks which is where he eventually took over the kit as a hardware editor. Today, as the senior editor of hardware for my electric sparks, he spends time reporting about the most recent developments in the hardware industry and technology. If he’s not reporting on hardware or electronics, you’ll see him trying to be as remote from the world of technology as possible through camping in the wild.