#5 Yenc
tak jsem na to prisel... mel jsem spatne ocislovane piny (zapojene) :) ted uz to jede... diky vsem
Příspěvky odeslané z IP adresy 37.188.139.–
hehe chyba nalezena, dal jsem except na zacatek radku :)
ted jedna teoreticka.. chapu to dobre jak to mam napsane, ze:
temp1 = read_temp(0)
R1Max = 30
R1Min = 24
R2Max = 33
R2Min = 26
if (temp1 >= R1Max):
GPIO.output(Rele1, GPIO.LOW)
# (GPIO.output(Rele2, GPIO.LOW)
if (temp1 <= R1Min):
GPIO.output(Rele1, GPIO.HIGH)
Pokud je temp1 vetsi nebo rovno R1Max tak nastavi gpio pro rele1 na low
a zase pokud je mensi nebo rovno R1Min, tak nastavi gpio rele1 na high?
tak jsem to udelal dle toho co pises (aspon si to tedy myslim) a zase chyba.. kod je tady:
#!/usr/bin/env python
import os
import glob
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
#Rele 1 pripojeno na pin 8 [gpio 14]
#Rele 2 pripojeno na pin 10 [gpio 15]
#Rele 3 pripojeno na pin 12 [gpio 18]
#Rele 4 pripojeno na pin 16 [gpio 23]
Relay1 = 8
Relay2 = 10
Relay3 = 12
Relay4 = 16
pinList = [Relay1, Relay2, Relay3 , Relay4]
# Turn both relays off to start with
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + "28*")[0]
device_file = [device_folder + "/w1_slave"]
# vycteni teploty
def read_temp_raw(device):
"""Pass this function either 0 or 1 to get the raw data from the
Temperature Sensor"""
f = open(device_file[device], 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(device):
"""Pass 0 or 1 to get the temperature in celcius of either sensor"""
lines = read_temp_raw(device)
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw(device)
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
# urceni zapinani rele v zavislosti na teplote
while True:
try:
temp1 = read_temp(0)
R1Max = 30
R1Min = 24
R2Max = 33
R2Min = 26
if (temp1 >= R1Max):
GPIO.output(Rele1, GPIO.LOW)
# (GPIO.output(Rele2, GPIO.LOW)
if (temp1 <= R1Min):
GPIO.output(Rele1, GPIO.HIGH)
# GPIO.output(Rele2, GPIO.HIGH)
if (temp1 >= R2Max):
GPIO.output(Rele2, GPIO.LOW)
# (GPIO.output(Rele4, GPIO.LOW)
if (temp1 <= R2Min):
GPIO.output(Rele2, GPIO.HIGH)
# (GPIO.output(Rele4, GPIO.HIGH)
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
syntaxerror unindent does not match any outer indentation level
except KeyboardInterrupt:
^
Diky za radu
ahoj, snad mi dokazete poradit (urcite ano :D)
s pythonem jsem si zacal hrat celkem nedavno, takze jeste porad vse nechapu ale tak nejak to jde :D
nyni bych chtel ovladat rele podle teploty ale nemuzu prijit na to, kde je chyba. muzete pls kouknout a poradit?
#!/usr/bin/env python
import os
import glob
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
#Rele 1 pripojeno na pin 8 [gpio 14]
#Rele 2 pripojeno na pin 10 [gpio 15]
#Rele 3 pripojeno na pin 12 [gpio 18]
#Rele 4 pripojeno na pin 16 [gpio 23]
Relay1 = 8
Relay2 = 10
Relay3 = 12
Relay4 = 16
pinList = [Relay1, Relay2, Relay3 , Relay4]
# Turn both relays off to start with
for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + "28*")[0]
device_file = device_folder + "/w1_slave"
# vycteni teploty
def read_temp_raw(device):
"""Pass this function either 0 or 1 to get the raw data from the
Temperature Sensor"""
f = open(device_file[device], 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(device):
"""Pass 0 or 1 to get the temperature in celcius of either sensor"""
lines = read_temp_raw(device)
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw(device)
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
# urceni zapinani rele v zavislosti na teplote
while True:
try:
temp1 = read_temp
R1Max = 30
R1Min = 24
R2Max = 33
R2Min = 26
if (temp1 >= R1Max):
GPIO.output(Rele1, GPIO.LOW)
# (GPIO.output(Rele2, GPIO.LOW)
if (temp1 <= R1Min):
GPIO.output(Rele1, GPIO.HIGH)
# GPIO.output(Rele2, GPIO.HIGH)
if (temp1 >= R2Max):
GPIO.output(Rele2, GPIO.LOW)
# (GPIO.output(Rele4, GPIO.LOW)
if (temp1 <= R2Min):
GPIO.output(Rele2, GPIO.HIGH)
# (GPIO.output(Rele4, GPIO.HIGH)
time.sleep(1)
Vysledek mi to vypise:
syntax error unexpected eof while parsing
diky za pomoc