Hi Avery one.
i using i2c lcd for my project.also it have a SIM900 module my problem is when running sim900 code in loop the lcd print struct.then i need run my lcd code in timer interrupt.How to do it any one pleas help me.
Delta_G:
Post your code. It isn't very likely that you'd need a timer interrupt to drive a display. It is far more likely that your other code needs to be optimized so that it can run with the LCD code.Doing I2C comms in an interrupt service routine would be very sketchy at best and might not work at all. IIRC the I2C is interrupt driven itself and during your ISR those interrupts would be turned off. So this may well end up dead-locking the code.
this is my code
void loop() {
temp1 = Now_temp;
hum = Now_hum;
on_time=Now_on;
off_time=Now_off;
Stemp1=Now_Stemp;
if(receiveMode==true && sendMode==false && sendserver==false && start_up_off ==true){
// Serial.println("Starting...");
power_on();
delay(2000);
// Serial.println("Setting SMS mode...");
sendATcommand("AT+CMGF=1", "OK", 1000); // sets the SMS mode to text
sendATcommand("AT+CPMS=\"SM\",\"SM\",\"SM\"", "OK", 1000); // selects the memory
answer = sendATcommand("AT+CMGR=1", "+CMGR:", 2000); // reads the first SMS
delay(3000);
receiveMode=false;
sendserver=false;
// lcd.clear();
}
if(receiveMode==false && sendMode==true && sendserver==false && start_up_off ==true){
// Serial.println("Starting...");
power_on();
delay(2000);
// Serial.println("Connecting to the network...");
while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
// Serial.print("Setting SMS mode...");
sendATcommand("AT+CMGF=1", "OK", 1000); // sets the SMS mode to text
// Serial.println("Sending SMS");
sprintf(aux_string,"AT+CMGS=\"%s\"", phone_number);
answer = sendATcommand(aux_string, ">", 2000); // send the SMS number
if (answer == 1)
{
Serial.println("OK");
Serial.write(0x1A);
}
delay(3000);
sendMode=false;
receiveMode=true;
}
if(receiveMode==false && sendMode==false && sendserver==true && start_up_off ==true){
save_value(String (temp1),String (hum),String (on_time),String (off_time),String (Stemp1));
}
SetV = num1.toInt();
St();
setT();
//SetT = ST;
if(sendserver1==true){
if(minute==5 || minute1==5){
sendserver=true;
sendserver1=false;
}
}
if(set_hour==0){
if(second1==60){
minute++;
second1=0;
if(minute==60){
minute=0;
sendserver1=true;
}
}
}
else{
if(second1==60){
minute1++;
second1=0;
if(minute1==60){
hour++;
minute1=0;
sendserver1=true;
if(hour==set_hour){
sendAll();
hour=0;
}
}
}
}
if (millis() - timeStamp > 10000 && index==0)
{
float Humidity1 = sht1x.readHumidity();
Humidity = Humidity1;
timeStamp = millis();
}
if (millis() - timeStamp > 3000 && index==1)
{
float Humidity1 = sht1x.readHumidity();
Humidity = Humidity1;
timeStamp = millis();
}
float Temp = getTemp() * 1.8 + 32; // temp in 'F
char key = keypad.getKey();
switch (index) {
case 0:
if(key=='0' || key=='*' || key=='#'){
sys = sys + key;
int keylenth = sys.length();
if(keylenth>=8){
sys="";
lcd.clear();
}
}
analogWrite(fanPin,0);
start_up_off = 1;
lcd.setCursor(3, 0);
lcd.print("SYSTEM STOPED");
lcd.setCursor(0, 1);
lcd.print("T:");
lcd.print(Temp);
lcd.print(" ");
lcd.setCursor(7, 1);
lcd.print((char)223);
lcd.print("F");
lcd.setCursor(11, 1);
lcd.print(" ST:");
lcd.print(SetT);
lcd.print((char)223);
lcd.print("F");
lcd.setCursor(0, 3);
lcd.print("HUM:");
lcd.print(Humidity);
lcd.print("%");
lcd.setCursor(12, 3);
lcd.print(sys);
if (digitalRead(startPin) == LOW && !integ_part) {
delay(50);
while (digitalRead(startPin) == LOW && !integ_part);
delay(1000);
lcd.clear();
sec_pointer = 0;
index = 1;
}
if (sys == "*#0000#") {
lcd.clear();
index = 9;
sys = "";
Ok=false;
num2="";
num1="";
print1=true;
}
break;
case 1:
lcd.setCursor(3, 0);
lcd.print("SYSTEM RUNNING");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("T:");
lcd.print(Temp);
lcd.print((char)223);
lcd.print("F");
lcd.setCursor(12, 1);
lcd.print("ST:");
lcd.print(SetT);
lcd.print((char)223);
lcd.print("F");
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print("HUM:");
lcd.print(Humidity);
lcd.print("%");
if(run==true && !stopp){
lcd.setCursor(13, 3);
lcd.print(" ");
lcd.setCursor(14, 3);
lcd.print("Run ");
lcd.print(sec_pointer);
}
if(!run && stopp==true){
lcd.setCursor(13, 3);
lcd.print(" ");
lcd.setCursor(13, 3);
lcd.print("Stop ");
lcd.print(sec_pointer);
}
if(!run && !stopp){
lcd.setCursor(13, 3);
lcd.print(" ");
}
if(sec_pointer==0){
lcd.setCursor(13, 3);
lcd.print(" ");
}
if (digitalRead(startPin) == LOW) {
delay(50);
while (digitalRead(startPin) == LOW);
delay(1000);
lcd.clear();
index = 0;
}
fanrun();
sys = "";
break;
[\code]
No, you don't need a timer interrupt. What are you really trying to achieve? Don't give us the solution, what is the actual problem?
It looks like that code already uses millis() to decide when to measure humidity, with the time period dependent on whether it's in state 0 or 1 (the index
variable.)