Problema strano con Arduino nano

/* 25/02/2025
  -TEST Volmetro Alimentatore Volpix.powerLab New Relase                                        #Fatto
  - Attivate le funzioni  (funzionano solo i LED)                                               #Fatto
  - Aggiunti Lampeggi LED                                                                       #Fatto
  - Aggiunto funzione fronti di salita e disceda pulsanti ( pulsanti antirimbalzo)              #Fatto
26/02/2025
  -passaggio da stato PRECHARGE a PREOUT ok                                                     #Fatto
  -Led Usita con lampeggio                                                                      #Fatto
  -Attivato la funzione di spegnimento da ogni stato con POWERON                                #Fatto
  - splash ok                                                                                   #Fatto
- Attivata routine precharge sul ingresso A0 e modulo modificato per tensione fino a 50 Volt    #Fatto
- Aggiunto moduli INA226 con letture su oled                                                    #Fatto
- Aggiunto Pulsante POWERON con funzione lampeggio led                                          #Fatto
- aggiunti rele di powerOn e precharge                                                          #Fatto
- Aggiunto Lettura Potenziometro Set Amper                                                      #Fatto
- Aggiunto valore sogloa a finco degli Amper                                                    #Fatto
*/
// ---> Libraries
#include <Wire.h>
#include <U8g2lib.h>
#include <U8x8lib.h>
#include <MUIU8g2.h>
#include <Arduino.h>
#include <INA226_WE.h>


// ---> definizioni costanti & variabili
#define Pin_PRECHARGE A0  //musura tensione di precharge sui condensatori elettrolitici con partirore R1-20K R2-2.2K
#define pin_Set_AMP A3    //tensione di setup amperometro
#define SDA_OLED A4       //SDA I2C
#define SCL_OLED A5       //SCL I2C
#define I2C_ADDRESS 0x40  //assegna indirizzo I2C al modulo Tensione  & corrente Ina226
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_POWERON 2      // Pulsante Luminoso POWERON
#define Pin_LED_POWERON 6  // LED pulsante PoWERON **
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_POWER_OUT 3      //Pulsante tensione uscita
#define Pin_LedPOWER_OUT 10  //LED Pulsante tensione uscita
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_Double_Vac 4  //uscita relai scambio 12/24 Vac TR1
                          //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_BootAlim3A 5  //Avvia PLC collegato all'alimentatore 3A
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_ReleOn 7  //Rele alimentazione TR1
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_LedOUT_V 8  //LED Uscita colore Verde (spenta)
#define Pin_LedOUT_R 9  //LED Uscita colore Rosso (Accesa)
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_ReleCHARGE 11  //uscita comanda Rele Precharge
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define Pin_RelePOWEROUT 12  //uscita comanda Rele BOCCOLE di uscita
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ----> Variabili
int Stato = 0;                // con "0" Nessuna funzione viene eseguita
int BT, PVBT = 0;             // setta a 0 l'antiRIMBALZO del pulsante
int BBT, PPVBT = 0;           // setta a 0 l'antiRIMBALZO del pulsante
int VT, PPVT = 0;             // Setta stato rele 12 24 volt controllo "fronte salita e fronte discesa"
unsigned long T1 = 0;         // Timer usato con millis
bool PRECHARGE = false;       //definisce lo stato della precarica
float shuntVoltage_mV = 0.0;  // Tensione sulla resistenza SHUNT di INA226
float loadVoltage_V = 0.0;    //Tensione misurata all'ingresso di INA226
float busVoltage_V = 0.0;     // ??
float current_mA = 0.0;       // Corrente calcolata da INA226 (in mA)
float power_mW = 0.0;         //potenza calcolata da INA226 ( in  mW)
//float SetAmpere1 = (Bit_Value * VVV) /1000; //converto il BitValue in Volt utilizzando la Costante V_Value e trasformo in Amp
//int Bit_Value = analogRead(pin_Set_AMP); //Legge l'ingresso tensione soglia correne uscita
//float VVV = map(Bit_Value, 0, 1023, 0, 3); //converte l'ingresso da BinValue in mV

//Inializzazione e configurazione moduli I2c
U8G2_SH1106_128X64_NONAME_1_HW_I2C OLED(U8G2_R0, SCL_OLED, SDA_OLED, /*reset=*/U8X8_PIN_NONE);  //Nome e sigla diplay OLED con libreria U8g2
INA226_WE ina226 = INA226_WE(I2C_ADDRESS);                                                      //legge Ina226 all'indirizzo assegnato

