Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5151

Beginners • Re: Help with connecting libraries

$
0
0
We normally use the import statement in Python to use librarie e.g.

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)
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.)

Code:

pip install rpi-lgpio
If the Pi is running Bookworm, we (I) normally create a python virtual environment (venv) with system packages:

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



Viewing all articles
Browse latest Browse all 5151

Trending Articles