Is that LCD won't work during attachInterrupt function (ISR) ? Please suggest.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27 // <<- Add your I2C LCD MODULE address here.
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
int a = 0; // JOB COUNTER STARTS WITH 0

// MACHINE INTERREPT PUSH BUTTON
// digital pin 2 IS INTERRUPT PUSH BUTTON
// digital pin 3 IS INTERRUPT FUNCTION BREAKING PUSH BUTTON

// MOTORS PIN CONFIGURATION

const int m6p1 = 4;
const int m6p2 = 5;
const int m6p3 = 6;
const int m6p4 = 7;
const int m6sdt1 = 10;

const int sl2 = 8;
const int dsl2tmd = 100;

// PAUSE FUNCTION i.e ISR, INTERRUPT FUNCTION
void PauseUno()
{
lcd.setCursor(0,0);
lcd.print(“M/C PAUSED !”);

while(digitalRead(3)==LOW)
{
// Don’t do Anything !!!
}
}

void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps*/

// PIN MODE
pinMode(13,INPUT);

pinMode(m6p1, OUTPUT);
pinMode(m6p2, OUTPUT);
pinMode(m6p3, OUTPUT);
pinMode(m6p4, OUTPUT);

pinMode(sl2, OUTPUT);

// 16X2 LCD I2C
lcd.begin (16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);

attachInterrupt(digitalPinToInterrupt(2),PauseUno,RISING);
} //END OF SETUP

void loop()
{
// JOB COUNTER DISPLAY
lcd.setCursor (0,0);
lcd.print("JOB COUNTER ");
lcd.setCursor(0,1);
lcd.print(a);

if (digitalRead(13) == HIGH)
{
digitalWrite(sl2, HIGH);

// JOB COUNTING
a++;
lcd.setCursor(0,1);
lcd.print(a);

delay(dsl2tmd);

unsigned long start = millis ();
while(digitalRead(A0)==0)
{
digitalWrite(m6p1, HIGH);
digitalWrite(m6p2, HIGH);
digitalWrite(m6p3, LOW);
digitalWrite(m6p4, LOW);
delay(2);

digitalWrite(m6p1, LOW);
digitalWrite(m6p2, HIGH);
digitalWrite(m6p3, HIGH);
digitalWrite(m6p4, LOW);
delay(2);

digitalWrite(m6p1, LOW);
digitalWrite(m6p2, LOW);
digitalWrite(m6p3, HIGH);
digitalWrite(m6p4, HIGH);
delay(2);

digitalWrite(m6p1, HIGH);
digitalWrite(m6p2, LOW);
digitalWrite(m6p3, LOW);
digitalWrite(m6p4, HIGH);
delay(2);

if (millis () - start >= 5000)
{
for(;:wink: // wooooooooo !!!
{
lcd.setCursor(0,0);
lcd.print(“M/C is STRUCKED!”);
delay(2700);
lcd.setCursor(0,0);
lcd.print(“plse POWER OFF &”);
delay(2700);
lcd.setCursor(0,0);
lcd.print("DO NECESSARY ");
delay(2700);
}
}

}

digitalWrite(sl2,LOW); // sl2 HOLDS JOB NUT

}

} // END OF LOOP

are you trying to print() to LCD DURING the ISR function?

your code isn't explicit.

Yes ,

"your code isn't explicit." I didn't get it !!!

(deleted)

:confused:

// PAUSE FUNCTION i.e ISR, INTERRUPT FUNCTION
void PauseUno()
{
  while(digitalRead(3)==LOW)
  {
   // Don't do Anything !!!
  }
}

Completely inappropriate use of an interrupt. What do you expect to happen while in the ISR?

SORRY IT IS AS FOLLOWS, AND STILL NOT WORKING, PLEASE SUGGEST HOW TO PRINT DURING ISR

// PAUSE FUNCTION i.e ISR, INTERRUPT FUNCTION void PauseUno() { lcd.setCursor(0,0); lcd.print("M/C PAUSED !"); // THIS IS NOT DISPLAYING

while(digitalRead(3)==LOW) { // Don't do Anything !!! } }

PLEASE SUGGEST HOW TO PRINT DURING ISR

Preferably don't.

And don't SHOUT.

You can't. Printing is interrupt driven and those interrupts are turned off while servicing yours.

Busy waiting in an ISR is a recipe for trouble. You probably need to restructure this code so the waiting doesn't happen in an ISR.

And don't cross-post. Duplicate deleted.

Thank you all for Quick reply, so lcd.print won't work during interrupt function. :relaxed:

(deleted)

RAHUL_AREKAR: Thank you all for Quick reply, so lcd.print won't work during interrupt function. :relaxed:

More specifically, interrupts don't work during an ISR (interrupt service routine) because they are disabled by default. You can manually re-enable interrupts inside an ISR, but I won't tell you how to do that since it's usually a stupid thing to do.

The Wire library (what Arduino uses for I2C) uses interrupts. Serial and millis() also use interrupts. None of those will work properly while you are in an ISR.

Do not use interrupts for push buttons. There is never a reason for it.