HX 711 SCK pin conflict - Help needed

Hi, I am trying to figure out if there's a possible conflict between an HX711 scale and an i2c ADS1115 ADC converter using esp32. The project is an automated cat feeder

My setup is:

  • esp32 mcu

  • L 298 motor driver

  • ADS 1115 analog to digital converter

  • DC high torque motor

  • small vibrating motor in order to prevent kibble from getting stuck

  • HX711 scale sensor

  • DS3231 clock module

Here's how it works: it is battery powered, the mcu stays in deep sleep most of the times and is awaken either from a manual pushbutton or from the INT pin on the DS3231 which calculate various alarms throughout the day. At that point, it should tare the scale, fill the bowl using the motor, vibrate, measure the scale in order to know how much food was provided, read the battery state using the adc and publish the results on my home assistant server

It worked flawlessly until i tried to install the strain gauge in order to weight the food.
In fact, it still does if I do comment the gauge lines or unplug its connector, which makes me suspect tat there might be a conflict between the sck pin of the HX711 and pin 18 which drives the motor.
The DC motor is activated between the tare and read method of the HX711. It also seems that HX711 affects the I2C readings of the adc. I am actually confused and first of all I am wondering wheter it would make sense to power down the scale after taring it and the power it back for measuring of if the powering down would totally erase the taring of the scale.

I am posting my code below, thank you.


#define VIBA 26
#define VIBB 27
#define IN1  18
#define IN2  19
#define BUT  2
#define wakepin  35
#define BUTTON_PIN_BITMASK 0x800000004
const int calibration_factor = 378;
const int LOADCELL_DOUT_PIN = 16;
const int LOADCELL_SCK_PIN = 17;
float this_cycle_feed=0;
float on_the_scale=0;
bool readyToSleep=false;
#include <WiFi.h>
#include <HTTPClient.h> 
#include <Wire.h>
#include <SPIFFS.h>
#include <ESPmDNS.h>
#include <Arduino.h>
#include "time.h"
#include <string.h>
#include <RTClibExtended.h>
#include <Adafruit_ADS1015.h>
#include "HX711.h"

// Replace the next variables with your SSID/Password combination
const char* ssid = "xx";
const char* password = "xx";
//const char* ntpServer = "pool.ntp.org";
//const long  gmtOffset_sec = 3600;
//const int   daylightOffset_sec = 3600;

//Your Domain name with URL path or IP address with path
const char* serverName = "xx";
DateTime pubb;
RTC_DS3231 RTC;
HX711 scale;
RTC_DATA_ATTR float prevgrams = 0;
Adafruit_ADS1115 ads(0x48);
float Voltage;
void managealarm(){

//RTC.adjust(DateTime(2022,4,10,12,28,0));
//pulisci allarmi
delay(1000);
RTC.armAlarm(1, false);
RTC.clearAlarm(1);
RTC.alarmInterrupt(1, false);
RTC.armAlarm(2, false);
RTC.clearAlarm(2);
RTC.alarmInterrupt(2, false);
RTC.writeSqwPinMode(DS3231_OFF);

  
//studio sia i delta positivi che negativi. i delta positivi ci sono se esiste una sveglia oggi più avanti di ora, negative sono tutte quelle già passate
//minpos è tutta la roba in avanti, max neg tutta la roba indietro
//int minpos = 86400; //24 ore
//int maxneg = 0;
int nextal=86400;
int delta=0;
  
//{al1 hours, al1 minutes, al2 hours, al2 minutes, al3 hours....
int myalarms[]={7,1,10,30,13,30,16,30,19,30,23,1};
//time_t variable type, which is the number of seconds elapsed since 1970
DateTime now= RTC.now();
for (int i=0;i<12; i=i+2)
{
int alhrs = int(myalarms[i]);
int almins = int(myalarms[i+1]);
DateTime sveglia(now.year(),now.month(),now.day(),alhrs,almins,0);

delta = sveglia.unixtime()-now.unixtime();
if(delta>0){
nextal=min(nextal,delta) ; 
}
else{
nextal=min(nextal,86400-abs(delta));  
}
}
nextal=now.unixtime()+nextal;
DateTime setnextalarm (nextal);

RTC.setAlarm(ALM1_MATCH_HOURS,0,setnextalarm.minute(),setnextalarm.hour(),0);
RTC.armAlarm(1, true);
RTC.alarmInterrupt(1, true);
pubb=setnextalarm;

}

