pico-scale
|
A scale API for a Raspberry Pi Pico (RP2040).
The .gif above illustrates the current example code obtaining data from a HX711 operating at 80 samples per second. Each line shows the current weight calculated from all samples obtained within 250 milliseconds, along with the minimum and maximum weights of the scale since boot. I applied pressure to the load cell to show the change in weight.
If you want to use this repository as-is with the example code, clone the respository and initialise the hx711-pico-c
submodule.
Then #include
as follows:
Run CTest to build the example and calibration programs. The .uf2
files you upload to your Pico will be found under build/tests/
.
Alternatively, if you want to use the scale functionality as an API in your own project, add pico-scale
as a submodule and then initialise it.
Then, from your own code, #include
the relevant files as follows and initialise the hx711:
See the explanation here for why you need to manually include the PIO program.
https://endail.github.io/pico-scale
You will always need to initialise the HX711 before using it as a scale. See here for how to do that.
CTest
.calibration.uf2
in the build/tests/
directory to the Raspberry Pi Pico.Q: __"Which mass units are supported?"__
A: The following mass_unit_t
s are available.
mass_ug
: microgramsmass_mg
: milligramsmass_g
: gramsmass_kg
: kilogramsmass_ton
: metric tonsmass_imp_ton
: imperial tonsmass_us_ton
: US tonsmass_st
: stonesmass_lb
: poundsmass_oz
: ouncesQ: __"How do I get the weight in pounds/ounces/tons/etc...?"__
A: You can either: set the scale_t
or change the mass_t
.
Q: __"How do I perform math on the weights?"__
A: You can either: get the underlying value and operate on that, or use the in-built functions to operate on two mass_t
structs.
The advantage of using the built-in functions is that the mass_t
structs can be of different units. So you can check if, for example, m1
is greater than or equal to m2
, even if m1
is is in pounds and m2
is in kilograms. The conversion is taken care of for you.
Q: __"Which math functions are available?"__
A:
mass_add(mass_t* lhs, mass_t* rhs, mass_t* res)
: add lhs
and rhs
and store result in res
mass_sub(mass_t* lhs, mass_t* rhs, mass_t* res)
: subtract rhs
from lhs
and store result in res
mass_mul(mass_t* lhs, mass_t* rhs, mass_t* res)
: multiply lhs
and rhs
and store result in res
mass_div(mass_t* lhs, mass_t* rhs, mass_t* res)
: divide lhs
by rhs
and store result in res
, returns false if rhs
is 0mass_addeq(mass_t* self, mass_t* rhs)
: add rhs
to self
mass_subeq(mass_t* self, mass_t* rhs)
: subtract rhs
from self
mass_muleq(mass_t* self, mass_t* rhs)
: multiply self
by rhs
mass_diveq(mass_t* self, mass_t* rhs)
: divide self
by rhs
, returns false if rhs
is 0mass_eq(mass_t* lhs, mass_t* rhs)
: return true if lhs
equals rhs
mass_neq(mass_t* lhs, mass_t* rhs)
: return true if lhs
does not equal rhs
mass_lt(mass_t* lhs, mass_t* rhs)
: return true if lhs
is less than rhs
mass_gt(mass_t* lhs, mass_t* rhs)
: return true if lhs
is greater than rhs
mass_lteq(mass_t* lhs, mass_t* rhs)
: return true if lhs
is less than or equal to rhs
mass_gteq(mass_t* lhs, mass_t* rhs)
: return true if lhs
is greater than or equal to rhs