Raspberry Pi Pico Programming with MicroPython | A Beginner’s Guide
What is MicroPython?
MICROPYTHON USES :
How is Computer to use for Raspberry Pi Programming?
RASPBERRY PI PICO DOCUMENTATION:
How to Install MicroPython on Raspberry Pi Pico?
Download MicroPython Binary
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”?
Install MicroPython on Raspberry Pi Pico
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.
Configuring Thonny for Raspberry Pi Programming
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:
For using the GPIO block, follow the following steps:
Blink an LED in Raspberry Pi Programming
#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)
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()
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.