Weather-Station

Værstasjon med raspberry PI pluss SenseHat:

Programkode:


# reading and writing to the sensehat with python

from sense_hat import SenseHat
# from sense_emu import SenseHat
from time import sleep

mySenHa = SenseHat()

i = 1
while i < 6:

    mySenHa.show_message("Weather Station:", text_colour = [100,200,150])

    mySenHa.load_image("/home/pi/Desktop/raspberry.jpg")
    sleep(3)
    mySenHa.show_message("Humidity:", text_colour = [100,200,150])
    myHumidity = mySenHa.get_humidity()
    myHumidity = round(myHumidity,1)
    humidString = str(myHumidity)
    mySenHa.show_message(humidString)


    mySenHa.load_image("/home/pi/Desktop/raspberry.jpg")
    sleep(3)

    mySenHa.show_message("Temperature:", text_colour = [100,200,150])
    myTemperature = mySenHa.get_temperature()
    myTemperature = round(myTemperature, 1)
    temperatureString = str(myTemperature)
    mySenHa.show_message(temperatureString)

    mySenHa.load_image("/home/pi/Desktop/raspberry.jpg")
    sleep(3)

    mySenHa.show_message("Pressure:", text_colour = [100,200,150])
    myPressure = mySenHa.get_pressure()
    myPressure = round(myPressure, 1)
    pressureString = str(myPressure)
    mySenHa.show_message(pressureString)

    mySenHa.load_image("/home/pi/Desktop/raspberry.jpg")
    sleep(3)


Programmet ble lagret på Desktop.

For å få programmet til å kjøre «fint» så lagrer jeg denne lille jpg filen på Desktop

For å få dette programmet til å starte automatisk, så redigerte jeg litt i finen /etc/rc.local

Det var nødvendig å bruke Linux shell og kommando «sudo nano /etc/rc.local» for å
få tilstrekkelige rettigheter til å endre denne filen. Filen ble slik etter endring:


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

python /home/pi/Desktop/wstation.py

exit 0

Noen syntakseksempler for PiHat: