endail / hx711 Goto Github PK
View Code? Open in Web Editor NEWRaspberry Pi HX711 C++ Library
License: MIT License
Raspberry Pi HX711 C++ Library
License: MIT License
Line 156 in ed5dc19
This repo should focus solely on communicating with a HX711. Functionality built on top, such as a scale for measuring weight, is out of scope and should be removed/moved into its own repo.
Line 282 in de87c5b
Restoring the backup gain and channel will be missed for exceptions other than TimeoutException.
Suggest catching base std::exception, restoring config, then rethrowing instead.
openGpioHandle, closeGpioHandle, etc...
Line 216 in 5556eb0
Line 84 in 84db959
Doesn't change and code should reflect that fact.
https://github.com/endail/hx711/search?q=assert
Code has been working for some time now and they are no longer needed.
Try run the HX711 Calibration and occurs the exception
Find an object you know the weight of. If you can't find anything, try searching Google for your phone's specifications to find its weight. You can then use your phone to calibrate your scale.
Enter the unit you want to measure the object in (eg. g, kg, lb, oz): kg
Enter the weight of the object in the unit you chose (eg. if you chose 'g', enter the weight of the object in grams): 1
Enter the number of samples to take from the HX711 module (eg. 15): 30
Remove all objects from the scale and then press enter.
Working...terminate called after throwing an instance of 'HX711::TimeoutException'
what(): timed out while trying to read bytes from HX711
Aborted
Reading from an unconnected GPIO could lead to the process hanging (or another other unpredictable result). It may be of some use to have a method of the HX711 class to "test" whether a HX711 could be detected by using a simple read which times-out after some predefined time. Conversely, it may even be better to implement a configurable timeout within the isReady and readValue methods.
https://github.com/endail/hx711/blob/master/src/HX711.cpp#L53-L58
https://github.com/endail/hx711/blob/master/src/HX711.cpp#L118-L119
Swapping delayMicroseconds for thread sleep resulted in -1 values from the sensor. Unsure of reason why, but it may be that thread sleep functions are not being called or are being prolonged.
In any case, wiringPi's delayMicroseconds functions are working correctly and can stay.
https://en.cppreference.com/w/cpp/chrono/high_resolution_clock
The high_resolution_clock is not implemented consistently across different standard library implementations, and its use should be avoided. It is often just an alias for std::chrono::steady_clock or std::chrono::system_clock, but which one it is depends on the library or configuration. When it is a system_clock, it is not monotonic (e.g., the time can go backwards). For example, for gcc's libstdc++ it is system_clock, for MSVC it is steady_clock, and for clang's libc++ it depends on configuration.
Generally one should just use std::chrono::steady_clock or std::chrono::system_clock directly instead of std::chrono::high_resolution_clock: use steady_clock for duration measurements, and system_clock for wall-clock time.
https://github.com/endail/hx711/search?q=high_resolution_clock shows it being used in contexts where a steady clock (ie. std::chrono::steady_clock
) should explicitly be used.
Lines 204 to 211 in 6962643
For the sake of consistency and to avoid confusion with Pico/RP2040 HX711 repos, rename this repo to hx711-rpi-cxx.
Note the breaking autobuild notification changes to hx711-rpi-py.
Lines 367 to 387 in 42d6305
Sleeping for settling time should be separate to powering up.
Lines 344 to 365 in 42d6305
Timeout should be separate from powering down to allow other/concurrent code to run.
Line 49 in 5556eb0
https://github.com/endail/hx711/blob/master/src/DiscoverTiming.cpp
Timing discovery is not in a working state and should not pollute the current codebase.
HX711 channels are linked-to a fixed, mututally-exclusive gain. See: https://github.com/endail/hx711-pico-c#where-is-channel-a-and-channel-b
Line 67 in 2db13b2
Line 89 in 5556eb0
Also consider using coarse timing.
Line 205 in 6962643
Considerations:
std::vector< HX711::Value >
? Perhaps a new HX711::ValueCollection
class?Currently, the clock pin is pulsed with two GPIO write calls through the lg library:
https://github.com/endail/hx711/blob/master/src/HX711.cpp#L88
https://github.com/endail/hx711/blob/master/src/HX711.cpp#L97
Both call lgGpioWrite through the Utility
class. But lg also has a lgTxPulse function.
I am wondering if using lgTxPulse to provide a single pulse to the HX711's clock pin may be more efficient than the two lgGpioWrite calls. If it is, it may also help to avoid the 60us power down issue.
AdvancedHX711Test.cpp
Calibration.cpp
SimpleHX711Test.cpp
test.cpp
HX711 has a predefined most significant bit format. HX711::Format
is therefore redundant.
Line 256 in 5556eb0
If a conversion is in progress, the gain can be altered without waiting for the conversion to complete.
Caveat: a distinction will need to be made between conversion period and input gain selection period.
Lines 257 to 265 in de87c5b
The waitReady method should busy-wait for a predefined maximum amount of time. If the amount of time is exceeded, a TimeoutException
should be thrown. The try-catch in setConfig can then handle accordingly.
Inheriting classes like AdvancedHX711 can then override with something else as needed.
This will also handle the case where DOUT is never "ready" for some unforeseen reason.
Lines 110 to 111 in 6962643
Open and close, begin and end, or connect and disconnect.
Lines 310 to 328 in 42d6305
The high_resolution_clock is not implemented consistently across different standard library implementations, and its use should be avoided. It is often just an alias for std::chrono::steady_clock or std::chrono::system_clock, but which one it is depends on the library or configuration. When it is a system_clock, it is not monotonic (e.g., the time can go backwards). For example, for gcc's libstdc++ it is system_clock, for MSVC it is steady_clock, and for clang's libc++ it depends on configuration.
Generally one should just use std::chrono::steady_clock or std::chrono::system_clock directly instead of std::chrono::high_resolution_clock: use steady_clock for duration measurements, and system_clock for wall-clock time.
https://en.cppreference.com/w/cpp/chrono/high_resolution_clock
Line 215 in 6962643
Line 213 in 6962643
Add a code comment on the result of this
Line 161 in 6962643
Line 139 in b1cb63a
eg. https://www.ebay.com/sch/i.html?_nkw=hx711
Note:
Line 67 in b1cb63a
Line 134 in ed5dc19
For the sake of consistency with other repo (hx711-pico-c, etc...).
Lines 65 to 67 in 42d6305
Line 171 in 6962643
Remove it and replace it with a 32 bit signed int. The various methods of the class can be placed in the HX711 class.
Line 111 in de87c5b
Particularly important for time based sampling where the total time does not allow for any samples to be gathered.
Line 65 in 5556eb0
https://cdn.sparkfun.com/assets/b/f/5/a/e/hx711F_EN.pdf
"Reset and Power-Down" details on pg. 5 have changed. Code needs to reflect these changes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.