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();
}