Arduino MKR1010 WiFi disconnecting

Hi everyone, everytime I try uploading something to my brand new MKR 1010 WiFi, It disconnect and reconnect from my pc while uploading and sometimes it works and others I had to hard reset the board by pressing the button 2 times. Any advice?

Thanks in advance

P.s. I tried Arduino IDE 1.8 and 2.0, but I had the same result

Your board supports native USB as far as I know. THE IDE first issues a software reset (opening and closing the serial port with a baudrate of 1200) to activate the boot loader and next does the actual upload. So the disconnect/connect is normal.

If you're a Windows user, you can observe the process in Windows device manager
It will show

  1. A normal port (e.g. COM4); it will probably also state "MKR 1010 WiFi".
  2. The upload port (e.g. COM7) after the reset; it will probably also state "MKR 1010 WiFi upload".
  3. The normal port (e.g. COM4) again once the upload is finished.

Does this happen with any sketch that you upload? E.g. upload blink (try it repeatedly); if no, you might have a bug in your sketch that causes your board not to recognise the reset command.

Part of the code that is uploaded is responsible for the board detection as well as the detection of the reset; a bug in your code can cause corruption of variables used by that specific part of the code.

Blink doesn't have any problem also uploaded repeatedly.
My code make the board disconnecting forever (I had to force reset pressing reset button 2 times quickly), but I can't recognise the error (I'm quite new and I've never used mkr board.
Can I share the code here for just a fast check by you?

You can; I'm however not familiar with your board and don't have one so can't test.

Post the error also.

that's normal, just wait it out. if you don't wait til it's finished and do something then that will cause you to have to hard reset it.

EDIT: I have one I can test with for you.

ecg.ino (4.2 KB)
Here you are the code.
It simply acquire some data from a module connected to pin A0 and the pin 10 and 11 are simply check pin to check if connection with module is fine

The strange part is that the code seems to not have any error while verifying, but the arduino get stuck immediately (I tried putting a Serial.println("1"); at the beginning of void loop and It doesn't even print it

Thanks everyone for the response

Most here(including me) will not download that because of the chance of malware.
Please follow the guide for posting code here: How to get the best out of this forum
Also please post the error message.

This might be a problem

  x0_index = (x0_index - 1) % 32;
  LPF_y0_index = (LPF_y0_index - 1) % 32;
  HPF_y0_index = (HPF_y0_index - 1) % 32;

What happens when those indices are 0; they will become negative after subtracting 1 and you will be writing outside the boundaries of your arrays.

I'm stupid enough :smiley:

//--------- RR ---------
float soglia = 100;           //soglia di rilevamento picco
bool passatoLH = 0;           //indica se ha superato la soglia
unsigned long prevPicco = 0;  //istante del precedente superamento soglia
unsigned long picco = 0;      //istante dell'attuale superamento soglia
unsigned long RR = 0;         //distanza picco-picco (RR)
//-----------------------------------------

//--------- Tempo di elaborazione ---------
unsigned long prevElabTime = 0;  //fine del ciclo precedente
unsigned long ElabTime = 0;      //fine del ciclo attuale
unsigned long T_camp = 100;
//-----------------------------------------

//--------- Derivazione ---------
unsigned long prevDataTime = 0;  //fine del ciclo precedente
unsigned long DataTime = 0;      //fine del ciclo attuale
//-----------------------------------------

//--------- Filtro a media mobile ---------
const int dimFinestraMediaMobile = 10;
float dati_da_mediare[dimFinestraMediaMobile];
int indice_dato_FirstIn = 0;
float total = 0;
//-----------------------------------------

//--------- Dati_letti ---------
float data = 0;
float prevData = 0;
//-----------------------------------------

//--------- Filtro passabanda ---------
float x[32];
float LPF_y[32];
float HPF_y[32];

int x0_index = 0;
int LPF_y0_index = 0;
int HPF_y0_index = 0;
//-----------------------------------------

float moving_average(float lastData)
{
  float average;
  total = total - dati_da_mediare[indice_dato_FirstIn];
  dati_da_mediare[indice_dato_FirstIn] = lastData;
  total = total + lastData;
  indice_dato_FirstIn += 1;

  if (indice_dato_FirstIn >= dimFinestraMediaMobile)
  {
    indice_dato_FirstIn = 0;
  }

  average = total / dimFinestraMediaMobile;
  return average;
}

float rit(char vettore, int pos)
{
  if (vettore == 'L')
  {
    return LPF_y[(LPF_y0_index + pos) % 32];
  }
  else if (vettore == 'H')
  {
    return LPF_y[(LPF_y0_index + pos) % 32];
  }
  return x[(x0_index + pos) % 32];
}

float passband_filter(float x0)
{  //coda: FIFO
  //Filtraggio FIR descritto dall'algoritmo di Pan-Tompkins

  x[x0_index] = x0;  //sto puntando all'elemento più vecchio da sostituire con quello più nuovo

  LPF_y[LPF_y0_index] = 2 * rit('L', 1) - rit('L', 2) + rit('x', 0) - 2 * rit('x', 6) + rit('x', 12);
  HPF_y[HPF_y0_index] = 32 * rit('L', 16) - (rit('H', 1) + rit('L', 0) - rit('L', 32));

  float data_PBF = HPF_y[HPF_y0_index];  //dato in uscita dalla cascata di LPF e HPF

  //Punto all'elemento più vecchio del vettore che andrò
  // a sostituire con quello nuovo al ciclo successivo.
  x0_index = (x0_index - 1) % 32;
  LPF_y0_index = (LPF_y0_index - 1) % 32;
  HPF_y0_index = (HPF_y0_index - 1) % 32;

  return data_PBF;
}

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(11, INPUT);  // Setup for leads off detection LO +
  pinMode(10, INPUT);  // Setup for leads off detection LO -
}

