A collection of examples for using the gpiozero library for reading sensors and activating actuators
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
944 B

from gpiozero import MCP3008
from time import sleep
##################
# Before you start #
##################
# remember to enable SPI in raspi-config > interfaces before you run this the first time
# see method one here: https://www.raspberrypi-spy.co.uk/2014/08/enabling-the-spi-interface-on-the-raspberry-pi/
#################
# Wiring MCP3008 #
################
# https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters/mcp3008
# gpiozero documentation about MCP3008: https://gpiozero.readthedocs.io/en/stable/api_spi.html
#################
# Wiring sensors #
#################
# This code assumes you have an LDR on channel 0 of the mcp3008
# You can wire one up like so: https://maker.pro/raspberry-pi/tutorial/how-to-read-an-ldr-sensor-with-raspberry-pi-using-mcp3008
# However, you could use any other analog sensor (up to eight)
ldr = MCP3008(channel=0, device=0)
while True:
print(ldr.value)
sleep(0.01)