Hi @Spanker. the point you make is a very valid one, and I think its something we could all learn from when we’re developing code that uses libraries that are outside the standard “out of the box” Arduino IDE install.
If I search the Arduino IDE library manager for “hx711” I get three results (one of these may be because I’ve installed a library myself, but you should probably see at least two results anyway)…
Here’s how I would go about trying to work-out which is the correct library to use. It’s not a foolproof system, and to a degree it depends on the authors of the libraries using the keywords file correctly, but it’s a good starting place.
@christophebl’s latest code (the ESP32 version) contains these two calls to the HX711 library:
scale.set_scale(calibration_factor)
scale.get_units()
If we click the “more info” link in the Arduino Library Manager for each of the HX711 libraries it will open the GitHub page for each library.
In each library you’ll see a keywords.txt file. This is used to tell the Arduino IDE which commands to highlight in a different colour on the screen, but it’s a handy way to quickly view the available function calls (probably ‘methods’ we’re being picky, but I’ll call them functions here) that are available in the library (assuming it’s been populated correctly by the developer).
The first library in my screenshot contain a keywords file that looks like this (I’ve removed some irrelevant parts):
is_ready KEYWORD2
set_gain KEYWORD2
read_average KEYWORD2
get_value KEYWORD2
get_units KEYWORD2 <--------
tare KEYWORD2
set_scale KEYWORD2 <--------
get_scale KEYWORD2
set_offset KEYWORD2
get_offset KEYWORD2
power_down KEYWORD2
power_up KEYWORD2
You’ll see that both set_scale
and get_units
exist in this list.
The next library in my screenshot has these keywords:
begin KEYWORD2
start KEYWORD2
startMultiple KEYWORD2
setGain KEYWORD2
tare KEYWORD2
tareNoDelay KEYWORD2
setCalFactor KEYWORD2
getCalFactor KEYWORD2
getData KEYWORD2
getSingleConversion KEYWORD2
getSingleConversionRaw KEYWORD2
getReadIndex KEYWORD2
getConversionTime KEYWORD2
getSPS KEYWORD2
getTareTimeoutFlag KEYWORD2
disableTareTimeout KEYWORD2
getSettlingTime KEYWORD2
powerDown KEYWORD2
powerUp KEYWORD2
getTareOffset KEYWORD2
getTareStatus KEYWORD2
setTareOffset KEYWORD2
setSamplesInUse KEYWORD2
getSamplesInUse KEYWORD2
You’ll see that although there are more available functions in this library, and there are some duplications such as tare
, neither set_scale
and get_units
exist in this list.
The last library’s keywords file look like this:
readyToSend KEYWORD2
read KEYWORD2
Which is very different to either of the other two and doesn’t contain the set_scale
orget_units
functions.
This means that it’s a fairly good bet that the library that @christophebl has used is the first one in the screenshot above, or it’s a 3rd party library that he’s fond from somewhere (fingers crossed that it’s the first).
So, the lesson is that it’s good practice to add a comment with the URL of the library alongside each of the libraries that you include. It’s also good practice to record which version of the library was used when you wrote/tested/compiled the code, as its not unheard of for new versions to drop retired commands, or for a newly added command top only be available from a certain version onwards.
If the keywords file doesn’t exist (it is optional), or you want to be more certain about the whole range of functions available, it’s possible to view the .cpp file (usually located in the src folder) and pick your way through it looking for functions that are a available within the library.
I also take a copy of every zip file library that I install and keep them in a separate folder, just in case I want to re-install the Arduino IDE with exactly the same libraries that I originally used.
Pete.