-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
executable file
·70 lines (52 loc) · 1.47 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /usr/bin/python3
# -*- coding: utf-8 -*-
import time
import sys
import lcddriver
import RPi.GPIO as GPIO
import math
GPIO.setmode(GPIO.BCM) #Zählweise der GPIO-PINS auf der Platine, analog zu allen Beispielen
GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) #Taster ist an GPIO-Pin 23 angeschlossen
#Schnittstellenbeschreibung
lcd = lcddriver.lcd() #LCD
EMULATE_HX711=False
referenceUnit = 1
if not EMULATE_HX711:
import RPi.GPIO as GPIO
from hx711 import HX711
else:
from emulated_hx711 import HX711
def cleanAndExit():
print("Cleaning...")
if not EMULATE_HX711:
GPIO.cleanup()
print("Bye!")
sys.exit()
hx = HX711(5, 6)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(343)
hx.reset()
hx.tare()
print("Tare done! Add weight now...")
lcd.lcd_display_string("Waage gestartet", 4)
time.sleep(5.2)
while True:
input_state = GPIO.input(25)
if input_state == False:
print("Tara ausgeführt")
lcd.lcd_display_string("Tara ausgefuehrt", 4)
hx.tare()
time.sleep(0.2)
try:
val = max(0, int(hx.get_weight(5)))
print(val)
hx.power_down()
hx.power_up()
time.sleep(0.1)
except (KeyboardInterrupt, SystemExit):
cleanAndExit()
#LCD Bereinigung
lcd.lcd_clear()
#Messwerte auf LCD schreiben
lcd.lcd_display_string(str(val), 1)
lcd.lcd_display_string(time.strftime("%d.%m.%Y %H:%M:%S"), 2)