HX711

Here we have two sets of code for an HX711 and a load cell. The first I found online, the second is from examples in the Arduino IDE.

I'd like to clear up why analog inputs are used (#A0, #A1) in both sets of code. I looked at the datasheet and can see no reason for not using a digital input. Is it something to do with the HX.711 library?

/* sample for digital weight scale of hx711, display with a HD44780 liquid crtstal monitor
 *
 * hardware design: syyyd
 * available at http://syyyd.taobao.com
 *
 * library design: Weihong Guan (@aguegu)
 * http://aguegu.net
 *
 * library host on
 * https://github.com/aguegu/Arduino
 */

// Hx711.DOUT - pin #A1
// Hx711.SCK - pin #A0

#include <hx711.h>

Hx711 scale(A1, A0);

void setup() {

  Serial.begin(9600);

}

void loop() {

  Serial.print(scale.getGram(), 1);
  Serial.println(" g");

  delay(200);
#include "HX711.h"

// HX711.DOUT	- pin #A1
// HX711.PD_SCK	- pin #A0

HX711 scale(A1, A0);		// parameter "gain" is ommited; the default value 128 is used by the library

void setup() {
  Serial.begin(38400);
  Serial.println("HX711 Demo");

  Serial.println("Before setting up the scale:");
  Serial.print("read: \t\t");
  Serial.println(scale.read());			// print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));  	// print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight (not set yet)

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);	// print the average of 5 readings from the ADC minus tare weight (not set) divided 
						// by the SCALE parameter (not set yet)  

  scale.set_scale(2280.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.tare();				        // reset the scale to 0

  Serial.println("After setting up the scale:");

  Serial.print("read: \t\t");
  Serial.println(scale.read());                 // print a raw reading from the ADC

  Serial.print("read average: \t\t");
  Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC

  Serial.print("get value: \t\t");
  Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight, set with tare()

  Serial.print("get units: \t\t");
  Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided 
						// by the SCALE parameter set with set_scale

  Serial.println("Readings:");
}

void loop() {
  Serial.print("one reading:\t");
  Serial.print(scale.get_units(), 1);
  Serial.print("\t| average:\t");
  Serial.println(scale.get_units(10), 1);

  scale.power_down();			        // put the ADC in sleep mode
  delay(5000);
  scale.power_up();
}

I'd like to clear up why analog inputs are used (#A0, #A1) in both sets of code. I looked at the datasheet and can see no reason for not using a digital input.

It is a load cell, you want to measure a load. A digital input will only give you high or low where as an analogue input will give you a number between 0 and 1023, this number will change as the load changes.

No idea why the analog inputs were used, any pin will work. The library calls pinMode() to setup one digital in (DOUT from hx711) and one digital out (SCK) which is all the i/o that the hx711 requires.

Hi guys
It appears that the interface uses some kind of serial link. Not I2C but clock and data. It is discussed here. What kind of protocol does the HX711 use? - Networking, Protocols, and Devices - Arduino Forum

That's what I thought avr_fred. I hesitate to comment on Grumpy_Mike's reply but we're talking about the output of the HX711 here not the load cell itself. I've attached the timing/control diagram which is digital.

I was wondering if there was some unspecified reason for the use of analog pins.