// Logo Volpix Lab, 128x64px
const unsigned char Logo_Volpix_Arduino[] PROGMEM{
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0x7F,
  0x01,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xFE,
  0x3F,
  0x00,
  0x00,
  0xC0,
  0xFF,
  0x07,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x0C,
  0x60,
  0x00,
  0x00,
  0xE0,
  0xFF,
  0x47,
  0x08,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x08,
  0xC0,
  0x00,
  0x00,
  0xF0,
  0xFF,
  0x43,
  0x08,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x18,
  0x80,
  0x01,
  0x00,
  0xF0,
  0xFF,
  0x81,
  0x0C,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x30,
  0x00,
  0x03,
  0x00,
  0xF8,
  0xFF,
  0x80,
  0x04,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x60,
  0x00,
  0x02,
  0x00,
  0xFC,
  0xFF,
  0x80,
  0x04,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x40,
  0x00,
  0x06,
  0x00,
  0xFE,
  0x7F,
  0x00,
  0x03,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xC0,
  0x00,
  0x0C,
  0x00,
  0xFE,
  0x3F,
  0x00,
  0x03,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x80,
  0x01,
  0x18,
  0x00,
  0xFF,
  0x1F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x03,
  0x10,
  0x80,
  0xFF,
  0x1F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x02,
  0x30,
  0xC0,
  0xFF,
  0x0F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x06,
  0x60,
  0xC0,
  0xFF,
  0x07,
  0x80,
  0x07,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x0C,
  0xC0,
  0xE0,
  0xFF,
  0x03,
  0x80,
  0x0C,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0x80,
  0xF0,
  0xFF,
  0x03,
  0xC0,
  0x08,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x10,
  0x80,
  0xF9,
  0xFF,
  0x01,
  0x80,
  0x08,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x30,
  0x00,
  0xFB,
  0xFF,
  0x00,
  0x80,
  0x04,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x60,
  0x00,
  0xFE,
  0x7F,
  0x00,
  0x00,
  0x03,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0xC0,
  0x00,
  0xFE,
  0x7F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x80,
  0x00,
  0xFF,
  0x3F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x80,
  0x01,
  0xFF,
  0x1F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x00,
  0x83,
  0xFF,
  0x0F,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0xE0,
  0x00,
  0xFC,
  0x3F,
  0x40,
  0x01,
  0x00,
  0x00,
  0xC6,
  0xFF,
  0x0F,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0xF0,
  0x01,
  0xFC,
  0x7F,
  0x40,
  0x01,
  0x00,
  0x00,
  0xE4,
  0xFF,
  0x07,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0xF0,
  0x01,
  0x1C,
  0x70,
  0x40,
  0x01,
  0x00,
  0x00,
  0xFC,
  0xFF,
  0x03,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0xB0,
  0x03,
  0x1C,
  0xE0,
  0x40,
  0x01,
  0x00,
  0x00,
  0xF8,
  0xFF,
  0x01,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0x38,
  0x03,
  0x1C,
  0xE0,
  0x40,
  0x01,
  0x00,
  0x00,
  0xF8,
  0xFF,
  0x01,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0x38,
  0x03,
  0x1C,
  0xE0,
  0x40,
  0x01,
  0x00,
  0x00,
  0xFC,
  0xFF,
  0x03,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0x18,
  0x07,
  0x1C,
  0xE0,
  0x40,
  0x01,
  0x00,
  0x00,
  0xFC,
  0x7F,
  0x06,
  0x00,
  0x00,
  0x00,
  0x06,
  0x00,
  0x1C,
  0x06,
  0x1C,
  0x70,
  0x40,
  0x01,
  0x00,
  0x00,
  0xFE,
  0x3F,
  0x0C,
  0x00,
  0x00,
  0x00,
  0x06,
  0x00,
  0x0C,
  0x0E,
  0xFC,
  0x3F,
  0x40,
  0x01,
  0x00,
  0x00,
  0xFF,
  0x3F,
  0x08,
  0x00,
  0x00,
  0x00,
  0x06,
  0x00,
  0x0E,
  0x0E,
  0xFC,
  0x7F,
  0x40,
  0x01,
  0x00,
  0x80,
  0xFF,
  0x1F,
  0x18,
  0x00,
  0x00,
  0x02,
  0x06,
  0x00,
  0x0E,
  0x1C,
  0x1C,
  0xF0,
  0x40,
  0x01,
  0x00,
  0x80,
  0xFF,
  0x0F,
  0x30,
  0x00,
  0x80,
  0x05,
  0x06,
  0x00,
  0xFE,
  0x1F,
  0x1C,
  0xE0,
  0x40,
  0x01,
  0x00,
  0xC0,
  0xFF,
  0x07,
  0x60,
  0x00,
  0x80,
  0x0C,
  0x06,
  0x00,
  0xFF,
  0x1F,
  0x1C,
  0xC0,
  0x41,
  0x01,
  0x00,
  0xE0,
  0xFF,
  0x0F,
  0x40,
  0x00,
  0x80,
  0x08,
  0x06,
  0x00,
  0x07,
  0x38,
  0x1C,
  0xC0,
  0x41,
  0x01,
  0x00,
  0xF0,
  0xFF,
  0x0B,
  0xC0,
  0x00,
  0x80,
  0x04,
  0x06,
  0x00,
  0x03,
  0x38,
  0x1C,
  0xC0,
  0x41,
  0x01,
  0x00,
  0xF0,
  0xFF,
  0x19,
  0x80,
  0x01,
  0x80,
  0x07,
  0x06,
  0x80,
  0x03,
  0x70,
  0x1C,
  0xC0,
  0x41,
  0x01,
  0x00,
  0xF8,
  0xFF,
  0x30,
  0x00,
  0x03,
  0x80,
  0x00,
  0x06,
  0x80,
  0x01,
  0x70,
  0x1C,
  0xF0,
  0x40,
  0x01,
  0x00,
  0xFC,
  0xFF,
  0x60,
  0x00,
  0x03,
  0x80,
  0x00,
  0xFE,
  0xDF,
  0x01,
  0x70,
  0xFC,
  0x7F,
  0x40,
  0x01,
  0x00,
  0xFE,
  0x7F,
  0x40,
  0x00,
  0x06,
  0x00,
  0x00,
  0xFE,
  0xDF,
  0x01,
  0xE0,
  0xFC,
  0x3F,
  0x40,
  0x01,
  0x00,
  0xFE,
  0x3F,
  0xC0,
  0x00,
  0x0C,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0xFF,
  0x1F,
  0x80,
  0x01,
  0x18,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x80,
  0xFF,
  0x1F,
  0x00,
  0x03,
  0x18,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xC0,
  0xFF,
  0x0F,
  0x00,
  0x02,
  0x30,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xC0,
  0xFF,
  0x07,
  0x00,
  0x06,
  0x60,
  0x00,
  0x02,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xE0,
  0xFF,
  0x03,
  0x00,
  0x0C,
  0xC0,
  0x00,
  0x02,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xF0,
  0xFF,
  0x03,
  0x00,
  0x18,
  0xC0,
  0x00,
  0x02,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xF8,
  0xFF,
  0x01,
  0x00,
  0x10,
  0x80,
  0x01,
  0x02,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xF8,
  0xFF,
  0x00,
  0x00,
  0x30,
  0x00,
  0x03,
  0x02,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xFC,
  0x7F,
  0x00,
  0x00,
  0x60,
  0x00,
  0x07,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0xFE,
  0x3F,
  0x00,
  0x00,
  0xC0,
  0xFF,
  0x07,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0xC0,
  0x01,
  0x00,
  0x00,
  0xE0,
  0x1C,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0x80,
  0x00,
  0x00,
  0x00,
  0xC0,
  0x0D,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0x80,
  0xC0,
  0x0E,
  0xCC,
  0x80,
  0x0F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0xC0,
  0xC1,
  0x0F,
  0xCC,
  0x80,
  0x07,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0xC0,
  0xC1,
  0x0D,
  0xCC,
  0x80,
  0x07,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x18,
  0xC0,
  0xC1,
  0x0C,
  0xCC,
  0xC0,
  0x0F,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0xF8,
  0xC1,
  0xC1,
  0x0C,
  0xFC,
  0xC0,
  0x0C,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0xF8,
  0xC1,
  0xC1,
  0x0C,
  0xFC,
  0xE0,
  0x1C,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0x01,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x00,
  0x40,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0xFF,
  0x7F,
};
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void setup() {  //Ciclo SETUP viene eseguito solo all'avvio
  // Definizioni dei PIN IN & OUT
  pinMode(Pin_POWERON, INPUT_PULLUP);    //Set Pin Interruttore POWER ON come Ingresso
  pinMode(Pin_LED_POWERON, OUTPUT);      //Set Pin Led Interruttore POWER ON come uscita
  pinMode(Pin_LedPOWER_OUT, OUTPUT);     //Set Pin Led Pulsante POWEROUT come uscita
  digitalWrite(Pin_LedPOWER_OUT, LOW);   //Set stato Led Spento
  pinMode(Pin_LedOUT_R, OUTPUT);         //Set Pin Led Rosso come uscita
  digitalWrite(Pin_LedOUT_R, HIGH);      //Set stato Led Spento
  pinMode(Pin_LedOUT_V, OUTPUT);         //Set Pin Led Verde come uscita
  digitalWrite(Pin_LedOUT_V, HIGH);      //Set stato Led Spento
  pinMode(Pin_POWER_OUT, INPUT_PULLUP);  ////Set Pin Interruttore POWER ON come Ingresso
  pinMode(Pin_ReleOn, OUTPUT);           //Pin uscita Arduino collegata al rele ReleOn
  digitalWrite(Pin_ReleOn, HIGH);        //forzo il rele spento
  pinMode(Pin_ReleCHARGE, OUTPUT);       //Pin uscita Arduino collegata al rele PreCharge
  digitalWrite(Pin_ReleCHARGE, HIGH);    //forzo il rele spento
  pinMode(Pin_BootAlim3A, OUTPUT);       // Pin uscita collegato al rele avvio alimentatore 3A
  digitalWrite(Pin_BootAlim3A, HIGH);    //setto spento il rele
  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  Serial.begin(9600);  //configuta velocita seriale per monitoraggio
  Wire.begin();
  if (!ina226.init()) {
    Serial.println("Failed to init INA226. Check your wiring.");
    while (1) {}
  }
  OLED.begin();  //Inizializza il display
  do {
    OLED.drawXBMP(0, 0, 127, 64, Logo_Volpix_Arduino);  //Carica nel Display l'immagine Volpix
  } while (OLED.nextPage());                            //scrive nel display il buffer
}  //End SETUP

