Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Hx711 load cell, learning python
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Hx711 load cell, learning python

by Itsybitsynoobie on Thu Apr 16, 2020 9:50 am

I am very new to Adafruit, programming, load cells, python, CircuitPython, etc
I have a project to connect the LS3DH accelerometer and (non-Adafruit product) hx711 to my itsybitsy. I’ve successfully hooked up and read the accelerometer. I’ve also hooked up the load cell and was able to use the print function to verify that I am successfully going through parts of the code.

My inquiry here is more so to understand the general code. I have found a great deal of codes for the hx711, RPI based python codes.

I think the first step for me is to understand the digitalio and how it relates to the RPI.GPIO. If you are using 0 and 1 or True and False, and your input is say... 0.0001V would this read as 0 or 1? Likewise what would be the cutoff for a True reading? Do I need to tell the controller what the range for 0 is and what the range for 1 is?

Here is the main bit of code I want to analyze and understand:

Removed the “GPIO”
Code: Select all | TOGGLE FULL SIZE
 scale_ready = False
    while not scale_ready:
        if hx.DOUT == 0):
            scale_ready = False
        if hx.DOUT == 1):
            print("Initialization complete!")
            scale_ready = True

Original RPI py code:

Code: Select all | TOGGLE FULL SIZE
scale_ready = False
    while not scale_ready:
        if (GPIO.input(hx.DOUT) == 0):
            scale_ready = False
        if (GPIO.input(hx.DOUT) == 1):
            print("Initialization complete!")
            scale_ready = True


If someone could point me in the direction of a device that Adafruit produces that is analog to digital and does not utilize I2C or SPI I think that would give me loads of knowledge! Thanks in advance!

Itsybitsynoobie
 
Posts: 4
Joined: Thu Apr 16, 2020 9:32 am

Re: Hx711 load cell, learning python

by dastels on Thu Apr 16, 2020 12:51 pm

You will need to have a digitalio.DigitalInOut configured for input. Getting it's value property will give you the boolean state on that pint.
Knowing what the hx structure is would help, but I'll assume it's a pin number.
Soo...

Code: Select all | TOGGLE FULL SIZE
hx_status = digitalio.DigitalInOut(hx.DOUT)
hx_status.dir = digitalio.Direction.INPUT

scale_ready = False
   
while not scale_ready:
    if not hx_status.value:
        scale_ready = False
    if hx_status.value:
        print("Initialization complete!")
        scale_ready = True


this can be simplified quite a bit, which should make it clearer.

Code: Select all | TOGGLE FULL SIZE
hx_status = digitalio.DigitalInOut(hx.DOUT)
hx_status.dir = digitalio.Direction.INPUT

scale_ready = False
   
while not scale_ready:
    scale_ready = hx_status.value

print("Initialization complete!")


As for what's true and false:

Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:
- None
- False
- zero of any numeric type, for example, 0, 0L, 0.0, 0j.
- any empty sequence, for example, '', (), [].
- any empty mapping, for example, {}.
- instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns the integer zero or bool value False.2.5

All other values are considered true


I trust that helps.

Dave

dastels
 
Posts: 2838
Joined: Tue Oct 20, 2015 3:22 pm

Re: Hx711 load cell, learning python

by tannewt on Thu Apr 16, 2020 12:55 pm

Hi! The voltage cutoffs for digital signals are dependent on the technology. Most modern integrated circuits us a process called CMOS. With CMOS digital signals, < 0.3 * Vdd is a zero (aka False) and > 0.7 * Vdd is a one (aka True). Vdd is the supply voltage. On Adafruit boards Vdd is usually 3.3V. For SAMD microcontrollers, like the ones on the Itsy M0 and M4, it's usually < 0.3 * 3.3V = 1 V is zero and > 0.7 * 3.3 = 2.3V is one.

Hope that helps!

tannewt
 
Posts: 1691
Joined: Thu Oct 06, 2016 8:48 pm

Re: Hx711 load cell, learning python

by Itsybitsynoobie on Fri Apr 17, 2020 8:44 pm

dastels wrote:You will need to have a digitalio.DigitalInOut configured for input. Getting it's value property will give you the boolean state on that pint.
Knowing what the hx structure is would help, but I'll assume it's a pin number.
Soo...

Code: Select all | TOGGLE FULL SIZE
hx_status = digitalio.DigitalInOut(hx.DOUT)
hx_status.dir = digitalio.Direction.INPUT

scale_ready = False
   
while not scale_ready:
    if not hx_status.value:
        scale_ready = False
    if hx_status.value:
        print("Initialization complete!")
        scale_ready = True


this can be simplified quite a bit, which should make it clearer.

Code: Select all | TOGGLE FULL SIZE
hx_status = digitalio.DigitalInOut(hx.DOUT)
hx_status.dir = digitalio.Direction.INPUT

scale_ready = False
   
while not scale_ready:
    scale_ready = hx_status.value

print("Initialization complete!")


As for what's true and false:

Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:
- None
- False
- zero of any numeric type, for example, 0, 0L, 0.0, 0j.
- any empty sequence, for example, '', (), [].
- any empty mapping, for example, {}.
- instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns the integer zero or bool value False.2.5

All other values are considered true


I trust that helps.

Dave


Thank you, I have played with this some and all though I have no clue what I’m doing, the trial and error, along with the print command is teaching me bits and pieces. Trying to chase the pins through and keep getting lost.

I’ve been trying to use this resource, sorry for not supplying the entire thing upfront. This one seems the most broken down for me to understand, however it’s probably a bit lengthy for my to wrap my head around:
https://github.com/learn2develop/hx711py

I’ve since came across this and think this may be a bit simpler for me to understand and get to run (non-SPI):
https://github.com/geda/hx711-lopy

I would prefer some direction on reading/learning the basics for me to know what I need vs you all taking your time to write my code. However, all help is greatly appreciated!

Itsybitsynoobie
 
Posts: 4
Joined: Thu Apr 16, 2020 9:32 am

Re: Hx711 load cell, learning python

by Itsybitsynoobie on Fri Apr 17, 2020 8:45 pm

tannewt wrote:Hi! The voltage cutoffs for digital signals are dependent on the technology. Most modern integrated circuits us a process called CMOS. With CMOS digital signals, < 0.3 * Vdd is a zero (aka False) and > 0.7 * Vdd is a one (aka True). Vdd is the supply voltage. On Adafruit boards Vdd is usually 3.3V. For SAMD microcontrollers, like the ones on the Itsy M0 and M4, it's usually < 0.3 * 3.3V = 1 V is zero and > 0.7 * 3.3 = 2.3V is one.

Hope that helps!

Excellent! I’m using 3.3v and 4.9v so this information helps!

Itsybitsynoobie
 
Posts: 4
Joined: Thu Apr 16, 2020 9:32 am

Re: Hx711 load cell, learning python

by dastels on Sat Apr 18, 2020 9:50 am

There are many good "learning Python" resources online. Using those to gain an understanding of the Python language will translate directly to applying it using CircuitPython.

Dave

dastels
 
Posts: 2838
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.