Raspberry Pi
Tutorial de Rapberry Pi en español.
- Juan Antonio Villalpando -
Volver al índice del tutorial
____________________________
4.- Potenciómetro.
______________________________
1.- Conexión.
- Raspberry Pi no tiene entrada analógica, como sí la tiene el Arduino.
- Podemos añadir un integrado tal como el MCP3002 o el MCP3008.
- En nuestro caso vamos a utilizar un condensador y consultar el tiempo que tarda en llegar a un determinado valor de tensión.
- El tiempo de carga de un condensador es T = 5 R C
- En nuestro caso haremos la lectura cuando alcance el 10% de ese valor, es decir: 0,5 R C
https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi/how-it-works
______________________________
2.- Código.
http://www.doctormonk.com/2013/12/analog-sensors-without-analog-inputs-on.html
- En este código las conexiones están en BCM, es decir están nombradas mediante su número de GPIO.
|
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
a_pin = 18
b_pin = 23
def descarga():
GPIO.setup(a_pin, GPIO.IN)
GPIO.setup(b_pin, GPIO.OUT)
GPIO.output(b_pin, False)
time.sleep(0.005)
def tiempo_de_carga():
GPIO.setup(a_pin, GPIO.OUT)
GPIO.setup(b_pin, GPIO.IN)
count = 0
GPIO.output(a_pin, True)
while not GPIO.input(b_pin):
count = count + 1
return count
def analog_read():
descarga()
return tiempo_de_carga()
while True:
print(analog_read())
time.sleep(1)
|
______________________________
3.- LDR.
https://www.raspberrypi-spy.co.uk/2012/08/reading-analogue-sensors-with-one-gpio-pin/
http://topelectronicpro.blogspot.com/2016/04/analogue-input-on-raspberry-pi.html
|
import RPi.GPIO as GPIO, time, os
GPIO.setmode(GPIO.BCM)
def RCtime(RCPin):
reading = 0
GPIO.setup(RCpin GPIO.OUT)
GPIO.output(RCpin. GPIO.LOW)
times.sleep(0.5)
GPIO.setup(RCpin, GPIO.IN)
while (GPIO.input(RCpin) == GPIO.LOW):
reading += 1
return reading
while True:
print RCtime(17)
GPIO pin
|
Analogico https://www.electronicwings.com/raspberry-pi/dht11-interfacing-with-raspberry-pi
https://www.raspberrypi-spy.co.uk/2012/08/reading-analogue-sensors-with-one-gpio-pin/
https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi/basic-photocell-reading
http://www.doctormonk.com/2013/12/analog-sensors-without-analog-inputs-on.html
___________________________________________________
|