Using a load cell with the extension board and HX711
-
Hey guys,
hope you can help me out here.
I'm trying to connect a load cell via the HX711 module and using it all with Arduino IDE.
Pin connections are:
HX7111 Ext. board GND GND DT PIN_D02 SCK PIN_D03 VCC Vout It is nothing special since I use a basic example ("HX_kitchen_scale") of the Arduino lib "HX711". Using the same pins for the Arduino UNO (also DUE) is working just fine.
I have measured the signal of the clock with an ocsilloscope and it differs from the Arduino to the Spresense of course.' Maybe that is the culprit', I thought because the HX711 expects the clock frequency to be lower (see https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf).
So I actually copied the source of the header/source file of the HX711 lib and the example sketch to a new sketch to play around with it. I noticed the linesv.data[2] = shiftIn(_dataPin, _clockPin, MSBFIRST); v.data[1] = shiftIn(_dataPin, _clockPin, MSBFIRST); v.data[0] = shiftIn(_dataPin, _clockPin, MSBFIRST);
in the
read()
method of the lib. I copied the code of theshiftIn
function again and changed the commented linesuint8_t shiftInMod(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint32_t myDelay) // myDelay is new { uint8_t value = 0; uint8_t i; for (i = 0; i < 8; ++i) { digitalWrite(clockPin, HIGH); if (bitOrder == LSBFIRST) value |= digitalRead(dataPin) << i; else value |= digitalRead(dataPin) << (7 - i); delayMicroseconds(myDelay); // this is new digitalWrite(clockPin, LOW); delayMicroseconds(myDelay); // this is new } return value; }
A delay of 5 µs makes the clock of the Spresense almost look like the clock of the UNO.
Still the problem is that I just get readings of
nan
only.
I also changed the data pin and clock pin to other pins but nothing works.As a voltage I use the 5 V from the extension board and I tried to level up the current with a transistor but took it out again since it did not work, either. So actually I don't really know if it is a software or a hardware problem.
I just hope that somebody has an idea or even used a load cell with the HX711 module.
Wish you all a nice day,
MezmerizeR -
Hi @MezmerizeR
I don't know what library you use but I guess this one: https://github.com/bogde/HX711
They support fast CPU boards here: https://github.com/bogde/HX711/blob/bc5a7e5a0d518a0f384bd30105cdce0773e20028/src/HX711.cpp#L24, but unfortunately Spresense is not added there.
Could you please try adding
|| defined(ARDUINO_ARCH_SPRESENSE)
here in your local library?Best Regards,
Kamil Tomaszewski -
Hey Kamil,
thank you for your answer. I used another HX711 lib before. I switched to the one that you have mentioned and put the
define
in there. But still I did not get the load cell to output values - just zeros. As in the other lib, I pulled the pins for clock and data to LOW in the beginning since the reading will not start if they are on HIGH.I don't know. The clock looks actually pretty good. Nice amplitude and regular. Maybe it is something with the amplifier board?
My idea is now to use the analog pins as input without the amplifier board. The ADC from the Spresense analog pins is only 16 bit instead of 24 bit with the amp but maybe I get it to give me some useful output with some other circuit I have not thought about yet.Thanks for your help anyways! If you have another suggestion for me, I'd still be open for that. It bothers me a little that it works right away on the UNO. Still I want to use the Spresense because of the multiple cores ;).
Best,
MezmerizeR -
Hey guys,
I have a new guess why it is not working:
The Spresense never hits 0 V. After pulsing the clock the voltage stays around 0.2 V which is probably not 'LOW' for some applications and therefore the lib that I'm using will never go into 'ready state'. Do you have a hint for me how to handle the offset? As I mentioned, the UNO does not have the problem. The UNO is almost at 0 V after pulsing.
Best,
MezmerizeR -
Hi @MezmerizeR
Have you tried to use an operating voltage of 3.3V on the GPIO pins?
https://developer.sony.com/develop/spresense/docs/hw_docs_en.html#_setting_operating_voltageIf you change it then you also need to connect VCC to 3.3V and not to Vout.
Best Regards,
Kamil Tomaszewski -
sorry for the late reply.
Yes, I've tried it and still there is an offset in Voltage which seems to be not LOW for the load cell.Still the load cell is not working on the Spresense.
Best,
MezmerizeR