Beispiel #1
0
#!/usr/bin/python3
import sys
import RPi.GPIO as GPIO
from scale import Scale

scale = Scale()

scale.setReferenceUnit(-300)

scale.reset()
scale.tare()

while True:

    try:
        val = scale.getMeasure()
        print("{0: 4.0f}".format(val))

    except (KeyboardInterrupt, SystemExit):
        GPIO.cleanup()
        sys.exit()
Beispiel #2
0
            scale.reset()
            scale.tare()

    # Every 30s jump to timedTare function
    schedule.every(30).seconds.do(timedTare)

    # Enter the main running loop
    while (True):

        # Points to the 30 seccond timer above. It remembers to check the time for the scheduled interrupt.
        schedule.run_pending()

        # Unless an exception occurs, run this code
        try:
            # Call for a scale, temperature, and humidity reading
            scaleReading = scale.getMeasure()
            dhtReading = instance.read()

            # If the dht reading is valid, store it as a new temp and humid value
            if dhtReading.is_valid():
                temp = dhtReading.temperature
                humid = dhtReading.humidity

            # Update camera annotation with mass, temp, and humid
            annotation = datetime.datetime.now().strftime("%H:%M:%S " \
               + "Mass: " + str("{0:.1f}".format(scaleReading)) + "g " \
               + "T: " + str("{0:.1f}".format(temp)) + " F " \
               + "H: " + str("{0:.1f}".format(humid)) + "%%")

            camera.annotate_text = annotation
            camera.annotate_text_size = cameraAnnoSize