Learning Python


I learned to use Python on my Raspberry Pis. Building electronic circuits on the breadboard and controlling them with a Python program is a lot of fun.

BTW, the electronic circuit kits I bought came with Python and C code. Unfortunately, the code was developed to run on Raspberry Pi 3 and 4s. The code as is doesn't t work on a Raspberry Pi 5 because the architecture changed on it causing the libraries to break. I had to rewrite the code using compatible libraries.

You might try a headless boot of the Raspberry Pi 5 and control it with a laptop. I keep my Raspberry Pi 5 on a coffee table and plug it in when I want to use it. Using the laptop saves having to go and get a monitor, keyboard and mouse.

Actually learning Python was the easiest part. Learning to use the libraries was harder. The libraries are used to communicate with the Rapsberry Pi GPIO pins

Here is the Python code used to control a dual-color LED on the breadboard. The library used is called gpiozero.

#!/usr/bin/env python3
#modified for Raspberry Pi 5
from gpiozero import PWMLED
import time

colors = [0xFF00, 0x00FF, 0xFFFF, 0x0000]
pins = (17, 18) # pins is a dict GPIO17, GPIO18

def map(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min

def setup():
p_R = PWMLED(pins[0], frequency = 2000) # set Frequece to 2KHz
p_G = PWMLED(pins[1], frequency = 2000)
p_R.off() # Initial duty Cycle = 0(leds off)
p_G.off()
return p_R, p_G

def setColor(col): # For example : col = 0x1122
R_val = col >> 8
G_val = col & 0x00FF

R_val = map(R_val, 0, 255, 0, 1)
G_val = map(G_val, 0, 255, 0, 1)

p_R.value = R_val # Change duty cycle
p_G.value = G_val

def loop():
while True:
for col in colors:
setColor(col)
time.sleep(3)

def destroy():
p_R.off()
p_G.off()

if __name__ == "__main__":
p_R, p_G = setup()
try:
loop()
except KeyboardInterrupt:
destroy()
 
Last edited:

My Computers My Computers

  • At a glance

    Windows 11 Pro 25H2 (26200.6901)AMD Ryzen 7 6800H with Radeon 680M GPU (486MB...Crucial DDR5-4800 (2400MHz) 32GB (2 x 16GB)NVIDIA RTX 3060 Laptop (6GB RAM)
    OS
    Windows 11 Pro 25H2 (26200.6901)
    Computer type
    Laptop
    Manufacturer/Model
    ASUS TUF Gaming A15 (2022)
    CPU
    AMD Ryzen 7 6800H with Radeon 680M GPU (486MB RAM)
    Memory
    Crucial DDR5-4800 (2400MHz) 32GB (2 x 16GB)
    Graphics Card(s)
    NVIDIA RTX 3060 Laptop (6GB RAM)
    Sound Card
    n/a
    Monitor(s) Displays
    15.6-inch
    Screen Resolution
    1920x1080 300Hz
    Hard Drives
    2 x Samsung 990 Evo Plus (2TB M.2 NVME SSD)
    PSU
    n/a
    Mouse
    Wireless Mouse M510
    Internet Speed
    2100Mbps/300Mbps
    Browser
    Firefox
    Antivirus
    Malwarebytes
  • At a glance

    Windows 11 Pro 25H2 (26200.8246)AMD Ryzen 7 5700X3DG.SKILL Flare X 32GB (2x16GB) DDR4ASUS ROG-STRIX-RTX3060TI-08G-V2-GAMING (RTX 3...
    Operating System
    Windows 11 Pro 25H2 (26200.8246)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom build
    CPU
    AMD Ryzen 7 5700X3D
    Motherboard
    ASUS ROG Strix B550-F Gaming WiFi II
    Memory
    G.SKILL Flare X 32GB (2x16GB) DDR4
    Graphics card(s)
    ASUS ROG-STRIX-RTX3060TI-08G-V2-GAMING (RTX 3060-Ti, 8GB RAM)
    Monitor(s) Displays
    Samsung G50D IPS 27"
    Screen Resolution
    1440p/180Hz
    Hard Drives
    SAMSUNG 990 EVO Plus (2TB] M.2 NVME SSD
    SAMSUNG 990 EVO Plus (4TB) M.2 NVME SSD
    PSU
    Corsair RM750x (750 watts)
    Case
    Cooler Master MasterCase 5
    Cooling
    Scythe Mugen 6
    Keyboard
    Logitech K520 (MK540 keyboard/mouse combo)
    Mouse
    Logitech M310 (MK540 keyboard/mouse combo)
    Internet Speed
    2100 Mbps down / 300 Mbps up
    Browser
    Firefox, Edge, Chrome
    Antivirus
    Malwarebytes (Premium)
    Other Info
    ASUS Blu-ray Burner BW-16D1HT (SATA) || Western Digital Easystore 20TB USB 3.0 external hard drive used with Acronis True Image 2025 backup software || HP OfficeJet Pro 6975 Printer/Scanner
I learned to use Python on my Raspberry Pis. Building electronic circuits on the breadboard and controlling them with a Python program is a lot of fun.

BTW, the electronic circuit kits I bought came with Python and C code. Unfortunately, the code was developed to run on Raspberry Pi 3 and 4s. The code as is doesn't t work on a Raspberry Pi 5 because the architecture changed on it causing the libraries to break. I had to rewrite the code using compatible libraries.

You might try a headless boot of the Raspberry Pi 5 and control it with a laptop. I keep my Raspberry Pi 5 on a coffee table and plug it in when I want to use it. Using the laptop saves having to go and get a monitor, keyboard and mouse.
What’s a headless boot?
 

My Computer My Computer

At a glance

Windows 11 Pro - version 24H2AMD Ryzen 5 7600X 6 Core AM5 5.3GHz CPUSilicon Power XPOWER Zenith 32GB (16GBx2) CL3...MSI GeForce RTX 4060 Ventus 2X Black 8G OC Gr...
OS
Windows 11 Pro - version 24H2
Computer type
PC/Desktop
CPU
AMD Ryzen 5 7600X 6 Core AM5 5.3GHz CPU
Motherboard
2024 MSI MAG B650 GAMING PLUS WIFI
Memory
Silicon Power XPOWER Zenith 32GB (16GBx2) CL30,1.35V UDIMM 6000MHz DDR5 RAM
Graphics Card(s)
MSI GeForce RTX 4060 Ventus 2X Black 8G OC Graphics Card
Monitor(s) Displays
Asus ROG Strix XG32WCS - 32in HDR VA 180Hz USB Type-C FreeSync Curved Gaming Monitor
Screen Resolution
2560 x 1440
Hard Drives
1) Silicon Power 1TB P34A60 Gen3x4 TLC R/W up to 2,200/1,600 MB/s PCIe M.2 NVMe SSD

2) Crucial 1TB E100 CT1000E100SSD8 Gen4 M.2 NVMe SSD
PSU
MSI 750W MAG A750GL 80+ Gold PCIe 5 ATX 3.0 Modular Power Supply
Case
SilverStone Fara R1 Pro V2 Tempered Glass ATX Case - Black
Cooling
Thermalright Peerless Assassin 120 SE ARGB Dual Loop CPU Cooler, 120mm Fan
Antivirus
Microsoft Defender
What’s a headless boot?

A headless boot in Windows 11 refers to the system starting up without a display, keyboard, or mouse connected — in other words, no monitor ("head") or user input devices.
 

My Computers My Computers

  • At a glance

    Windows 11 Pro 25H2 Build 26200.8655Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz32.0 GB of I forget and the box is in storage.Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    OS
    Windows 11 Pro 25H2 Build 26200.8655
    Computer type
    PC/Desktop
    Manufacturer/Model
    Sin-built 2013
    CPU
    Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz
    Motherboard
    ASUS ROG Maximus VI Formula
    Memory
    32.0 GB of I forget and the box is in storage.
    Graphics Card(s)
    Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    Sound Card
    Onboard thingy
    Monitor(s) Displays
    5 x LG 25MS500-B - 1 x 24MK430H-B - 1 x Wacom Pro 22" Touch Screen Tablet
    Screen Resolution
    All over the place
    Hard Drives
    Too many to list.
    OS on Samsung 1TB 870 QVO SATA
    PSU
    Silverstone 1500
    Case
    NZXT Phantom 820 Full-Tower Case
    Cooling
    Noctua NH-D15 Elite Class Dual Tower CPU Cooler / 6 x EziDIY 120mm / 2 x Corsair 140mm somethings / 1 x 140mm Thermaltake something / 2 x 200mm Corsair.
    Keyboard
    Corsair K95 / Logitech diNovo Edge Wireless
    Mouse
    Logitech: G402 / G502 / Mx Masters / Mx Air Cordless
    Internet Speed
    2000/500Mbps
    Browser
    All sorts
    Antivirus
    Kaspersky Premium
    Other Info
    ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    TP-Link BE9300 WiFi 7 Bluetooth 5.4 (Archer TBE550E)
    TP-Link TX201 V1 2.5GB Lan

    Grandstream HT812 - VoIP
    ASUS DSL-AX82U - Mesh
    ASUS RT-AC68U - Mesh
    ASUS RT-BE88U Router

    Brother MFC-L2880DW Printer

    I’m on a horse.
  • At a glance

    Windows 11 Pro 25H2 Build 26200.8655Intel Core 12th Gen i5-1240P Processor (1.7 -...16GB LPDDR5 RAMIntel Iris Xe Graphics Processor
    Operating System
    Windows 11 Pro 25H2 Build 26200.8655
    Computer type
    Laptop
    Manufacturer/Model
    LENOVO Yoga 7 14IRL8 - 7i EVO OLED 14" Touchscreen i5 12 Core 16GB/512GB
    CPU
    Intel Core 12th Gen i5-1240P Processor (1.7 - 4.4GHz)
    Memory
    16GB LPDDR5 RAM
    Graphics card(s)
    Intel Iris Xe Graphics Processor
    Sound Card
    Optimized with Dolby Atmos®
    Screen Resolution
    QHD 2880 x 1800 OLED
    Hard Drives
    M.2 512GB
    Antivirus
    Defender / Malwarebytes
    Other Info
    …still on a horse.
From memory reading about it, It's a process. Strap in lol
Probably not difficult for those of whom have done it.
 

My Computers My Computers

  • At a glance

    Windows 11 Pro 25H2 Build 26200.8655Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz32.0 GB of I forget and the box is in storage.Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    OS
    Windows 11 Pro 25H2 Build 26200.8655
    Computer type
    PC/Desktop
    Manufacturer/Model
    Sin-built 2013
    CPU
    Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz
    Motherboard
    ASUS ROG Maximus VI Formula
    Memory
    32.0 GB of I forget and the box is in storage.
    Graphics Card(s)
    Gigabyte nVidia GeForce GTX 1660 Super OC 6GB
    Sound Card
    Onboard thingy
    Monitor(s) Displays
    5 x LG 25MS500-B - 1 x 24MK430H-B - 1 x Wacom Pro 22" Touch Screen Tablet
    Screen Resolution
    All over the place
    Hard Drives
    Too many to list.
    OS on Samsung 1TB 870 QVO SATA
    PSU
    Silverstone 1500
    Case
    NZXT Phantom 820 Full-Tower Case
    Cooling
    Noctua NH-D15 Elite Class Dual Tower CPU Cooler / 6 x EziDIY 120mm / 2 x Corsair 140mm somethings / 1 x 140mm Thermaltake something / 2 x 200mm Corsair.
    Keyboard
    Corsair K95 / Logitech diNovo Edge Wireless
    Mouse
    Logitech: G402 / G502 / Mx Masters / Mx Air Cordless
    Internet Speed
    2000/500Mbps
    Browser
    All sorts
    Antivirus
    Kaspersky Premium
    Other Info
    ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    TP-Link BE9300 WiFi 7 Bluetooth 5.4 (Archer TBE550E)
    TP-Link TX201 V1 2.5GB Lan

    Grandstream HT812 - VoIP
    ASUS DSL-AX82U - Mesh
    ASUS RT-AC68U - Mesh
    ASUS RT-BE88U Router

    Brother MFC-L2880DW Printer

    I’m on a horse.
  • At a glance

    Windows 11 Pro 25H2 Build 26200.8655Intel Core 12th Gen i5-1240P Processor (1.7 -...16GB LPDDR5 RAMIntel Iris Xe Graphics Processor
    Operating System
    Windows 11 Pro 25H2 Build 26200.8655
    Computer type
    Laptop
    Manufacturer/Model
    LENOVO Yoga 7 14IRL8 - 7i EVO OLED 14" Touchscreen i5 12 Core 16GB/512GB
    CPU
    Intel Core 12th Gen i5-1240P Processor (1.7 - 4.4GHz)
    Memory
    16GB LPDDR5 RAM
    Graphics card(s)
    Intel Iris Xe Graphics Processor
    Sound Card
    Optimized with Dolby Atmos®
    Screen Resolution
    QHD 2880 x 1800 OLED
    Hard Drives
    M.2 512GB
    Antivirus
    Defender / Malwarebytes
    Other Info
    …still on a horse.
When I run the Raspberry Pi 5 headless like it was said I don't use a keyboard, mouse or monitor. All I do is plug in the Raspberry Pi 5, wait a minute for it to boot then connect to it from my laptop. Note there is some configuration to do for this to happen. It took some time for me to figure out how to do this.

headless.webp
 

My Computers My Computers

  • At a glance

    Windows 11 Pro 25H2 (26200.6901)AMD Ryzen 7 6800H with Radeon 680M GPU (486MB...Crucial DDR5-4800 (2400MHz) 32GB (2 x 16GB)NVIDIA RTX 3060 Laptop (6GB RAM)
    OS
    Windows 11 Pro 25H2 (26200.6901)
    Computer type
    Laptop
    Manufacturer/Model
    ASUS TUF Gaming A15 (2022)
    CPU
    AMD Ryzen 7 6800H with Radeon 680M GPU (486MB RAM)
    Memory
    Crucial DDR5-4800 (2400MHz) 32GB (2 x 16GB)
    Graphics Card(s)
    NVIDIA RTX 3060 Laptop (6GB RAM)
    Sound Card
    n/a
    Monitor(s) Displays
    15.6-inch
    Screen Resolution
    1920x1080 300Hz
    Hard Drives
    2 x Samsung 990 Evo Plus (2TB M.2 NVME SSD)
    PSU
    n/a
    Mouse
    Wireless Mouse M510
    Internet Speed
    2100Mbps/300Mbps
    Browser
    Firefox
    Antivirus
    Malwarebytes
  • At a glance

    Windows 11 Pro 25H2 (26200.8246)AMD Ryzen 7 5700X3DG.SKILL Flare X 32GB (2x16GB) DDR4ASUS ROG-STRIX-RTX3060TI-08G-V2-GAMING (RTX 3...
    Operating System
    Windows 11 Pro 25H2 (26200.8246)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Custom build
    CPU
    AMD Ryzen 7 5700X3D
    Motherboard
    ASUS ROG Strix B550-F Gaming WiFi II
    Memory
    G.SKILL Flare X 32GB (2x16GB) DDR4
    Graphics card(s)
    ASUS ROG-STRIX-RTX3060TI-08G-V2-GAMING (RTX 3060-Ti, 8GB RAM)
    Monitor(s) Displays
    Samsung G50D IPS 27"
    Screen Resolution
    1440p/180Hz
    Hard Drives
    SAMSUNG 990 EVO Plus (2TB] M.2 NVME SSD
    SAMSUNG 990 EVO Plus (4TB) M.2 NVME SSD
    PSU
    Corsair RM750x (750 watts)
    Case
    Cooler Master MasterCase 5
    Cooling
    Scythe Mugen 6
    Keyboard
    Logitech K520 (MK540 keyboard/mouse combo)
    Mouse
    Logitech M310 (MK540 keyboard/mouse combo)
    Internet Speed
    2100 Mbps down / 300 Mbps up
    Browser
    Firefox, Edge, Chrome
    Antivirus
    Malwarebytes (Premium)
    Other Info
    ASUS Blu-ray Burner BW-16D1HT (SATA) || Western Digital Easystore 20TB USB 3.0 external hard drive used with Acronis True Image 2025 backup software || HP OfficeJet Pro 6975 Printer/Scanner

Latest Support Threads

Back
Top Bottom