Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
dhawgupta-private committed Oct 26, 2017
1 parent 52d900f commit ffd69c2
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 4 deletions.
Binary file modified hx711.pyc
Binary file not shown.
109 changes: 109 additions & 0 deletions hx711_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import mraa

class Hx711:
def __init__(self,dout,pd_sck, gain = 128):
# self.PD_SCK = pd_sck
# self.DOUT = dout
self.PD_SCK = mraa.Gpio(pd_sck)
self.DOUT = mraa.Gpio(dout)
self.PD_SCK.dir(mraa.DIR_OUT)
self.DOUT.dir(mraa.DIR_IN)
self.GAIN = 1
self.OFFSET = 0
self.SCALE = 1
self.set_gain(gain)
def set_gain(self,gain):
if gain == 128:
self.GAIN = 1
elif gain == 64:
self.GAIN = 3
elif gain == 32:
self.GAIN = 2
self.PD_SCK.write(0) # is for low signal
self.read()
def read(self):
while self.DOUT.read() == 1:
continue

value = 0
data = 0
filler = 0x00
for i in range(24):
self.PD_SCK.write(1)
value = value<<1
self.PD_SCK.write(0)
if(self.DOUT.read()):
value = value + 1
self.PD_SCK.write(1)
value = value ^ 0x800000
self.PD_SCK.write(0)
return value

def read_average(self,times):
abuf = []
for i in range(10):
abuf.append(self.read())
abuf.sort()
aval = (abuf[4] + abuf[3] + abuf[5] + abuf[6])/4
return aval
# sum0 = 0
# for i in range(times):
# sum0 += self.read()
# return sum0/times;


def get_value(self,times):
return self.read_average(times) - self.OFFSET


def get_units(self,times):
return self.get_value(times) /self.SCALE


def tare(self, times):
abuf = []
for i in range(10):
abuf.append(self.read())
abuf.sort()
aval = (abuf[4] + abuf[3] + abuf[5] + abuf[6])/4
#sum = self.read_average(times)
self.set_offset(aval)

def set_scale(self,scale):
self.SCALE = scale

def get_scale(self):
return self.SCALE

def get_offset(self):
return self.OFFSET



def set_offset(self,offset):
self.OFFSET = offset;

def power_down(self):
self.PD_SCK.write(0)
self.PD_SCK.write(1)

def power_up(self):
self.PD_SCK.write(0)


# def shiftIn(self):
# value =0
# for i in range(24):
# self.PD_SCK.write(1)
# value = value<<1
# self.PD_SCK.write(0)
# if(self.DOUT.read()):
# value = value + 1

# return value

# def is_ready(self):
# if self.DOUT.read() == 0:
# return True
# else:
# return False
Binary file added hx711_2.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion intel_fice2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from hx711 import Hx711
from time import sleep
calibration_factor = -7050.0
calibration_factor = -17650.0 # set the calibratino factor from -7050 for pounds to -176550 for kg's
a1 = Hx711(36,20)
a2 = Hx711(48,14)
a1.set_scale(calibration_factor)
Expand Down
81 changes: 81 additions & 0 deletions intel_fice2_custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from hx711_2 import Hx711
from time import sleep
calibration_factor = 17650.0 # set the calibratino factor from -7050 for pounds to -176550 for kg's
a1 = Hx711(36,20)
a2 = Hx711(48,14)
a1.set_scale(calibration_factor)
a2.set_scale(calibration_factor)
a1.tare(1)
a2.tare(1)
# borders = [10,20,30,40,50,60]
# l1 = 5
# l2 = 55
# threshold_w = 1.0
# threshold_x = 4
# x =float()
# w = float()
# x_p = 0.0
# w_p = 0.0
# x_n = float()
# w_n = float()
# mark = [0.0,0.0,0.0,0.0,0.0,0.0] # places on the shelf for containers
# mark2 = [0,0,0,0,0,0]
while 1:
# arr = []
# arr2 = []
# for i in range(10):
# arr.append(a1.get_units(1))
# arr2.append(a2.get_units(1))
# arr.sort()
# arr2.sort()

r1 = a1.get_units(1)
r2 = a2.get_units(1)#(arr2[6] + arr2[5] + arr2[3] + arr2[4])/4

w = r1 + r2
print str(r1) + " " + str(r2) + " " + str(w)

# if w > threshold_w:
# x = (r1*l1 + r2*l2)/w

# if w-w_p > threshold_w or w_p-w > threshold_w or x-x_p > threshold_x or x_p-x > threshold_x :
# w_n = w - w_p
# x_n = (w*x - w_p*x_p)/w_n

# for i in range(6):
# if x_n < borders[i]:
# if w_n > 0:
# mark[i] = w_n # replacing 1 with the weight added
# mark2[i] = 1
# print "Container Added at : " + str(i + 1)
# elif w_n < 0:
# mark2[i] = 0
# mark[i] = 0
# print "Container Removed from : " + str(i+1)
# break

# else:
# for i in range(6):
# mark2[i] = 0
# mark[i] = 0.0 # not sure about this slot
# x = 0
# w_p = w
# x_p = x
# string = str()
# string2 = str()
# for i in range(6):
# string = string + str(mark[i]) + " "
# string2 = string2 + str(mark2[i]) + " "
# print string
# print string2
# with open('weights.txt','w') as w:
# w.write(string)


a1.power_down()
a2.power_down()
sleep(1)
a1.power_up()
a2.power_up()


9 changes: 7 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from hx711 import Hx711
a = Hx711(36,20)
abuf = []
offset = 0
div = 1
offset2 = 8278500.0
div2 = 18000.0

while 1:
abuf = []
for i in range(10):
Expand All @@ -9,8 +14,8 @@
abuf.sort()
string = str()
for i in range(10):
string = string + str(abuf[i]) + " "
string = string + str((abuf[i] - offset)/div) + " "

aval = (abuf[4] + abuf[3] + abuf[5] + abuf[6])/4
print aval
print (aval - offset)/div
print string
4 changes: 3 additions & 1 deletion test2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from hx711 import Hx711
a = Hx711(48,14)
abuf = []
offset = 0 #8278500.0
div = 1 #18000.0
while 1:
abuf = []
for i in range(10):
Expand All @@ -12,7 +14,7 @@
string = string + str(abuf[i]) + " "

aval = (abuf[4] + abuf[3] + abuf[5] + abuf[6])/4
print aval
print ( aval - offset)/div
print string


Expand Down

0 comments on commit ffd69c2

Please sign in to comment.