0
\$\begingroup\$

We're going to use an HX711 amplifier to read data from a strain gauge - the SparkFun page says you can use any GPIO pins but it one is "clock" and one is "data." What does that mean in this case? Does that mean in needs to be connected to an SCLK pin? Or can I really use any GPIO pin?

\$\endgroup\$
  • \$\begingroup\$ Depends on whether you are using bit-banged SPI routines or not. \$\endgroup\$ – Dwayne Reid Apr 11 '18 at 2:09
  • \$\begingroup\$ The HX711 has to be bit-bashed, it is not I2C or SPI. You can use any GPIO pins as the clock and data lines. Read the code provided by Sparkfun for the Arduino, that should make it all clear. \$\endgroup\$ – Jack Creasey Apr 11 '18 at 5:41
1
\$\begingroup\$

The statement of HX711 amplifier module from Sparkfun says,

The example code has DAT and CLK hooked up to pin 3 and 2 respectively, but this is easily changed in the code. Any GPIO pin will work for either.

Also, from the example code, as Jack Creasy says, you can confirm the above statement:

/*
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This is the calibration sketch. Use it to determine the calibration_factor that the main example uses. It also
 outputs the zero_factor useful for projects that have a permanent mass on the scale in between power cycles.

 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
 Use this calibration_factor on the example sketch

 This example assumes pounds (lbs). If you prefer kilograms, change the Serial.print(" lbs"); line to kg. The
 calibration factor will be significantly different but it will be linearly related to lbs (1 lbs = 0.453592 kg).

 Your calibration factor may be very positive or very negative. It all depends on the setup of your scale system
 and the direction the sensors deflect from zero state
 This example code uses bogde's excellent library: https://github.com/bogde/HX711
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE
 Arduino pin 2 -> HX711 CLK
 3 -> DOUT
 5V -> VCC
 GND -> GND

 >>>>**Most any pin on the Arduino Uno will be compatible with DOUT/CLK.**

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/

#include "HX711.h"

#define DOUT  3
#define CLK  2

HX711 scale(DOUT, CLK);

float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup

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: ");
  Serial.print(scale.get_units(), 1);
  Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
  Serial.print(" calibration_factor: ");
  Serial.print(calibration_factor);
  Serial.println();

  if(Serial.available())
  {
    char temp = Serial.read();
    if(temp == '+' || temp == 'a')
      calibration_factor += 10;
    else if(temp == '-' || temp == 'z')
      calibration_factor -= 10;
  }
}

See the '>>>>' marked line. You can use any pin in Arduino. Hence, HX711 amplifier's D_OUT and SCK pins don't need to be connected only with I2C pins of the microcontroller.

The same case is for Raspberrypi. Like Arduino, RaspberryPi also can be used with HX711 amplifier via python library of HX711. And there is no need to use SCK pin of Raspberrypi. For more info, find this tutorial.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.