//*****************************************************************************************
//*****************************************************************************************
//*****************************************************************************************
//*****************************************************************************************
void loop() {
  //Fine routine 12/24v
  //------------------------------------------------------------------------------------------
  switch (Stato) {
    case 0:
      OFF_0();
      break;
      //------------------------------------------------------------------------------------------
    case 1:
      STANDBY_1();
      break;
      //------------------------------------------------------------------------------------------
    case 2:
      PRECHARGE_2();
      break;
      //------------------------------------------------------------------------------------------
    case 3:
      PREOUT_3();
      break;
      //------------------------------------------------------------------------------------------
    case 4:
      NORMAL_WORK_4();
      break;
  }  //End switch
     //------------------------------------------------------------------------------------------
     // routine 12/24 volt
  if (loadVoltage_V > 12) {
    digitalWrite(Pin_BootAlim3A, LOW);
    delay(200);
  }

  if (loadVoltage_V < 10) {
    digitalWrite(Pin_BootAlim3A, HIGH);
    delay(200);
  }
  BT = digitalRead(Pin_POWERON);
  if (!BT && PVBT) {  //se il pulsante poweon e Acceso
    Stato = 2;
  }  //End DigitalREAD POWERON
  PVBT = BT;
}  //End Void Loop
//*****************************************************************************************
// ----> Routine

