Arduino uno crashes in my hx711 scale project

Hello everyone, I have small problem and this is my first real project.
I've built weighing scale for potato bags. It has two sets of Arduino uno, hx711, screen and load cells. I attach the diagram. Basically it is two separate systems with common power supply.

In terms of accuracy it works great, however every 10-30 min arduino crashes. It stops updating digits on screen, sometimes distorts digits and ceases communication through serial port. However, It doesn't happen for both at the same time, one is crashing more often than the other.

Currently I suspect power supply, scale is located close to heavy machinery, so I suppose the current quality is not optimal. I use switching power supply 9V 2A to power both arduinos, i've already ordered linear 9V 0.5A. Hope this helps.

Could you please take a look at my code, I guess it's not the best, I've made it myself out of two others. Still, maybe there's something bad going on.

Thanks for any help!

#include <HX711.h>
#include <Wire.h>


#define DOUT  6
#define CLK  7

byte saa1064 = 0x70 >> 1; // SAA1064-based screen
int digits[11]={252, 12, 218, 158, 46, 182, 246, 28, 254, 190, 0}; // ditigs definition
int digitsn[2]={2,64}; // minus and underline
HX711 scale;

float calibration_factor = -811; 
float units;

void setup() {
  
Wire.begin();
delay(500);
initDisplay();
scale.begin(DOUT, CLK);
delay(500);
Serial.begin(9600);
scale.set_scale();
scale.tare();

long zero_factor = scale.read_average(); // actually iam not sure is it necessary
}

void initDisplay()
{
Wire.beginTransmission(saa1064);
Wire.write(B00000000);
Wire.write(B01000111);
Wire.endTransmission();
}


void displayInteger(int num) // displays the number 'num'
{
 if (num<0) // if the weight is negative 
 {
 int thousand, hundred, ten, one; // breakdown number into columns
 num=num*(-1); // my small trick for the code to work normally
 thousand = num/1000;
 hundred = (num-(thousand*1000))/100;
 ten = (num-((thousand*1000)+(hundred*100)))/10;
 one = num-((thousand*1000)+(hundred*100)+(ten*10));
 if (hundred==0 && num<100) { hundred=11; } // 11 is blank digit, so this function takes care of unnecessary zeros
 if (ten==0 && num<10) { ten=11; } 
 Wire.beginTransmission(saa1064);
 Wire.write(1);
 Wire.write(digits[one]);
 Wire.write(digits[ten]);
 Wire.write(digits[hundred]);
 Wire.write(digitsn[0]); //minus symbol
 Wire.endTransmission();
 delay(10);
 }
 else
 if (num>=0) // normal work
 { 
  int thousand, hundred, ten, one; // breakdown number into columns
 thousand = num/1000;
 hundred = (num-(thousand*1000))/100;
 ten = (num-((thousand*1000)+(hundred*100)))/10;
 one = num-((thousand*1000)+(hundred*100)+(ten*10));
 if (thousand==0) { thousand=11; } // 11 is blank digit, so this function takes care of unnecessary zeros
 if (hundred==0 && num<100) { hundred=11; } 
 if (ten==0 && num<10) { ten=11; } 

 Wire.beginTransmission(saa1064);
 Wire.write(1);
 Wire.write(digits[one]);
 Wire.write(digits[ten]);
 Wire.write(digits[hundred]);
 Wire.write(digits[thousand]);
 Wire.endTransmission();
 delay(10);
 }
}

void loop() {

scale.set_scale(calibration_factor); 
units=scale.get_units(2); // it takes average of two readings
displayInteger(units);  
Serial.print(units);
Serial.print(" kilograms"); 
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();
 
}

power on your drawing seems complicated so worth looking at

In the code, you define digits like thisint digits[11] = {252, 12, 218, 158, 46, 182, 246, 28, 254, 190, 0}; // ditigs definitionso it has 11 entries, with index 0 to 10

then I see you access an illegal digit entry

    if (hundred == 0 && num < 100) {
      hundred = 11;  // 11 is blank digit, so this function takes care of unnecessary zeros
    }
    if (ten == 0 && num < 10) {
      ten = 11;
    }
...
    Wire.write(digits[ten]);
    Wire.write(digits[hundred]);

==> you can't access digits[11]

you might want to double check that the number is between Ok boundaries as if I send -12515 you'll do weird stuff

J-M-L:
power on your drawing seems complicated so worth looking at

Well I've stitched all grounds together, 9V goes to arduinos and 12V to both screens.

J-M-L:
In the code, you define digits like this

int digits[11] = {252, 12, 218, 158, 46, 182, 246, 28, 254, 190, 0}; // ditigs definition

so it has 11 entries, with index 0 to 10

then I see you access an illegal digit entry

    if (hundred == 0 && num < 100) {

hundred = 11;  // 11 is blank digit, so this function takes care of unnecessary zeros
   }
   if (ten == 0 && num < 10) {
     ten = 11;
   }
...
   Wire.write(digits[ten]);
   Wire.write(digits[hundred]);



==> you can't access digits[11]

you might want to double check that the number is between Ok boundaries as if I send -12515 you'll do weird stuff

I added 10th element to have blank digit useful for hiding zeros e.g. 20 instead of 0020, i assumed that he will never ask for it since he will only get 0-9 in arithmetic. Do you think its a problem?
Actually all I need is to present numbers from -999 to 2000. Rarely when the machine tare is not right i can see it tries to show numbers lower than -999 by just cutting thousands away, like -1020 is -020. Its not a problem for me.

are the screen commands meant for 5V SCL/SDA ?

As far as I know, it's "TTL level signal"

OK.

In terms of accuracy it works great, however every 10-30 min arduino crashes. It stops updating digits on screen, sometimes distorts digits and ceases communication through serial port. However, It doesn't happen for both at the same time, one is crashing more often than the other.

May be you'd be better off adding pull-up (4.7kΩ) for SCL and SDA.

1 Like

Sorry for late response. Adding pull-up fixed the problems. Later had to deal with wrong readings showing up in regular pattern. I've changed the power source again and checked connectors, up until now no problems. Bit scared to touch anything. I plan to restart all project, fix connections and add wifi connectivity. Thank you a lot J-M-L, I send you internet hugs

Good to hear
Have fun

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