IDLE (Integrated Development and Learning Environment) is a user-friendly Python IDE (Integrated Development Environment) available on Linux systems. It provides a simple and intuitive environment for writing, testing, and executing Python code.
IDLE offers a range of features that make it suitable for beginners and learners. It includes a code editor with syntax highlighting, indentation support, and code completion, which helps users write clean and error-free code. The editor also allows you to run code directly and see the output in the integrated Python shell.
The Python shell in IDLE provides an interactive command-line interface where you can execute Python statements, test code snippets, and explore Python’s functionality in real-time. It allows for quick prototyping and experimentation.
In addition to the editor and shell, IDLE supports basic debugging features. Users can set breakpoints, step through code, and inspect variables to understand and troubleshoot their programs.
IDLE is lightweight and typically comes pre-installed with Python on Linux systems. Its simplicity and accessibility make it a suitable choice for beginners or those learning Python programming on Linux.
Author: Pradeep Nandigama, Software Developer, OKdo
Open a terminal and type the command below, enter password for sudo, if asked:
sudo apt update
The command “sudo apt update” is used in Linux systems, particularly those using Debian-based distributions like Ubuntu, to update the package lists or repositories.
Here’s a breakdown of the command:
The process of running “sudo apt update” involves the following steps:
After running “sudo apt update,” you will see the output showing the progress of the update process, including the repositories being accessed and the packages being refreshed. Once completed, your package management system will be up to date and ready for package installation or upgrade using commands like “sudo apt install” or “sudo apt upgrade.”
It is a good practice to run “sudo apt update” regularly to keep your system updated with the latest software packages, security patches, and bug fixes provided by the distribution’s package maintainers.
Open a terminal and type the command below, enter password for sudo, if asked:
sudo apt install idle -y
The command “sudo apt install idle -y” is used in Linux systems, particularly those using Debian-based distributions like Ubuntu, to install the IDLE (Integrated Development and Learning Environment) package.
Here’s a breakdown of the command:
When you run the command “sudo apt install idle -y”, it installs the IDLE package on your system, including all its dependencies. The package manager retrieves the necessary files from the software repositories, resolves dependencies, and handles the installation process.
By including the “-y” flag, the command ensures that the installation proceeds without requiring manual confirmation for each step, allowing for automated installation scripts or unattended installations.
After the installation is complete, you can use IDLE by launching it from the application menu or by running the “idle” command in the terminal. IDLE provides an interactive environment where you can write, test, and execute Python code, making it a useful tool for Python development and learning.
Open a terminal and type the command below:
idle
On the ‘idle’ command line interface opened previously, type as shown below and press enter:
print ("Hello World1")
Launch ‘idle’ with python file name to edit and press enter:
Idle test.py
The test code here calculates the sum of two numbers:
# Python3 program to add two numbers
num1 = 15
num2 = 12
# Adding two nos
sum = num1 + num2
# printing values
print("Sum of", num1, "and", num2 , "is", sum)
Press ‘F5’ on the keyboard to run the python code:
Please follow the instruction in the guide named “AN-00001_MRRA_INSTALLATION_IN_ROCK_4SE_C+_V1_18042023.docx”
ROCK 4 series has a 40-pin expansion header. Each pin is distinguished by color. For ROCK 4C+, the following pin-out is applicable for version 1.2 and later.
Notes about 40-pin Header
SPI
UART
For I2C-2 and I2C-7
IO Voltage
RK3399 have three IO voltages, 1.8V/3.0V/3.3V. For ROCK Pi 4, below is the default voltage:
Here’s an example code in Python that uses the libmraa library to control GPIO pins on a device:
import mraa
import time
# Define the GPIO pin number
gpio_pin = 16
# Initialize the GPIO pin
gpio = mraa.Gpio(gpio_pin)
# Toggle the GPIO pin on and off
while True:
gpio.dir(mraa.DIR_OUT)
gpio.write(1) # Set the pin high
time.sleep(1) # Delay for 1 second
gpio.write(0) # Set the pin low
time.sleep(1) # Delay for 1 second
In this example, we first import the mraa library. Then, we define the GPIO pin number that we want to control (gpio_pin = 13). Next, we initialize the GPIO pin by creating a Gpio object with the specified pin number. We set the direction of the pin to output using gpio.dir(mraa.DIR_OUT). After that, we enter a loop where we toggle the GPIO pin on and off. We use gpio.write(1) to set the pin high (logic level 1), followed by a delay of 1 second using time.sleep(1). Then, we use gpio.write(0) to set the pin low (logic level 0), followed by another 1-second delay.
The loop continues indefinitely, toggling the GPIO pin on and off every second.
Connect a LED to pin 16 GPIO to an LED via a 1k resistor as shown in the image.
PLEASE NOTE: By default the ‘idle’ IDE should be run as root:
sudo idle gpio.py
This will cause the LED to blink on and off every second.
Use ‘groupadd’ command to create a group called ‘gpio’
sudo groupadd -f gpio
sudo nano /etc/udev/rules.d/10-gpio-permissions.rules
SUBSYSTEM=="gpio", PROGRAM="/bin/sh -c '
chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;
chown -R root:gpio /sys/devices/platform/soc/*.gpio/gpio && chmod -R 770 /sys/devices/platform/soc/*.gpio/gpio;
chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath
'"
Press ‘ctrl+o’ and ‘ctrl+x’ to save.
sudo service udev restart
sudo usermod -aG gpio <username>
Replace <username> with the actual username of the user running the script. In ROCK boards, it will be either ‘rock’ or ‘radxa’ by default.
Log out and log back in to apply the group membership changes.
After following these steps, you should be able to run the Python code that uses libmraa without requiring sudo privileges. The user running the script will have the necessary permissions to access the GPIO pins.
idle gpio.py
This will cause the LED to blink on and off every second.
If you have followed the steps above, you will have successfully completed installation, execution, editing of python code and controlling of GPIO pins from inside IDLE IDE without a root access.
What’s your challenge? From augmented reality to machine learning and automation, send us your questions, problems or ideas… We have the solution to help you design the world. Get in touch today.
Van een snelle tik tot het verpletteren van die liefdesknop en laat zien hoeveel plezier je aan dit project hebt beleefd.