void OFF_0() {

  if ((millis() - T1) >= 1000) {
    digitalWrite(Pin_LED_POWERON, !digitalRead(Pin_LED_POWERON));
    T1 = millis();
  }  //EndIF millis
}  //End OFF_0
//*******************************************************************************************

void STANDBY_1() {
  Serial.println("Standby");
  if ((millis() - T1) >= 1000) {
    digitalWrite(Pin_LED_POWERON, !digitalRead(Pin_LED_POWERON));
    T1 = millis();
  }                                     //EndIF millis
  digitalWrite(Pin_LedPOWER_OUT, LOW);  //Spengo Pulsante POWEROUT (Rosso) Fisso
  digitalWrite(Pin_LedOUT_V, HIGH);     //Spengo LED uscita (Verde)
  digitalWrite(Pin_LedOUT_R, HIGH);     //Spengo LED uscita (Rosso)
  digitalWrite(Pin_ReleOn, HIGH);       //Spengo Rele alimenazione TR1
  OLED.firstPage();
  do {
    OLED.setFont(u8g2_font_ncenB10_tr);
    OLED.drawStr(0, 20, "StandBy");
    OLED.drawStr(0, 40, "Trafo principale");
    OLED.drawStr(0, 60, "Spento");
  } while (OLED.nextPage());
}  //End STANDBY_1
//*******************************************************************************************

