The coefficient calculation of the program changes depending on the power supply voltage (AVDD) for the load cell of the HX711 and the characteristics (resistance value and output voltage) of the load cell. Also, for each of the four load cells, error adjustment and zero adjustment are required, so simply speaking, the program is quadrupled. It corresponds to the idea of measuring with four separate AVR circuits and summarizing the four results obtained.
Simply asking only the subroutine part of a program can be difficult to solve if you don't know how the entire program works. It may take some time, but do your best!
Thanks. I understand simple basic programming but this is too complicated for an old man like me and therefore I wants lots of help, help with the whole program is of course invaluable help and thanks. To learn this I think will be very time consuming for a hobby project. Thanks
If the questioner has a high level of programming, we can also suggest simplifying the program. For example, the [PD_SCK] pin is shared by all four ports and connected to one port, and only the pin is received individually by the four ports. However, since many modifications of the provided test program are required, I proposed a method to make the four easiest subroutines by copying.
Even so, the questioner often doesn't understand the BASIC language. You'll have to learn a little more and then ask questions or ask for all the programming.
Dim Hx711ad As Long Dim Hx711avg As Long Dim Hx711count As Byte Dim Average(16) As Long Dim Avgpoi As Byte Dim Avgsum As Long Dim Zeroadj As Long Dim Stablecount As Byte Dim Lastvalue As Long Dim Sensorcal As Long ' Dim Temp1 As Byte Dim Temp2 As Byte Dim Templ1 As Long Dim Tempstr As String * 40 ' Dim Dummy As Eram Long Dim Eepprgid As Eram Long Dim Eepsensorcal As Eram Long
Main: If Hx711_dat = 0 Then Gosub Hx711get Gosub Hx711movavg Templ1 = Hx711avg + Zeroadj
Templ1 = Templ1 * 100 Templ1 = Templ1 / Sensorcal ' Temp2 = Temp2 + 1 If Temp2 > 10 Then Temp2 = 0 End If
waitms 100 Tempstr = Str(templ1) If Templ1 < 0 Then print Format(tempstr , " 0") If Temp2 = 0 Then Print Format(tempstr , " 0") End If Else print Format(tempstr , " 0") If Temp2 = 0 Then Print Format(tempstr , " 0") End If End If
If Templ1 = Lastvalue Then Stablecount = Stablecount + 1 If Stablecount > 5 Then Stablecount = 5
End If Else Lastvalue = Templ1 Stablecount = 0
End If End If Goto Main
Hx711get: Hx711ad = 0 For Hx711count = 23 To 0 Step -1 Set Hx711_clk Waitus 1 Hx711ad.hx711count = Hx711_dat Reset Hx711_clk Waitus 1 Next Hx711count
Set Hx711_clk Waitus 1 Reset Hx711_clk Waitus 1 ' If Hx711ad.23 = 1 Then Hx711ad = Hx711ad Or &HFF000000 End If Return
Hx711movavg: Avgsum = Avgsum - Average(avgpoi) Average(avgpoi) = Hx711ad Avgsum = Avgsum + Hx711ad ' Avgpoi = Avgpoi + 1 If Avgpoi > 16 Then Avgpoi = 1 End If ' Hx711avg = Avgsum Shift Hx711avg , Right , 4 , Signed Return
but now I want to use there more HX711 on port b2 to port b7
there are multiple solutions. the most simple would be when you use a full port for example PORTB. Say portb.0 and portb.1 for the first device, portb.2 and portb.3 for the next, etc.
code becomes :
[code:1:e439bf5711] For Hx711count = 23 To 0 Step -1 'Extract 24-bit data. Set PORTB.0 'clock of first device SET PORTB.2 'clock of second device SET PORTB.4 SET PORTB.6 Waitus 1 'Period of [H]. (T3 = 1uS) Hx711ad1.hx711count = PINB.1 Hx711ad2.hx711count = PINB.3 Hx711ad3.hx711count = PINB.5 Hx711ad4.hx711count = PINB.7 Reset PORTB.0 Reset PORTB.2 Reset PORTB.4 Reset PORTB.6 Waitus 1 'Period of [L]. (T4 = 1uS) Next Hx711count [/code:1:e439bf5711]
this is just a partial sample to show the idea where you perform the operations on 4 devices at once. this also requires 4 variables to contain the data. you could also make a sub routine where you pass the bit numbers of the port.
and you can simple copy the code and then assign 4 different ports as the author suggested.
I am aware of Gosub but where in my code should I insert Gosub Hx711get1, Gosub Hx711get2, Gosub Hx711get3 abd Gosub Hx711get4. I am aware of the principle of Basic since the 80's with CBM64 but Bascom Basic is more advanced Basic than what I learned then. I really need this gadget that reads all 4 weights one by one.