void loop()
{
  prevElabTime = ElabTime;
  if ((digitalRead(10) == 1) || (digitalRead(11) == 1))
  {  //controllo collegamenti
    Serial.println('!');
    DataTime = micros();  //in caso di errore inizializzo il contatore del timer all'istante corrente
  }
  else
  {                         //se i collegamenti sono OK
    data = analogRead(A0);  //leggo output del modulo sul pin A0

    //PASS-BAND filter
    data = passband_filter(data);

    prevDataTime = DataTime;
    DataTime = micros();
    unsigned long deltaDataTime = DataTime - prevDataTime;  ////durata di un ciclo

    float data_derivative = (data - prevData) / deltaDataTime;  //eseguo la derivata
    prevData = data;                                            //imposto il dato attuale come precedente per il prossimo calcolo

    float square_data_derivative = data_derivative * data_derivative;  //elevo al quadrato il valore derivato

    float final_data = moving_average(square_data_derivative);  //ricavo il dato finale
    if ((final_data >= soglia) && (passatoLH == 0))
    {
      passatoLH = 1;
      prevPicco = picco;
      picco = micros();
      RR = picco - prevPicco;
    }
    if ((final_data <= soglia) && (passatoLH == 1))
    {
      passatoLH = 0;
    }

    ElabTime = millis();  //millis() va in overflow (si azzera) ogni 50 giorni, mentre micros() ogni 70 minuti
    unsigned long deltaElab = ElabTime - prevElabTime;
    Serial.println(data);
    delay(100);  //delay(T_camp - deltaElab);
  }
}
1 Like

Well Thanks to @sterretje I've uploaded your code and it runs and prints the exclamation mark as it should. I'm not getting any error's.

I added more print statements and connected a button.
@sterretje nailed it. As soon as the button is pushed and the code enters the code section that @sterretje posted it runs it once then on the second time thru it locks up the IDE until the WIFI1010 is unplugged.

It's the same as my code

I changed the code so that it prevents writing outside the bounds of your array. When it tries to go below 0 it is redirected to the last array member instead. It functions well now but I don't know if that is the behavior you wanted.
Here is how I changed one of them:

  // change this:
  x0_index = (x0_index - 1) % 32;

  // to this:
  x0_index--;
  if (x0_index <0) x0_index = 31;
  x0_index % 32;

Are you using a pulldown resistors? If not your inputs are Floating. Which will cause them to change state randomly.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.