Strain Gauge with ESP32

Hi All,

I'm trying to read values from a strain gauge (using Spark Fun's HX711 amplifier board) with an ESP32. The problem is that I can't upload the code from the Arduino IDE to the ESP32. I keep getting the following error message: "Error compiling for board ESP32 Dev Module".

The code I'm trying to upload is as follows:

/*
 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  21
#define CLK  22

HX711 scale;

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.begin(DOUT, CLK);
  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;
  }
}

I've installed the "esp32 by Espressif Systems version 1.0.4" using the boards manager in the Arduino IDE and I was able to upload other sketches to the ESP32. This is the 1st time I've got trouble uploading a sketch to the ESP32.

Any help would be greatly appreciated!

ooh great, another HX711 issue to look at! I've beenn playing with these lately so hopefully may have something to give back to the community :slight_smile: I've been able to get these going using two different libraries on Nano, Uno and ESP8266 so far.

ESP32 may have some issues similar to ESP8266. The main issue with ESP is that the example libraries have code for Uno/Nano which gives unsuitable pin mapping declarations for ESP8266. But this doesn't stop the code compiling. You have uploading covered so that seems not an issue, unless circumstances happened to change at the same time. I happen to have a couple of ESP32 cam modules I've successfully loaded code to, so very interested to have a "play" and see what happens on the bench at this end.

Hmm, dug out an ESP32 Camera module, verified I could upload then tried the HX71 code, working ok.
The main change was to choose the interface pins. Went for Data Pin = 2, SCK = 14.
edit - discovered IO2 was a strapping pin so moved Data to IO15

Are there any extra details in the IDE status panel when the failure happens?

Hi Azeo,

Thank you very much for your reply!

I had a closer look at the error message and it seems that the problem was that there were two HX711.h files (from two different libraries I tested). After deleting one of the two files, the sketch compiled just fine :slight_smile:

Cheers,

Christian

Hi Christian, no problem! Glad it's going. I had a compilation problem recently where expanding and scrolling through the error messages helped find the issue, so it struck me it may be a useful place to look for any further clues.

During testing, it's handy to be able to enter the cal factor from the serial monitor/plotter, as well as just incrementing / decrementing by a smaller amount like +- 1. It's also useful to be able to perform a tare from a button and the serial monitor.

The Arduino serial plotter is not very friendly for load cells/ weighing scales, but can be contrived to prevent auto-scaling by plotting some axis lines also used to limit the signal, preferably also movable from serial input, so can be made useful before moving on to something else. Have Fun :slight_smile:

Cheers,
azeo