void PRECHARGE_2() {
  Serial.println("Precharge");
  digitalWrite(Pin_ReleOn, LOW);              //Accendo Rele alimenazione TR1
  int v1 = analogRead(Pin_PRECHARGE);         //Legge l'ingresso tensione
  int tensione1 = map(v1, 0, 1023, 0, 5000);  //converte l'ingresso da BinValue in mV
  OLED.firstPage();
  do {
    OLED.setFont(u8g2_font_ncenB10_tr);
    OLED.setCursor(0, 14);      // imposta la posizione del cursore
    OLED.print("PreCharging");  // scrive il valore numerico
    OLED.setCursor(40, 30);     // imposta la posizione del cursore
    OLED.print(tensione1);      // scrive il valore numerico
    OLED.setCursor(0, 42);
    OLED.print("Tensione");
    OLED.setCursor(0, 60);
    OLED.print("sulle capacita'");
  } while (OLED.nextPage());
  if ((millis() - T1) >= 100) {
    digitalWrite(Pin_LED_POWERON, !digitalRead(Pin_LED_POWERON));
    T1 = millis();
  }  //EndIF millis
  if (tensione1 > 1300) {
    digitalWrite(Pin_ReleCHARGE, LOW);
    Stato = 3;
  }                                        //End IF TEnsione1
  if (digitalRead(Pin_POWERON) == HIGH) {  // se il pulsante poweon e spento
    Stato = 1;                             // Salto a STANDBY
  }                                        //End Digitalread Pin_POWERON
}  //End PRECHARGE_1
//*******************************************************************************************

void PREOUT_3() {
  Serial.println("Preout");
  digitalWrite(Pin_LedOUT_R, HIGH);  //Spengo LED uscita (Verde) //
  if ((millis() - T1) >= 1000) {
    digitalWrite(Pin_LedOUT_V, !digitalRead(Pin_LedOUT_V));  //Lampeggio Led Verde
    T1 = millis();
  }                                      //EndIF millis
  digitalWrite(Pin_LED_POWERON, HIGH);   //Accendo il LED Interruttore POWERON fisso
  digitalWrite(Pin_LedPOWER_OUT, HIGH);  //Accendo Pulsante POWEROUT (Rosso) Fisso
  BBT = digitalRead(Pin_POWER_OUT);
  //Serial.println("leggo BT"); Serial.println(BT);
  if (!BBT && PPVBT) {  //se il pulsante poweon e Acceso
    //Serial.println("leggo BT"); Serial.println(BT);
    Stato = 4;
  }  //End Digital POWER_OUT
  PPVBT = BBT;
  //-----------------------------------------------------------------------------------------------------
  int v1 = analogRead(pin_Set_AMP);             //Legge l'ingresso tensione
  int SetAmpere1 = map(v1, 0, 1023, 0, 10050);  //converte l'ingresso da BinValue in mV
  float PotAMP = SetAmpere1 * 0.001;
  //------------------------------------------------------------------------------------------------------


  shuntVoltage_mV = ina226.getShuntVoltage_mV();
  busVoltage_V = ina226.getBusVoltage_V();
  current_mA = ina226.getCurrent_mA();
  power_mW = ina226.getBusPower();
  loadVoltage_V = busVoltage_V + (shuntVoltage_mV / 1000);

  //checkForI2cErrors();
  OLED.firstPage();
  do {
    OLED.setFont(u8g2_font_ncenB10_tr);
    OLED.drawStr(10, 11, "-- PrePower --");
    OLED.drawStr(0, 30, "Volt. ");
    OLED.drawStr(0, 50, "Set_Amp. ");
    OLED.setCursor(80, 30);
    OLED.print(loadVoltage_V);  // scrive il valore numerico);
    OLED.setCursor(80, 50);
    OLED.print(PotAMP);
    //OLED.print(Set_Amp1,3);
    //Serial.println(Set_Amp1);


  } while (OLED.nextPage());

  //} //end working True
  if (digitalRead(Pin_POWERON) == HIGH) {  // se il pulsante poweon e spento
    Stato = 1;                             // Salto a STANDBY
  }                                        //End Digitalread Pin_POWERON
}  //end Preout3

