I am trying to use the DFRobot HX711 Scale kit for a project for my son's school project. I downloaded the code from the website and I am trying to use the kit with a new Uno 4, this is different than what DFRobot uses in their example. I have the following wiring:
SDA output => SDA Arduino Board
SCL output => SCL Arduino Board
I think my problem is setting the address as I keep getting an error when I try to upload the code. The code starts like this:
//DFRobot_HX711_I2C MyScale(&Wire,/*addr=*/0x64);
DFRobot_HX711_I2C MyScale;
My address is 0x64, but how do I add that to the code above? I have tried various combinations but can't seem to get it to work.
In file included from /Users/michaelspee/Documents/Arduino/Dog_Feeder/Dog_Feeder.ino:1:0:
/Users/michaelspee/Documents/Arduino/libraries/DFRobot_HX711_I2C/DFRobot_HX711_I2C.h:26:33: error: expected ',' before 'sensor'
#define HX711_I2C_ADDR (0x64) sensor IIC address*/
^
/Users/michaelspee/Documents/Arduino/libraries/DFRobot_HX711_I2C/DFRobot_HX711_I2C.h:48:60: note: in expansion of macro 'HX711_I2C_ADDR'
DFRobot_HX711_I2C(TwoWire * pWire = &Wire,uint8_t addr = HX711_I2C_ADDR);
That's a compile error, not an upload error.
So we'd have to see the complete sketch to know what's causing it.
That is the error I get when I use the following:
//DFRobot_HX711_I2C MyScale(&Wire,/*addr=*/0x64);
DFRobot_HX711_I2C MyScale(&Wire,/*addr=*/0x64);
#include <DFRobot_HX711_I2C.h>
//DFRobot_HX711_I2C MyScale(&Wire,/*addr=*/0x64);
DFRobot_HX711_I2C MyScale(&Wire,/*addr=*/0x64);
float Weight = 0;
void setup() {
Serial.begin(9600);
while (!MyScale.begin()) {
Serial.println("The initialization of the chip is failed, please confirm whether the chip connection is correct");
delay(1000);
}
//// Set the calibration weight when the weight sensor module is automatically calibrated (g)
MyScale.setCalWeight(50);
// Set the trigger threshold (G) for automatic calibration of the weight sensor module. When only the weight of the object on the scale is greater than this value, the module will start the calibration process
// This value cannot be greater than the calibration weight of the setCalWeight() setting
MyScale.setThreshold(30);
// Obtain the calibration value. The accurate calibration value can be obtained after the calibration operation is completed
Serial.print("the calibration value of the sensor is: ");
Serial.println(MyScale.getCalibration());
MyScale.setCalibration(MyScale.getCalibration());
delay(1000);
}
void loop() {
Weight = MyScale.readWeight();
Serial.print("weight is: ");
if(Weight > 0.5){
Serial.print(Weight, 1);
}
else{
Serial.print(0, 1);
}
Serial.println(" g");
delay(1000);
}
Pull up the DFRobot_HX711_I2C.h file and change line 26 from
#define HX711_I2C_ADDR (0x64) sensor IIC address*/
to
#define HX711_I2C_ADDR (0x64) /*sensor IIC address*/
I always get a sinking feeling in the pit of my stomach when I come across such an obvious error in a manufacturer's library...
Haha, thank you! That is an amazing catch. I will see if I can figure out where to find that file and edit it. I assume it is in one of my Arduino folders.
The library should be in the libraries directory under the sketchbook directory.
Thank you both for the help! I found it.
The scale is working great now, I struggled with this for a few hours. Thank you!
It seems to have been fixed. From DFRobot_HX711_I2C/DFRobot_HX711_I2C.h at master · DFRobot/DFRobot_HX711_I2C · GitHub
#define HX711_I2C_ADDR (0x64) ///<sensor IIC address
Having fixed the problem three years ago, one wonders why they haven't made a new release incorporating the fix, which would make it available to folks who obtain their libraries from the Library Manager and don't yet have the technical know how to go to Github and obtain the most recent code.
Also true. I did not check the library that is available through the library manager.