hi people,
made project , want share all. hope you.
in project raspberry pi has totally 16 input are 8 analog , 8 digital. each input show , transmit 1 data in 15 mins. database use google spreadsheets. these data shown on the website daily, weekly, monthly, annual , last data.
programmed raspberry pi on phyton. website is html, css , javascript.
digital input: 0-24v
analog input: 0-10v
can see overview of project on picture below. the materials;
the circuit of digital inputs: the circuit of analog inputs:
note :i attached other pictures on next post because of picture limit.
selamlar,
coskun kozakbas
made project , want share all. hope you.
in project raspberry pi has totally 16 input are 8 analog , 8 digital. each input show , transmit 1 data in 15 mins. database use google spreadsheets. these data shown on the website daily, weekly, monthly, annual , last data.
programmed raspberry pi on phyton. website is html, css , javascript.
digital input: 0-24v
analog input: 0-10v
can see overview of project on picture below. the materials;
- raspberry pi 2 b
- mcp3008 adc
- 8x1k
- 8x470ohm
- 8x820ohm
- 8x4.7k
- 8x121ohm
- 8xled
the circuit of digital inputs: the circuit of analog inputs:
note :i attached other pictures on next post because of picture limit.
code: select all
# 8 analog - 8 digital input raspberry pi python code # # berufsakademie bautzen # # coskun kozakbas # import spidev import time import os import urllib import rpi.gpio gpio gpio.setmode(gpio.bcm) spi = spidev.spidev() spi.open(0,0) def readchannel(channel): adc = spi.xfer2([1,(8+channel)<<4,0]) data = ((adc[1]&3) << 8) + adc[2] return data def convertvolts(data,places): volts = (data * 10) / float(1023) volts = round(volts,places) return volts sensor1_channel = 0 sensor2_channel = 1 sensor3_channel = 2 sensor4_channel = 3 sensor5_channel = 4 sensor6_channel = 5 sensor7_channel = 6 sensor8_channel = 7 delay = 5 gpio.setwarnings(false) gpio.setup(5, gpio.in) gpio.setup(6, gpio.in) gpio.setup(13, gpio.in) gpio.setup(19, gpio.in) gpio.setup(26, gpio.in) gpio.setup(16, gpio.in) gpio.setup(20, gpio.in) gpio.setup(21, gpio.in) while true: foldtime = time.time() fnewtime = time.time() fstore = 900.0 # saniye while true: fnewtime = time.time() fdtime = fnewtime-foldtime digital1 = gpio.input(5) digital2 = gpio.input(6) digital3 = gpio.input(13) digital4 = gpio.input(19) digital5 = gpio.input(26) digital6 = gpio.input(21) digital7 = gpio.input(20) digital8 = gpio.input(16) if digital1 == 1: digital1 = 'on' else: digital1 = 'off' if digital2 == 1: digital2 = 'on' else: digital2 = 'off' if digital3 == 1: digital3 = 'on' else: digital3 = 'off' if digital4 == 1: digital4 = 'on' else: digital4 = 'off' if digital5 == 1: digital5 = 'on' else: digital5 = 'off' if digital6 == 1: digital6 = 'on' else: digital6 = 'off' if digital7 == 1: digital7 = 'on' else: digital7 = 'off' if digital8 == 1: digital8 = 'on' else: digital8 = 'off' sensor1_level = readchannel(sensor1_channel) sensor1_volts = convertvolts(sensor1_level,2) sensor2_level = readchannel(sensor2_channel) sensor2_volts = convertvolts(sensor2_level,2) sensor3_level = readchannel(sensor3_channel) sensor3_volts = convertvolts(sensor3_level,2) sensor4_level = readchannel(sensor4_channel) sensor4_volts = convertvolts(sensor4_level,2) sensor5_level = readchannel(sensor5_channel) sensor5_volts = convertvolts(sensor5_level,2) sensor6_level = readchannel(sensor6_channel) sensor6_volts = convertvolts(sensor6_level,2) sensor7_level = readchannel(sensor7_channel) sensor7_volts = convertvolts(sensor7_level,2) sensor8_level = readchannel(sensor8_channel) sensor8_volts = convertvolts(sensor8_level,2) if fdtime >= fstore: foldtime = fnewtime googlepage = "https://script.google.com/macros/s/" mygooglekey = "akfycbysdfsdfsdfsdfskqtjr_0wsgfjaskfqr6s21qtdsaleo9ojmhuqzf7bs" // wtime = time.strftime("%d/%m/%y %h:%m:%s") content = urllib.urlopen("%s%s/exec?date=%s&sensor1=%s&sensor2=%s&sensor3=%s&sensor4=%s&sensor5=%s&sensor6=%s&sensor7=%s&sensor8=%s&digital1=%s&digital2=%s&digital3=%s&digital4=%s&digital5=%s&digital6=%s&digital7=%s&digital8=%s" %(googlepage, mygooglekey, wtime, sensor1_volts, sensor2_volts, sensor3_volts, sensor4_volts, sensor5_volts, sensor6_volts, sensor7_volts, sensor8_volts, digital1, digital2, digital3, digital4, digital5, digital6, digital7, digital8)).read() print "-----------------------------------------------------------------------------" print(" sensor-1 sensor-2 sensor-3 sensor-4 sensor-5 sensor-6 sensor-7 sensor-8") print(" {} - ({}v) {} - ({}v) {} - ({}v) {} - ({}v) {} - ({}v) {} - ({}v) {} - ({}v) {} - ({}v)".format(sensor1_level,sensor1_volts,sensor2_level,sensor2_volts,sensor3_level,sensor3_volts,sensor4_level,sensor4_volts,sensor5_level,sensor5_volts,sensor6_level,sensor6_volts,sensor7_level,sensor7_volts,sensor8_level,sensor8_volts)) print(" digital-1 digital-2 digital-3 digital-4 digital-5 digital-6 digital-7 digital-8") print(" {} {} {} {} {} {} {} {} ".format(digital1,digital2,digital3,digital4,digital5,digital6,digital7,digital8)) time.sleep(delay)
selamlar,
coskun kozakbas
raspberrypi
Comments
Post a Comment