Voor het gebruik van een 20x4 I2C display met Domoticz op de RPi.
Ik heb de tutorial van "TheRaspberryPiGuy" gebruikt. Voor meer info hierover verwijs ik u door naar zijn
YouTube video.
Het script heb ik gemaakt met behulp van het script van MikeF @ Domoticz.com.
Als eerste verbind de 4 pinnen van de I2C display aan de GPIO van de RPi als volgt.
I2C -> GPIO
GND -> Pin 6 (Ground)
VCC -> Pin 2 (5V)
SDA -> Pin 3 (SDA)
SCL -> Pin 5 (SCL)
Start de RPi, login via Putty of een andere SSH client en voer de volgende regels in.
Alle benodigde packages worden nu geïnstalleerd en hierna zal de RPi rebooten.
Om te testen of alles werkt type het volgende.
cd lcd
python demo_lcd.py
Er wordt nu een demo tekst op de display weergegeven. Deze kunt u stoppen met "CTRL-C".
Mocht u geen of slecht beeld krijgen, verdraai de potmeter van de I2C module tot u beeld krijgt.
Mocht de display niet worden aangesproken verander dan het lcddriver.py script.
sudo nano lcddriver.py
Verander de volgende regel in het script. Test hierna opnieuw.
"ADDRESS = 0x20" naar "ADDRESS = 0x3f"
Start WINSCP en ga naar /home/pi/lcd en maak een nieuw bestand genaamd status.py.
Kopieer het volgende in het status.py script:
# Simple status program for Domoticz
# This program is created for the I2C 20x4 Display
# Created by Matthew Timmons-Brown for The Raspberry Pi Guy YouTube channel. Editted to work with Domoticz by MyBearTibbers.
# Import necessary libraries for commuunication and display use
import lcddriver
from time import ctime
import datetime
import os
import subprocess
import unicodedata
import urllib, json
# Configuration
cfgDomoticzHost = "<username>:<password>@<DomoticzIP>:<Port>"
def get_domoticz_sensor(idx):
url = "http://"+str(cfgDomoticzHost)+"/json.htm?type=devices&rid="+str(idx)
response = urllib.urlopen(url);
data = json.loads(response.read())
if data["status"] == "OK":
return data["result"][0]
def get_domoticz_info(result):
url = "http://"+str(cfgDomoticzHost)+"/json.htm?type=command¶m=checkforupdate&forced=true"
response = urllib.urlopen(url);
data = json.loads(response.read())
if data["status"] == "OK":
return data[result]
ch = unichr(0xFF)
deg = " C"
# Load the driver and set it to "display"
# If you use something from the driver library use the "display." prefix first
display = lcddriver.lcd()
try:
print("Writing to display")
display.lcd_display_string(" Domoticz", 1) # Write line of text to first line of display
while True:
display.lcd_display_string(str(datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")), 2)
display.lcd_display_string(" TempBinnen: " + str(get_domoticz_sensor(<idx>)["Temp"]) + deg, 3)
display.lcd_display_string(" TempBuiten: " + str(get_domoticz_sensor(<idx>)["Temp"]) + deg, 4)
# Write just the time to the display
# Program then loops with no delay (Can be added with a time.sleep)
except KeyboardInterrupt: # If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
print("Cleaning up!")
display.lcd_clear()
Verander in de volgende regels:
cfgDomoticzHost = "<username>:<password>@<DomoticzIP>:<Port>"
display.lcd_display_string(" TempBinnen: " + str(get_domoticz_sensor(<idx>)["Temp"]) + deg, 3)
display.lcd_display_string(" TempBuiten: " + str(get_domoticz_sensor(<idx>)["Temp"]) + deg, 4)
<username>:<password>@<DomoticzIP>:<Port> spreekt voor zich.
<idx> dit is het idx nummer van uw temperatuur sensor. Deze kunt u vinden in het Devices menu van Domoticz.
Nu gaan we het script automatisch starten na elke reboot.
Start Putty en maak een crontab.
crontab -e
En voeg onderaan deze regel toe.
@reboot /bin/sleep 60 ; /usr/bin/python /home/pi/lcd/status.py
Reboot and enjoy!