Yikes, I don't have time to trawl through all that, but here is an example
stash.println((millis()/1000)/60);
stash.print("Z,"); // Potência aparente
stash.println((millis()/1000)/60);
stash.print("ZA,"); // Fator de potência
stash.println((millis()/1000)/60);
stash.print("ZB,"); // Tensão RMS
stash.println((millis()/1000)/60);
stash.print("ZC,"); // Corrente RMS
stash.println((millis()/1000)/60);
stash.print("ZD,"); // Frequência
stash.println((millis()/1000)/60);
stash.print("ZE,"); // KWh
stash.println((millis()/1000)/60);
Why call millis() and do that maths every time, do it once then print a variable.
setup() has a gazillion pinModes() in a row, use an array of pin numbers and a loop.
checktpa() has a humungous amount of duplicate code, maybe that could be reduced. For example
if ((segunda==t.dow) && (hora==t.hour) && (minuto==t.min) && (tpa == 0))
{
tpa=1;
if ((4294967295ul - tempo) < millis())
{
marcadoriniciotpa= millis() - (tempo*2);
}
else
{
marcadoriniciotpa= millis();
}
}
if ((terca==t.dow) && (hora==t.hour) && (minuto==t.min) && (tpa == 0))
{
tpa=1;
if ((4294967295ul - tempo) < millis())
{
marcadoriniciotpa= millis() - (tempo*2);
}
else
{
marcadoriniciotpa= millis();
}
}
// and another 7 times I think
The only difference between these is the variables being compared I think, at least put the body of the if() block in a function, but why do you do the same thing with different tests?
I'm sure this code could be substantially reduced, but unless you have finished it it will just grow too big again so a more capable platform may still be the answer.
Rob