-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload.py
51 lines (35 loc) · 942 Bytes
/
load.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
import time
import sys
import urllib.request
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(0.055)
hx.set_reference_unit(referenceUnit)
hx.reset()
hx.tare()
print("Add weight now...")
while True:
try:
val = hx.get_weight(5)
print(val)
hx.power_down()
hx.power_up()
time.sleep(3)
weightz = urllib.request.urlopen("https://api.thingspeak.com/update?api_key=PQAOVMZ8LLRYZV3E&field3=%s"%(val))
print(weightz.read())
weightz.close()
except (KeyboardInterrupt, SystemExit):
cleanAndExit()