Hi everyone, hope my post fits in this section.
I will not post all my code cause is huge and wouldnt expect anyone to look into all of it.
Basically, I have had a project running for a long long time, but now I have added 2 push buttons and when pushing them, from time to time arduino freezes.
I have disabled pieces of code until found where the problem comes from, seems to be related to I2C (i use rtc clock and I2C lcd)
When I push the buttons intensively my code reports RTC time error (based on this check)
if ( (years > 2030) || (months > 12) || (days > 31) || (hours > 24) || (minutes >= 60) || (seconds > 60) )Also I have noticed that if I disable all LCD printing code, then I dont get Arduino freezes.
I think I2C goes crazy but maybe it has something to do with some calculations been done in the update lcd function (although i tried removing them and also happended)
example of lcd screen print..
double Percentage_Energy = (( (SumPower_1Month + ct1.SumPower) / Max_Month_wh) * 100.0);
// Time passed this month / number of hours in this month * percentage
double Percentage_M_Time = (( (((days-1) * 24) + hours + (minutes/60.0)) / (daysInMonths[months - 1] * 24)) * 100.0);
double Cost = (SumPower_1Month/1000.0) * PriceEnergyKwh;
lcd.print("** MONTHLY INFO **");
lcd.setCursor(0, 1); lcd.print("Power: "); printlcdspaces(ct1.Irms*230.0); lcd.print(ct1.Irms*230.0,0); lcd.print("W ");
printlcdspaces(Cost); lcd.print(Cost,1); lcd.print("E ");
lcd.print("Energy: "); lcd.print(Percentage_Energy,2); lcd.print(" % ");
lcd.print("M.Time: "); lcd.print(Percentage_M_Time,2); lcd.print(" % "); lcd.print(" ");
long hours; long minutes; long seconds; // I have declare them as long instead of int because I think that if RTC fails it can read bigger than int size numbers and try to save them in the int, and cause problem
long years; long months; long days;
double PriceEnergyKwh = 0.20;
double Max_Month_wh = 450000;
I know its a long post, but please any hint is very welcome.resume:
- Why would a push-button (internal pullup resistor used) caused a I2C misreading?
- Do my formulas have a problem with data types?
Thank you eveyone