This is my collection of basic Raspberry Pi projects and helpful resources for those getting started with the Raspberry Pi ๐
- RPi.GPIO Python module basic documentation
- Projects ๐ก
- Blinking LED
- DHT11 Temperature and humidity sensor
- more coming soon...
- Helpful resources
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(pin_number, GPIO.IN)
GPIO.setup(pin_number, GPIO.OUT)
-- example
GPIO.setup(7, GPIO.OUT)
pin_numbers = [7,14]
GPIO.setup(pin_numbers, GPIO.OUT)
This will return either 0 / GPIO.LOW / False or 1 / GPIO.HIGH / True
GPIO.input(pin_number)
State can be 0 / GPIO.LOW / False or 1 / GPIO.HIGH / True
GPIO.output(pin_number, state)
-- example
GPIO.output(LedPin, GPIO.HIGH)
pin_numbers = [7,14]
GPIO.output(pin_numbers, GPIO.LOW) # sets all to GPIO.LOW
GPIO.output(pin_numbers, (GPIO.HIGH, GPIO.LOW)) # sets first HIGH and second LOW
You can clean up inividual channels or all channels like this:
GPIO.cleanup()
code: blink_led.py
Execute Python program in terminal:
python blink_led.py
- sensor DHT11
- code: temp_humid_sensor.py
- Clone a repository
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
- Install library
cd Adafruit_Python_DHT
sudo apt-get install build-essential python-dev
sudo python setup.py install
- Run code temp_humid_sensor.py
python temp_humid_sensor.py
credits: circuit.basics.com