I'm trying to modify the stock code that reads a loadcell weight via a HX711.
I've got the HX711.h, the example code I have uses a line:
units = scale.get_units(), 10;
how do I find out more about the get_units command? (I would like to know what the 10 refers to but also for the future know how to look up thin information thanks)
Aaaaargh_rduino:
I've got the HX711.h, the example code I have uses a line:
units = scale.get_units(), 10;
Better double check that. I definitely doesn't do what you think it does. Try printing the resultant value of 'units'.
how do I find out more about the get_units command? (I would like to know what the 10 refers to but also for the future know how to look up thin information thanks)
gfvalvo:
Better double check that. I definitely doesn't do what you think it does. Try printing the resultant value of 'units'.
Look in HX711.h and HX711.cpp.
The whole code is below - it does work... not sure how though?
/*
Setup your scale and start the sketch WITHOUT a weight on the scale
Once readings are displayed place the weight on the scale
Press +/- or a/z to adjust the calibration_factor until the output readings match the known weight
Arduino pin 6 -> HX711 CLK
Arduino pin 5 -> HX711 DOUT
Arduino pin 5V -> HX711 VCC
Arduino pin GND -> HX711 GND
*/
#include "HX711.h"
HX711 scale(5, 6);
float calibration_factor = 2230; // this calibration factor is adjusted according to my load cell
float units;
float ounces;
void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");
scale.set_scale();
scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}
void loop() {
scale.set_scale(calibration_factor); //Adjust to this calibration factor
Serial.print("Reading: ");
units = scale.get_units(), 10;
/*if (units < 0)
{
units = 0.00;
}
*/
ounces = units * 0.035274;
Serial.print(units);
Serial.print(" grams");
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
Sorry I think you guys are jumping a bit ahead of me,
What is the precedence in C - the language (in which case I definitely dont understand) or commas (which I might)
So what do we think the 10 does?
I opened hx711.h in notepad but could not find an explanation what for example the get scale command does, what syntax it needs etc.
What I'm trying to do is read from 2 scales quickly one after another.
I tried
HX711 scale(3,2);
scale.set_scale(calibration_factor1); //Adjust to this calibration factor
unit1 = scale.get_units(), 10;
HX711 scale(5,6);
scale.set_scale(calibration_factor1); //Adjust to this calibration factor
unit2 = scale.get_units(), 10;
but this won't compile as I cannot redeclare HX711??
I have used each section of the HX711 seperately, Iand it correctly reads from one sensor or the other (so the numbers must refer to pins I'm using for sensor connection) - but now I'm a bit stumped how to get readings from both scales in the same program??
The "Order of Precedence" is the order in which operations are done (what operation precedes another). For example, that is why "5 + 3 * 4" is 17 (5+12) and not 32 (8 * 4).
A "higher precedence" means that the '=' (assignment operator) is done before the ',' (comma operator). The line is treated as if you wrote:
(units = scale.get_units()) , 10;
The comma operator is almost never used. What is does is ignore the value to the left of the comma. About the only place I ever see the comma operator used is in a 'for' loop, for example:
for (i=0, j= 255; i < 128; i++, j--)
This is a loop with i counting up from 0 to 127 and j counting down from 255. Unless the loop does something else strange with i or j you could get the same effect with: