Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7199

Arduino nano crash when use Lcd I2C in Watchdog interrupt timer

$
0
0

I want to use Arduino Nano watchdog as a timer and display time in a I2C LCD, but program crash when use LCD function in watchdog timer. I can't use LCD function in loop because the code in it takes a long time more than a second .
I tried the following code in Arduino IDE.

#include <WatchDog.h>#include <LCD_I2C.h>LCD_I2C lcd(0x27, 16, 2);     // LCD pin ** A4=SDA ** A5=SCLbyte hr;                    // hourbyte mn;                    // minutebyte sc;                    // secoundvoid setup() {  lcd.begin();  lcd.backlight();  Serial.begin(57600);  WatchDog::init(interruptTimer, OVF_1000MS);}void loop() {// It takes a long time more than a second}void interruptTimer() { // watchdog timer interrupt service routine  lcdClock();  clockUpdate();}void lcdClock() {  char clock[9];  sprintf(clock, "%02i:%02i:%02i ", hr, mn, sc);  Serial.println(clock);  lcd.setCursor(0, 0); // arduino crash in this line and next line  lcd.print(clock); }void clockUpdate() {  sc++;  if (sc % 10 == 0) sc++;  if (sc > 59) {    sc = 0;    mn++;  }  if (mn > 59) {    mn = 0;    hr++;  }  if (hr > 23) hr = 0;}

And when comment lcd.setCursor(0, 0) and lcd.print(clock) The Serial.println(clock) works correctly.

Does I2C and Watchdog functions are incompatible?And how I resolve my problem without using Timer modules. thanks a lot.


Viewing all articles
Browse latest Browse all 7199

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>