-
Notifications
You must be signed in to change notification settings - Fork 542
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
ESP32 issue, clock speed too fast #75
Comments
After having this library working perfectly on an ESP8266 I thought i could just slot in a ESP32 as a replacement.... I am getting regular nonsense readings. Bizarrely the first reading and then every 60s are 829.52kg, measurements between these are a constant 3.05kg. The (recalibrated) software and hardware are unchanged - this timing issue seems likely. How do I try your fix? You don't say which files are patched. |
Can you try my fork, it is still not super optimal implemented, but when ESP_H is defined it will change to a slower shiftIn function. In a better update it should look at the clock speed to make it future proof for other boards... https://github.com/lemio/HX711 |
Thank you! this fixes my problem of fluctating readings. Had to re-determine my zero & calibration factor, but now readings are consistent. Thank you again! |
Thanks @lemio for figuring this out. I wish I understood your original graph better. In case anyone is interested, I wanted to work through the numbers so I'm sharing them here. The requirement of 0.2µs for each of clock high and low yields 0.4µs per clock cycle or 2.5MHz. Assuming 30 instructions for each That's why a 160MHz ESP32 is just too fast. And if |
The experiment shown in the graphs is a barrel (for brewing beer) which is having a valve (so slowly losing weight) what you can see it that it is not correct shifting the bits, because of that reason it sometimes is right (when there should be a 0 and there is a 0, but sometimes is fails when there should be a 1 but there is still a zero. My proposal is to change the Arduino ecosystem, so other libraries could also benefit from this change. Without losing speed when using the 'old' version of shiftIn and shiftOut: See this issue: https://github.com/arduino/Arduino/issues/6561 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val, unsigned long maxSpeed = 0);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, unsigned long maxSpeed = 0);
We could use the constant value of the F_CPU to change the bahaviour of the shiftIn and shiftOut if the maximum communication speed is defined. In this way more libraries and hardware in the Arduino ecosystem can use this configuration and have a limited shiftIn or shiftOut speed.
@frankleonrose I could only use some help on the speed comparison part, because do you know the ratio of pure clock speed vs the speed of the shiftIn/shiftOut (communication speed). Than we can relatively easily do a proposal for implementing it into the core Arduino functions. |
I seem to be running into this issue on teensy3.2 also, with 96 MHz clock. So not just an ESP32 issue. I was searching for whether anyone had anything to say about shiftin being too fast (in general), because I suspected there might be an issue, since I saw there was no delay in the code. And I got this link to the very HX711 library I was using. |
I pulled lemio's patch, and after defeating the ESP32 conditional, it is working for me on teensy3.2. |
I believe a solution exists here: https://youtu.be/iywsJB-T-mU Looks like setting the esp32 to 80mhz solves the issue nicely |
Hi guys. I tried @lemio 's branch but I still have the problem. Andreas Spiess' solution linked by @geekspeed but then I my scale doesn't wake up from deep sleep anymore, so slower CPU frequency is currently not an option. Is the slowed down shiftIn function still working for you guys? Or might this have been broken by a later SDK build? Did anybody ever hook up a logic analyzer to the hx711 to see what's going on? Any help appreciated... |
Hello Mans! |
This is an obvious point, but even if reducing the clock speed helps, that doesn't rule out some stupid problem. I found that the HX711 board I got on ebay had a really dumb problem. FWIW, if you look at the HX711 data sheet, the supply situation may be slightly confusing because it has an internal regulator on the power supply that uses an external pass transistor. And also the only ground pin is labelled AGND, which might lead you to think it didn't need to be connected to the digital ground. |
I could solve the issue without slowing down the ESP32. Here is my read() method. It does not allow to read with different gain or from the B port but I don't have anymore glitches:
I think the main difference is to first send the complete pulse and then read the DOUT signal. This way the HX711 has more time to produce the signal... |
I disable interrupts when CLOCKing:
CLOCK stable now, no glitches by 48 hours period yet. |
It is said from a post that the ESP32 is too fast for HX711, thus will output wierd data. After slow down the CPU, althoug the board processes much slower, but the data is much more accurate and stable. The resources: bogde/HX711#75
Dear @lemio, @robmacl and @nae9, we just pushed some amendments [1] to this popular library where we rebundled some pieces which have been loosely floating around here. While being at it, we also cherry-picked your valuable contributions and suggestions which not have been merged yet, thanks again. For more details, please follow the issue referenced above. As we actually don't have any hardware on our workbench, we will be happy to hear about successful reports from the community running this on a real iron, actually on as much as possible things supported by the Arduino framework. Maybe you can afford some minutes to check whether the status quo works as expected if you still have a MCU and a HX711 breakout around? We will appreciate your feedback, thanks already. With kind regards, |
I got It to work with ESPS32 however I never managed to get more that 8 reading per second. Has anybody managed to get it working with 80 measure per second? I use the same HX711 module with other Arduino board an I can do 80 measures per second |
I found a problem with this (and some of the other HX711 libraries), it seems like the library is too fast for the HX711 if the clock speed of the MCU is higher.
It seems that the real speed is actually below the minimal values in the data sheet
This was the image before
And this after
I changed the shiftIn to be slower:
and changed the GAIN part of read:
The text was updated successfully, but these errors were encountered: