New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
data is sampled on the wrong clock edgde #11
Comments
Hi @DigKleppe Saw your remark and I will work on it as soon time permits however my agenda is quite full so it might take a while. Thanks for posting the issue. |
Did some reading, and what I understand is that some processors are faster than others. This can be solved by putting an appropriate delay before the reading of the dataPin. Question: |
Longer than 60 us HIGH ==> low power mode.. |
@DigKleppe Can you please test it as I have no test setup nearby? // MSB_FIRST optimized shiftIn
// see datasheet page 5 for timing
uint8_t HX711::_shiftIn()
{
uint8_t value = 0;
uint8_t mask = 0x80;
while(mask > 0)
{
digitalWrite(_clockPin, HIGH);
delayMicroseconds(1); // T2 >= 0.2 us
if (digitalRead(_dataPin) == HIGH)
{
value |= mask;
}
digitalWrite(_clockPin, LOW);
delayMicroseconds(1); // keep duty cycle ~50%
mask >>= 1;
}
return value;
} |
It might be better to set the pinMode of the dataPin to INPUT_PULLUP. |
Hi Rob, It works ok. Note: the values you will get now are doubled compared to the previous software. get 1 bit more! |
Thanks for testing, The doubling of the digits means that the calibration numbers will be different, I do not expect users to use the raw numbers directly. So I should mention that in the readme.md Noise I have seen before, don't know the details, not sure but I recall smaller numbers (but that might be the factor 2 already). How much is that noise in grams after conversion in your setup? The library has different modi to make multiple reads and average them or take the median to "reduce" the noise. The rise and fall times are nice, so the 1 us delay is more than enough, maybe the delayMicroseconds after the CLOCK LOW is not needed (line 299) but it keeps the duty cycle around ~50%. But for 24 bits one would gain about 24 micros, making the reading faster, but possibly more unreliable. I need to make a test setup to investigate some ideas here. |
Merged the PR into master. |
The arduino shiftin function reads the data before the clock is set high. The first bit (= sign) is missed then.
The data should be read just before you set the clock low.
The delay function is just a short delayloop, mostly not needed.
I also debounce , just for sure.
Dig
The text was updated successfully, but these errors were encountered: