We normally use the import statement in Python to use librarie e.g. you will need to install the libraries to the Pi first (like we do in the Arduino IDE), usually using pip (that gets it from the network PyPi etc.)If the Pi is running Bookworm, we (I) normally create a python virtual environment (venv) with system packages:
Code:
# blink.py (put LED + resistor on GPIO21 and GND)import RPi.GPIO as GPIOimport timemyled=21GPIO.setmode(GPIO.BCM)GPIO.setwarnings(False)GPIO.setup(myled,GPIO.OUT)print ("Using RPi.GPIO with LED on GPIO",myled)while True: GPIO.output(myled,GPIO.HIGH) time.sleep(1) GPIO.output(myled,GPIO.LOW) time.sleep(1)
Code:
pip install rpi-lgpio
Code:
mkdir my_projectcd my_projectpython -m venv --system-site-packages envsource env/bin/activate
Statistics: Posted by neilgl — Fri Jul 26, 2024 1:30 pm