I am using the Adafruit ESP32-S3 Reverse TFT Feather (product 5691), with Adafruit HX711 break out (product 5974), and Adafruit Strain Gauge Load Call 5kg (product 4541).
I am trying to build a scale and have the output displayed on the Feather's TFT, using the Arduino 1.8.9 IDE. I have been able to read the load cell without problems when the results are limited to the serial monitor. See code below. I have also been able to display test numbers on the TFT without problems as long as I don't call on the HX711. See code below. The problem is that when I try to both read the HX711 and then display the output on the TFT, something is compromising the results and I get nothing but random numbers. Can anyone help me understand what the problem is? Thank you!
This code works as expected, with valid load scale results shown in the serial monitor:
#include "Adafruit_HX711.h"
#include "Arduino.h"
const uint8_t DATA_PIN = A4;
const uint8_t CLOCK_PIN = A5;
Adafruit_HX711 hx711(DATA_PIN, CLOCK_PIN);
float BU=0;
void setup() {
Serial.begin(115200);
while (!Serial) {delay(10);}
Serial.println("Adafruit HX711 Test!");
hx711.begin();
Serial.println("Tareing....");
for (uint8_t t=0; t<3; t++)
{ hx711.tareA(hx711.readChannelRaw(CHAN_A_GAIN_128));
hx711.tareA(hx711.readChannelRaw(CHAN_A_GAIN_128));
hx711.tareB(hx711.readChannelRaw(CHAN_B_GAIN_32));
hx711.tareB(hx711.readChannelRaw(CHAN_B_GAIN_32));}}
void loop() {
int32_t weightA128 = hx711.readChannelBlocking(CHAN_A_GAIN_128);
BU=weightA128/100000.0;
Serial.print("Channel A (Gain 128): ");
Serial.println(abs(BU),1);}
This code also works just fine, displaying the test number 2.7 on the screen as expected:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup(void) {
pinMode(TFT_BACKLITE, OUTPUT);
digitalWrite(TFT_BACKLITE, HIGH);
pinMode(TFT_I2C_POWER, OUTPUT);
digitalWrite(TFT_I2C_POWER, HIGH);
delay(10);
tft.init(135, 240); // Init ST7789 240x135
tft.setRotation(3);
tft.fillScreen(ST77XX_BLACK);}
void loop() {
tft.setTextWrap(false);
tft.setCursor(30, 30);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(10);
tft.println("2.7");
delay(10000);}
When I try to combine the code above and display the HX711 results on the TFT, however, I get random numbers for output. Here is the code for that:
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
#include "Adafruit_HX711.h"
#include "Arduino.h"
const uint8_t DATA_PIN = A4;
const uint8_t CLOCK_PIN = A5;
Adafruit_HX711 hx711(DATA_PIN, CLOCK_PIN);
float BU=0;
void setup(void) {
Serial.begin(115200);
while (!Serial) {delay(10);}
Serial.println("Adafruit HX711 Test!");
hx711.begin();
Serial.println("Tareing....");
for (uint8_t t=0; t<3; t++)
{ hx711.tareA(hx711.readChannelRaw(CHAN_A_GAIN_128));
hx711.tareA(hx711.readChannelRaw(CHAN_A_GAIN_128));
hx711.tareB(hx711.readChannelRaw(CHAN_B_GAIN_32));
hx711.tareB(hx711.readChannelRaw(CHAN_B_GAIN_32));}
pinMode(TFT_BACKLITE, OUTPUT);
digitalWrite(TFT_BACKLITE, HIGH);
pinMode(TFT_I2C_POWER, OUTPUT);
digitalWrite(TFT_I2C_POWER, HIGH);
delay(10);
tft.init(135, 240); // Init ST7789 240x135
tft.setRotation(3);
tft.fillScreen(ST77XX_BLACK);}
void loop() {
int32_t weightA128 = hx711.readChannelBlocking(CHAN_A_GAIN_128);
BU=weightA128/100000.0;
Serial.print("Channel A (Gain 128): ");
Serial.println(abs(BU),1);
tft.setTextWrap(false);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(30, 30);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(10);
tft.println(BU,1);
delay(100);}