Abnormal Problem

Hi,

I have a problem with the arduino uno
I have a weight scale project to measure weight from HX711 module and show value an LCD and send the value to computer by serial port. the problem is that, the program stop working automatically by itself and it rework when i put my finger (only touch it) on the ATMEGA IC.
I have more then one board, so I try my software on all of it but the problem still occur.
also I try other software on the boards and works so far so good
the HX711 module used is the DFrobot HX711 module
the HX711 librery used is: ardulibs/hx711 at master · aguegu/ardulibs · GitHub

thank you for any help

Sounds like you have a floating input.

Agreed

To get an answer please provide us with schematic and code. Otherwise it's as vague as "My car doesn't start!" and we don't even know if you have a car or just a bicycle!

Hi,

thank you for your reply
Sorry, I am new to this Form, so I don't take attention for the attachment availibility.
now, I attacehd the code file, but for the schematic I use the arduino UNO board and the connection is included (as comment) on the code.

Mr. aarg can you explain please, what you mean by "floating input"?!!!

thank you

_3-Read_LCD_NegL_EEPROM.ino (1.85 KB)

Hi, I think this could be the problem:

  attachInterrupt(0, InterruptCommand, HIGH);

If I remember, interrput zero is digital pin 2. What do you have connected to that?

The InterruptCommand code seems to implement a "Tare" function, calibrating zero on the scale. It then goes into an infinite loop for some reason.

This is not a good reason or way to implement an interrupt...

A "floating" input is one that is not connected to either ground (0V) or 5V. Such an input cannot be read reliably. Even waving your hand near it, or interference from nearby electrical equipment, can cause the reading to change.

Paul

thank you Mr. Paul for your reply,

Yeh, the interrupt 0 is on pin D2, and I connect it to a simple button (see attached pictures) the goal of the interrupt is s Tare function as you say. but if the function does to infinite loop as you say then I should press reset to rework but it is not, it is rework when i put my hand on it. I guess it is Floating input, but how I can solve it?!!

thank you

Button.PNG

Why not simply POST your code, instead of attaching it?

#include <LiquidCrystal.h>
#include "HX711.h"
#include "EEPROMex.h"

/*
 * connection:
   HX711 scale(Dout, Sck); 
   Hx711.DOUT - pin #A0
   Hx711.SCK  - pin #A1
*/
HX711 scale(A0, A1);

/* 
 * initialize the library with the numbers of the interface pins
 * connection:
   LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
   LCD RS pin to digital pin 12
   LCD Enable pin to digital pin 11
   LCD D4 pin to digital pin 5
   LCD D5 pin to digital pin 4
   LCD D6 pin to digital pin 3
   LCD D7 pin to digital pin 2
   LCD R/W pin to ground
   LCD VSS pin to ground
   LCD VCC pin to 5V
   10K resistor:
      ends to +5V and ground
      wiper to LCD VO pin (pin 3)
 */
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

long offset1 = 0;

 
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);            // set up the LCD's number of columns and rows
  offset1 = EEPROM.readLong(0x00);
  if(offset1 < 0 || offset1 > 16777215) offset1 = 0;
  scale.set_offset(offset1);
  scale.set_scale(2305);  // (scale) calcult by testing known weight
                                // scale = 2305 (with 1 kg LS), scale = 422 (with 5 kg LS)                              
  
  attachInterrupt(0, InterruptCommand, HIGH);
  lcd.setCursor(4,0);
  lcd.print("TRAGGING");
  lcd.setCursor(3,1);
  lcd.print("Smart Shelf");
  delay(2000);
}
 
void loop() {
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("units: ");
  lcd.setCursor(3,1); 
  lcd.print(scale.get_units(5),0);
  Serial.print(scale.read_average(5));
  Serial.print(" - offset = ");
  Serial.print(scale.get_value(5));
  Serial.print(" / scale = ");
  Serial.println(scale.get_units(5),0);
  lcd.setCursor(8,1);
  lcd.print(" Gram");
  delay(200);
}

void InterruptCommand()
{
  EEPROM.writeLong(0x00, scale.read_average(10));
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Now Press");
  lcd.setCursor(3,1);
  lcd.print("RESET button");
  while(1){};
}

Why on Earth is this   while(1){}; inside an interrupt?
Why on Earth is there an interrupt at all in this sketch?

Sorry, i read in “How to use this forum - please read.” that I should not post the code as it is (only a part of it or I should attach it). anyway, the while(1) is to stop work until the user press reset button to Reread the offset from the EEPROM.

