import RPi.GPIO as GPIO import time from ADCDevice import * ledPin = 11 # define ledPin adc = ADCDevice() # Define an ADCDevice class object def setup(): global adc if(adc.detectI2C(0x48)): # Detect the pcf8591. adc = PCF8591() elif(adc.detectI2C(0x4b)): # Detect the ads7830 adc = ADS7830() else: print("No correct I2C address found, \n" "Please use command 'i2cdetect -y 1' to check the I2C address! \n" "Program Exit. \n"); exit(-1) global p GPIO.setmode(GPIO.BOARD) GPIO.setup(ledPin,GPIO.OUT) # set ledPin to OUTPUT mode GPIO.output(ledPin,GPIO.LOW) p = GPIO.PWM(ledPin,1000) # set PWM Frequence to 1kHz p.start(0) def loop(): while True: value = adc.analogRead(0) # read the ADC value of channel 0 p.ChangeDutyCycle(value*100/255) voltage = value / 255.0 * 3.3
from time import * from RPi import GPIO from ADCDevice import * adc = ADCDevice() pwmPin = 11 def setup(): global adc if adc.detectI2C(0x48): adc = PCF8591() elif adc.detectI2C(0x4b): adc = ADS7830() else: print( "No correct I2C address found \n" "Please use command 'i2cdetect -y 1' to check the I2C address! \n" "Programm exit. \n") exit(-1) GPIO.setmode(GPIO.BOARD) GPIO.setup(pwmPin, GPIO.OUT) global f f = GPIO.PWM(pwmPin, 1000) f.start(0) def loop(): while True: value = adc.analogRead(0) voltage = value / 255.0 * 3.3
import sys import Adafruit_DHT as dht import time from ADCDevice import * from urllib.request import urlopen from time import sleep adc = ADCDevice() # Enter Your API key here myAPI = '5KJ5TVQRF5NFSEXL' # URL where we will send the data, Don't change it baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI def DHT22_data(): # Reading from DHT22 and storing the temperature and humidity humi, temp = dht.read_retry(dht.DHT22, 4) return humi, temp def setup(): global adc if (adc.detectI2C(0x48)): # Detect the pcf8591. adc = PCF8591() elif (adc.detectI2C(0x4b)): # Detect the ads7830 adc = ADS7830() else: print( "No correct I2C address found, \n" "Please use command 'i2cdetect -y 1' to check the I2C address! \n"
import sys import time from ADCDevice import * from time import sleep adc = ADCDevice() def DHT22_data(): # Reading from DHT22 and storing the temperature and humidity humi, temp = dht.read_retry(dht.DHT22, 4) return humi, temp def setup(): global adc if (adc.detectI2C(0x4b)): # Detect the ads7830 adc = ADS7830() else: print( "No correct I2C address found, \n" "Please use command 'i2cdetect -y 1' to check the I2C address! \n" "Program Exit. \n") exit(-1) setup() while True: try: if (adc is not None):