//*******************************************************************************************

void NORMAL_WORK_4() {
  Serial.println("Normal Working");
  digitalWrite(Pin_LedOUT_V, HIGH);  //Spengo LED uscita (Verde) //
  if ((millis() - T1) >= 100) {
    digitalWrite(Pin_LedOUT_R, !digitalRead(Pin_LedOUT_R));  //Lampeggio Led Verde
    T1 = millis();
  }  //EndIF millis
  BBT = 0;
  BBT = digitalRead(Pin_POWER_OUT);
  //Serial.println("leggo BT"); Serial.println(BT);
  if (!BBT && PPVBT) {  //se il pulsante poweon e Acceso
    //Serial.println("leggo BT"); Serial.println(BT);
    digitalWrite(Pin_LedOUT_R, HIGH);  //Spengo LED uscita (Verde) //
    Stato = 3;
  }  //End Digital POWER_OUT

  //------------------------------------------------------------------------------------

  PPVBT = BBT;
  //------------------------------------------------------------------------------------
  //-----------------------------------------------------------------------------------------------------
  int v1 = analogRead(pin_Set_AMP);             //Legge l'ingresso tensione
  int SetAmpere1 = map(v1, 0, 1023, 0, 10050);  //converte l'ingresso da BinValue in mV
  float PotAMP = SetAmpere1 * 0.001;

  float shuntVoltage_mV = 0.0;  // Tensione sulla resistenza SHUNT di INA226
  float loadVoltage_V = 0.0;    //Tensione misurata all'ingresso di INA226
  float busVoltage_V = 0.0;     // ??
  float current_mA = 0.0;       // Corrente calcolata da INA226 (in mA)
  float power_mW = 0.0;         //potenza calcolata da INA226 ( in  mW)
                                //------------------------------------------------------------------------------------------------------
  shuntVoltage_mV = ina226.getShuntVoltage_mV();
  busVoltage_V = ina226.getBusVoltage_V();
  current_mA = ina226.getCurrent_mA();
  power_mW = ina226.getBusPower();
  loadVoltage_V = busVoltage_V + (shuntVoltage_mV / 1000);
  //checkForI2cErrors();
  OLED.firstPage();
  do {

    OLED.setFont(u8g2_font_ncenB10_tr);
    OLED.drawStr(10, 11, "--  Operate  --");
    // OLED.setFont(u8g2_font_ncenB14_tr);
    OLED.drawStr(0, 30, "Volt ");
    OLED.drawStr(0, 46, "Amp ");
    OLED.drawStr(0, 64, "Watt ");
    //OLED.drawStr(0,64, "OverLoad ");

    OLED.setCursor(48, 30);
    OLED.print(loadVoltage_V);

    OLED.setCursor(48, 46);
    OLED.print(current_mA / 100);
    OLED.setCursor(83, 46);
    OLED.setFont(u8g2_font_7x13_mr);
    OLED.print("(");
    OLED.print(PotAMP);
    OLED.setFont(u8g2_font_ncenB10_tr);
    OLED.print(")");

    OLED.setCursor(48, 64);
    OLED.print(power_mW / 100);


  } while (OLED.nextPage());

  //-------------------------------------------------------------------------------------
  if (digitalRead(Pin_POWERON) == HIGH) {  // se il pulsante poweon e spento
    Stato = 1;                             // Salto a STANDBY
  }                                        //End Digitalread Pin_POWERON

}  //NORMAL_WORK_4

Buongiorno a tutti impegni di lavoro mi hanno tenuto lontano dai miei hobby, ma c'era ancora una faccenda che mi premeva risolvere.

Quel famoso blocco dello scheth che mi bloccava Arduino…all'inizio pensavo potesse dipendere dall' alimentazione ( poca corrente fornita dall' alimentatore switch, oppure da qualche Spike generato dai relè, nonostante tutti avessero il diodo in antiparallelo.

Dopo aver escluso tutte le cause probabili, mi restava il bus I2c che collega un piccolo display OLED e un modulo INA226, il collegamento era fatto con 4 conduttori intrecciati..di 25 centimetri, dopo averli sostituiti con cavetto schermato opportunamente collegato a massa il problema è scomparso.