what is “Why on Earth is this”!!!

AWOL:
Why not simply POST your code, instead of attaching it?

#include <LiquidCrystal.h>

#include “HX711.h”
#include “EEPROMex.h”

/*

  • connection:
      HX711 scale(Dout, Sck);
      Hx711.DOUT - pin #A0
      Hx711.SCK  - pin #A1
    */
    HX711 scale(A0, A1);

/*

  • initialize the library with the numbers of the interface pins
  • connection:
      LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
      LCD RS pin to digital pin 12
      LCD Enable pin to digital pin 11
      LCD D4 pin to digital pin 5
      LCD D5 pin to digital pin 4
      LCD D6 pin to digital pin 3
      LCD D7 pin to digital pin 2
      LCD R/W pin to ground
      LCD VSS pin to ground
      LCD VCC pin to 5V
      10K resistor:
          ends to +5V and ground
          wiper to LCD VO pin (pin 3)
    */
    LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

long offset1 = 0;

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);            // set up the LCD’s number of columns and rows
  offset1 = EEPROM.readLong(0x00);
  if(offset1 < 0 || offset1 > 16777215) offset1 = 0;
  scale.set_offset(offset1);
  scale.set_scale(2305);  // (scale) calcult by testing known weight
                                // scale = 2305 (with 1 kg LS), scale = 422 (with 5 kg LS)                             
 
  attachInterrupt(0, InterruptCommand, HIGH);
  lcd.setCursor(4,0);
  lcd.print(“TRAGGING”);
  lcd.setCursor(3,1);
  lcd.print(“Smart Shelf”);
  delay(2000);
}

void loop() {
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print(“units: “);
  lcd.setCursor(3,1);
  lcd.print(scale.get_units(5),0);
  Serial.print(scale.read_average(5));
  Serial.print(” - offset = “);
  Serial.print(scale.get_value(5));
  Serial.print(” / scale = “);
  Serial.println(scale.get_units(5),0);
  lcd.setCursor(8,1);
  lcd.print(” Gram”);
  delay(200);
}

void InterruptCommand()
{
  EEPROM.writeLong(0x00, scale.read_average(10));
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print(“Now Press”);
  lcd.setCursor(3,1);
  lcd.print(“RESET button”);
  while(1){};
}




Why on Earth is this `  while(1){};` inside an interrupt?
Why on Earth is there an interrupt at all in this sketch?

MMJZ:
I guess it is Floating input, but how I can solve it?!!

Your diagram look ok, so you should carefully check your connections with a multimeter. The voltage on d2 should be zero and change to 5V when the switch is pressed.

Yeh, it is
0v when unpressed and 4.6 when pressed

Strange. Can you borrow another Uno to see if the same thing happens?

This is on an UNO?

Then look at this line again...

attachInterrupt(0, InterruptCommand, HIGH);

And then read this from the reference page for attachInterrupt:

mode:
defines when the interrupt should be triggered. Four contstants are predefined as valid values:

LOW to trigger the interrupt whenever the pin is low,

CHANGE to trigger the interrupt whenever the pin changes value

RISING to trigger when the pin goes from low to high,

FALLING for when the pin goes from high to low.

The Due board allows also:
HIGH to trigger the interrupt whenever the pin is high.
(Arduino Due only)

Good spot Delta_G!

MMJZ, change your attachInterrupt call to use RISING instead of HIGH.

thank you all for your interest
thank you Delta_G, thank you PaulRB,

I try to change "HIGH" to "RISING" but the problem still happen, also I try to eliminate the interrupt (no interrupt) but also still happen, also I try the change on the 3 UNO boards I have it but no change (only on change, on one board the problem appear less than others).
know that the problem appear suddenly (not all the time) and when I put my finger on the PINs or IC the problem continue its cycle for a while and then stop again.

MMJZ:
I try to eliminate the interrupt (no interrupt) but also still happen

When you touch the ic and the problem happens even though you have set no interrupt, do you still see the "Now press reset button" on the lcd? This would indicate that the interrupt is still working.

PaulRB, after eliminating the interrupt (try the software without interrupt, so there is no InterruptCommand function anymore, so no "Now press reset button" message) and the problem still happen, so we can deduce that the problem was not related to the interrupt.
Also know that, when I attached the code in the first post I attached the minimum code (as I read in the Forum law), but in my last version I use 2 HX711 module as follows:

HX711 scale1(7, 6);
HX711 scale2(4, 3);

And in each time I read from one scale in the loop

Post. Your. Code.