Advertisement
Guest User

ciekawy

a guest
Feb 9th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import mysql.connector
  3. import time
  4. import mysql.connector
  5. import sys
  6. from hx711 import HX711
  7.  
  8.  
  9. hx = HX711(5, 6)
  10. cnx = mysql.connector.connect(user="tomaszde_projekt", password="Bazaprojekt1", host="sql.tomaszde.nazwa.pl", database="tomaszde_projekt")
  11. cursor = cnx.cursor()
  12. hx.set_reference_unit(-1550)
  13.  
  14. hx.reset()
  15. hx.tare()
  16. val=hx.get_weight(5)
  17. while True:
  18.     try:
  19.         cursor.execute("DELETE FROM `waga`;")
  20.         val = hx.get_weight(5)
  21.         if val<=0:
  22.             print('0')
  23.         else:
  24.             print (val)
  25.             cursor.execute("INSERT INTO `waga`(`g`) VALUES ('%d');" % (val))
  26.             cnx.commit()
  27.         hx.power_down()
  28.         hx.power_up()
  29.         time.sleep(5)
  30.     except (KeyboardInterrupt, SystemExit):
  31.         cleanAndExit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement