Thank you Mr. Paul.
I read that from LCD print within Interrupt Function - Programming Questions - Arduino Forum in #8 maybe I miss understand him.
Let me discuss my problem from beginning:
When I test interrupt code for the sensor I works perfectly and when I test the LCD screen (which works on I2C) alone it works perfectly too
BUT when I combine both codes they don't work. I just receive "Tu" in serial monitor which is the first two letters in the first Serial.print in the code.
The LCD code Which work alone perfectly :
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
void setup(){
Serial.begin(9600);
lcd.begin (16,2);
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop(){
Serial.println();
lcd.setCursor (0,0);
lcd.print("Speed: 1800");
lcd.setCursor (6,1);
lcd.print("RPM");
delay (1000);
}
The sensor code Which work alone perfectly :
//inductive
int metalPin = A5;
volatile int count; //measuring the rising edges of the signal
int Calc;
void setup(){
Serial.begin(9600);
//sensor
pinMode(2, INPUT);
attachInterrupt(0, rpm, RISING);
}
void loop(){
Serial.println();
inductive();
Serial.println();
delay (1000);
}
void inductive(){
count = 0; //reset the counter
sei(); //Enables interrupts
delay (15000);
cli(); //Disable interrupts
Calc = (count *4); //to be(RPM)
Serial.print ("Turbine: ");
Serial.print (Calc);
Serial.println (" RPM");
}
void rpm(){ //This is the function that the interupt calls
count++;
}
The combined code which doesn't work:
//LCD
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
//inductive
int metalPin = A5;
volatile int count; //measuring the rising edges of the signal
int Calc;
void setup(){
Serial.begin(9600);
//sensor
pinMode(2, INPUT);
attachInterrupt(0, rpm, RISING);
//LCD
lcd.begin (16,2);
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop(){
inductive();
lcd.setCursor (0,0);
lcd.print("Speed: ");
lcd.print(Calc);
lcd.setCursor (6,1);
lcd.print("RPM");
delay (1000);
}
void inductive(){
count = 0; //reset the counter
sei(); //Enables interrupts
delay (15000);
cli(); //Disable interrupts
Calc = (count *4); //to be(RPM)
Serial.print ("Turbine: ");
Serial.print (Calc);
Serial.println (" RPM");
}
void rpm(){ //This is the function that the interupt calls
count++;
}
Thanks