Kombiniert
In diesem Programm wurden die meisten der Sensoren für die Wetterstation zusammengefügt.

Eine Liste der enthaltenen Sensoren

Das Programm:

import time
import RPi.GPIO as GPIO
import math
from gpiozero import Button
from gpiozero import MCP3008
GPIO.setmode(GPIO.BOARD)
Niederschlag = 0
N = 2
adc = MCP3008(channel=0)
windrichtung = {0.4: "Norden", 1.4: "Nordnordosten", 1.2: "Nordosten", 2.8: "Ostostnorden", 2.7: "Osten", 2.9:"Ostostsüden", 2.2:"Südosten", 2.5:"Südsüdosten", 1.8:"Süden", 2.0:"Südsüdwesten", 0.7:"Südwesten", 0.8:"Westwestsüden", 0.1:"Westen", 0.3:"Westwestnorden", 0.2:"Nordwesten", 0.6:"Nordnordwesten"} 
y = "Norden"
j = "100"
f = 0
k = 0
radius_cm = 9.0
zeit = time.time()
km_per_hour = 0
sensor_path = "/sys/bus/w1/devices/28-00000ade081f/w1_slave"
wind_speed_sensor = Button(5)
Regensensor = Button(N)
old = 5
 
def halfturn():
        global zeit
        global km_per_hour
        zeit2 = time.time()
        diff = zeit2 - zeit
        zeit = zeit2
        circumference_cm = math.pi * radius_cm
        speed_cm_per_sec = circumference_cm / diff
        km_per_sec = speed_cm_per_sec / 100000.0
        km_per_hour = km_per_sec * 3600
 
wind_speed_sensor.when_pressed = halfturn
 
def get_temp():
        f = open(sensor_path, 'r')
        content = f.readlines()
        f.close()
        temp = "error"
        if (content[0].strip())[-3:] == "YES":
                index = content[-1].find('t=')
                if index != -1:
                        temp = float(content[-1][index+2:-1].strip())
                        temp = temp/1000.0
        return temp
 
def Temperatur():
        temperatur = get_temp()
        temperatur = round(temperatur, 1)
        return str(temperatur) + "°C"
 
def Windrichtung():
        x  =round(adc.value*3.3,1)
        if x in windrichtung:
                return windrichtung[x]
 
def Niederschlagssensor():
        global Niederschlag
        Niederschlag = Niederschlag + 0.1397
 
Regensensor.when_pressed = Niederschlagssensor
 
while True:
        b = Windrichtung()
        a = Temperatur()
        Zeit3 = time.time()
        if Zeit3 - zeit > 3:
                km_per_hour = 0
 
#       time.sleep(0.5)
        c = km_per_hour = round(km_per_hour, 1)
        if b != y:
                print("Temperatur: " + a + "    " +  "Windrichtung: " + b + "    " + "Windgeschwindigkeit: " + str(km_per_hour) + "km/h"  + "    " + str(round(Niederschlag, 1)) + "mm")
                y = b
        elif j != a:
                print("Temperatur: " + a + "    " +  "Windrichtung: " + b + "    " + "Windgeschwindigkeit: " + str(km_per_hour) + "km/h" + "    " + str(round(Niederschlag, 1)) + "mm")
                j = a
        elif k != c:
                print("Temperatur: " + a + "    " +  "Windrichtung: " + b + "    " + "Windgeschwindigkeit: " + str(km_per_hour) + "km/h" + "    " + str(round(Niederschlag, 1)) + "mm")
                k = c
        elif f != Niederschlag:
                print("Temperatur: " + a + "    " +  "Windrichtung: " + b + "    " + "Windgeschwindigkeit: " + str(km_per_hour) + "km/h" + "    " + str(round(Niederschlag, 1)) + "mm")
                f = Niederschlag