Add fast reading function and refactor read_channel methods for HX711 #9
+30
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses the issue #7.
I made a separated function
read_fast
for the bit banging reading of the AD. This improved the performance by caching the object reference and opens up possibilities for other implementations.The delays are enforced with the
microcontroller.delay_us
function.I had to disable the interrupts during the read, because according to the datasheet, the clock is not allowed to stay up for more than 50µs during the operation :
With interrupts on, I was not able to guarantee the correct timing.
I tested on a ESP32 and it never failed.
Note that some other lines have been reformated according to the style guide defined in
ruff.toml
(line-length = 100
)