Ich bin übers 3D drucken zum Raspberry Pi gekommen und bin jetzt bei Python gelandet. Ich bin total begeistert was man alles machen kann. Ich habe mir schon ein Buch gekauft und den Python komplett Kurs mit Videos. Allerdings bin ich erst 3Wochen dabei und das meiste ist für mich noch Chinesisch
Ich habe natürlich gelesen das Ihr hier keine Hausaufgaben lösen wollt, ich bin auch kein Schüler und Student bin ich auch nicht.
Ich bin trotzdem blutiger Anfänger!!!
Jetzt zu meinem Problem.
Ich würde gerne das die Waage das Ergebnis nicht in Gramm sondern in Kg mit 2 Nachkommastellen ausgibt z.b. 12,45 kg.
Ich habe mir schon in den letzten Nächten die Augen im WWW plat geschaut und nix gefunden.
Würde mir einer von Euch helfen
Gruß Petro
#!/usr/bin/python
import time, os, datetime, sys
import RPi.GPIO as GPIO
EMULATE_HX711=False
referenceUnit = 1
if not EMULATE_HX711:
import RPi.GPIO as GPIO
from hx711 import HX711
else:
from emulated_hx711 import HX711
# Zuordnung der GPIO Pins (ggf. anpassen)
LCD_RS = 4
LCD_E = 17
LCD_DATA4 = 18
LCD_DATA5 = 22
LCD_DATA6 = 23
LCD_DATA7 = 24
LCD_WIDTH = 16 # Zeichen je Zeile
LCD_LINE_1 = 0x80 # Adresse der ersten Display Zeile
LCD_LINE_2 = 0xC0 # Adresse der zweiten Display Zeile
LCD_CHR = GPIO.HIGH
LCD_CMD = GPIO.LOW
E_PULSE = 0.0005
E_DELAY = 0.0005
def lcd_send_byte(bits, mode):
# Pins auf LOW setzen
GPIO.output(LCD_RS, mode)
GPIO.output(LCD_DATA4, GPIO.LOW)
GPIO.output(LCD_DATA5, GPIO.LOW)
GPIO.output(LCD_DATA6, GPIO.LOW)
GPIO.output(LCD_DATA7, GPIO.LOW)
if bits & 0x10 == 0x10:
GPIO.output(LCD_DATA4, GPIO.HIGH)
if bits & 0x20 == 0x20:
GPIO.output(LCD_DATA5, GPIO.HIGH)
if bits & 0x40 == 0x40:
GPIO.output(LCD_DATA6, GPIO.HIGH)
if bits & 0x80 == 0x80:
GPIO.output(LCD_DATA7, GPIO.HIGH)
time.sleep(E_DELAY)
GPIO.output(LCD_E, GPIO.HIGH)
time.sleep(E_PULSE)
GPIO.output(LCD_E, GPIO.LOW)
time.sleep(E_DELAY)
GPIO.output(LCD_DATA4, GPIO.LOW)
GPIO.output(LCD_DATA5, GPIO.LOW)
GPIO.output(LCD_DATA6, GPIO.LOW)
GPIO.output(LCD_DATA7, GPIO.LOW)
if bits&0x01==0x01:
GPIO.output(LCD_DATA4, GPIO.HIGH)
if bits&0x02==0x02:
GPIO.output(LCD_DATA5, GPIO.HIGH)
if bits&0x04==0x04:
GPIO.output(LCD_DATA6, GPIO.HIGH)
if bits&0x08==0x08:
GPIO.output(LCD_DATA7, GPIO.HIGH)
time.sleep(E_DELAY)
GPIO.output(LCD_E, GPIO.HIGH)
time.sleep(E_PULSE)
GPIO.output(LCD_E, GPIO.LOW)
time.sleep(E_DELAY)
def display_init():
lcd_send_byte(0x33, LCD_CMD)
lcd_send_byte(0x32, LCD_CMD)
lcd_send_byte(0x28, LCD_CMD)
lcd_send_byte(0x0C, LCD_CMD)
lcd_send_byte(0x06, LCD_CMD)
lcd_send_byte(0x01, LCD_CMD)
def lcd_message(message):
message = message.ljust(LCD_WIDTH," ")
for i in range(LCD_WIDTH):
lcd_send_byte(ord(message),LCD_CHR)
def cleanAndExit():
print("Cleaning...")
if not EMULATE_HX711:
GPIO.cleanup()
print("Bye!")
sys.exit()
if __name__ == '__main__':
# initialisieren
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(LCD_E, GPIO.OUT)
GPIO.setup(LCD_RS, GPIO.OUT)
GPIO.setup(LCD_DATA4, GPIO.OUT)
GPIO.setup(LCD_DATA5, GPIO.OUT)
GPIO.setup(LCD_DATA6, GPIO.OUT)
GPIO.setup(LCD_DATA7, GPIO.OUT)
display_init()
hx = HX711(5, 6)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(88.437)
hx.reset()
hx.tare()
print("Tara fertig! jetzt wiegen....")
while True:
try:
val = hx.get_weight(5)
msg1 = str(int(val)) + " g Rest GAS "
print(msg1)
lcd_send_byte(LCD_LINE_1, LCD_CMD)
lcd_message(msg1)
lcd_send_byte(LCD_LINE_2, LCD_CMD)
lcd_message("bei 5200g leer")
hx.power_down()
hx.power_up()
time.sleep(0.1)
except (KeyboardInterrupt, SystemExit):
cleanAndExit()