void battread() {
int16_t adc0;
Voltage=0;
adc0=0;
ads.begin();
delay(500);
adc0 = ads.readADC_SingleEnded(0);
delay(100);
Voltage = (adc0 * 0.1875)*10.4/1000;//470k+470k-100k divider
delay(100);
}

void api() {
WiFi.begin(ssid, password);
int k=0;
  while ((WiFi.status() != WL_CONNECTED) and (k<10)) {
    delay(500);
    k=k+1;
  }
 
  
  
  if(WiFi.status()== WL_CONNECTED){
      HTTPClient http;
      String serverPath = String(serverName)+String("sensor.catfeed_battery") ;      
      http.begin(serverPath.c_str());
      http.addHeader("Authorization","Bearer xx");
      http.addHeader("Content-Type", "application/json");
      int httpResponseCode = http.POST("{\"entity_id\": \"sensor.catfeed_battery\",\"state\":\""+String(Voltage)+"\",\"attributes\":{\"friendly_name\":\"pet_batt\",\"icon\":\"mdi:battery\"}}");
      http.end();

      delay(300);

      serverPath = String(serverName)+String("sensor.catfeed_wifisig") ;
      http.begin(serverPath.c_str());
      http.addHeader("Authorization","Bearer xx");
      http.addHeader("Content-Type", "application/json");
      httpResponseCode = http.POST("{\"entity_id\": \"sensor.catfeed_wifisig\",\"state\":\""+String(WiFi.RSSI())+"\",\"attributes\":{\"friendly_name\":\"pet_wifisignal\",\"icon\":\"mdi:battery\"}}");
      http.end();

      delay(300);

      serverPath = String(serverName)+String("sensor.on_scale") ;
      http.begin(serverPath.c_str());
      http.addHeader("Authorization","Bearer xx");
      http.addHeader("Content-Type", "application/json");
      httpResponseCode = http.POST("{\"entity_id\": \"sensor.on_scale\",\"state\":\""+String(this_cycle_feed)+"\",\"attributes\":{\"friendly_name\":\"pet_onscale\",\"icon\":\"mdi:battery\"}}");
      http.end();

      delay(300);
      
      serverPath = String(serverName)+String("sensor.nextalarm") ;
      http.begin(serverPath.c_str());
      http.addHeader("Authorization","Bearer xx");
      http.addHeader("Content-Type", "application/json");
      httpResponseCode = http.POST("{\"entity_id\": \"sensor.nextalarm\",\"state\":\""+String(pubb.hour())+"\",\"attributes\":{\"friendly_name\":\"pet_nextalarmhour\",\"icon\":\"mdi:battery\"}}");
      http.end();

     delay (300);
    
    WiFi.disconnect();
    delay (100);    
    readyToSleep =true;
  }
readyToSleep =true;
}


void setMotor(int direz) {
  if (direz == 1) {
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
  }
  else if (direz == 2) {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
  }
  else {
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
}
}


void erogazione(){
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
if (scale.wait_ready_retry(3,1000)){
delay(100);
scale.set_scale(calibration_factor);
scale.tare();
setMotor(2);
delay(5000);
delay(5000);
setMotor(3);
delay(1000);
this_cycle_feed=scale.get_units(5);
delay(100);

}
else{
setMotor(2);
delay(5000);
delay(5000);
setMotor(3);
delay(1000);
}
scale.power_down();
}

void vib() {
  digitalWrite(VIBA, HIGH);
  digitalWrite(VIBB, LOW);
  delay(1000);
  digitalWrite(VIBA, LOW);
  digitalWrite(VIBB, LOW);
  delay(100);
}



void setup() {
  
  pinMode(wakepin, INPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(BUT, INPUT);
  pinMode(VIBA, OUTPUT);
  pinMode(VIBB, OUTPUT);
  digitalWrite(VIBA, LOW);
  digitalWrite(VIBB, LOW);
  digitalWrite(BUT, LOW);
  delay(400);
  readyToSleep=false;
  managealarm();
  //attacco gli interrupt ai due pin
  esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK,ESP_EXT1_WAKEUP_ANY_HIGH);
//bitmask: pin 2 e 36. faccio 2^2+2^36=x, poi converto x in decimale

  while(!readyToSleep){
  delay(500);
  erogazione();
  vib();
  battread();
  api();
}


 readyToSleep =true;
  esp_deep_sleep_start();
  }
void loop() {
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.