Problems in WiFi connection with Nano RP2040

Hello, I really can not understand why I lost wifi connection in Arduino IoT Cloud with the code below....
I am using the Arduino Nano RP2040.
While the code is running the serial port is unavailable and I can not connect via wifi to the cloud.

If instead of two cycles for, I only had one, the code runs without problems
Some suggestions?

Thank you

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/7a957fe1-7dc6-4d28-b027-de46f5b5c8f7 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  String msg;
  float tensaoA0;
  bool presenca;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
int green_light = 10;
float aRef=3.3;
float media=0;
float media1;
#define AMOSTRAS 20
unsigned long time1;


void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  //delay(1500); 
  pinMode(green_light, OUTPUT);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

float lePorta(uint8_t portaAnalogica) {
  float total=0;  
  for (int i=0; i<AMOSTRAS; i++) {
    
    time1=millis();
    total += analogRead(portaAnalogica);
    while (millis() < time1+5){
      
    }
  }
  return total / (float)AMOSTRAS;
}


void mostraTensoes() {
  //Serial.print("Tensao em A0: ");
  Serial.println(tensaoA0,3);
}  

void loop() {
  ArduinoCloud.update();
  // Your code here 
  float vetor;
  media=0;
  float soma=0;
  
  for (int i=0;i<10;i++){
    tensaoA0 = (lePorta(A0) * aRef) / 1023.0;
    vetor=tensaoA0;
    soma=soma+vetor;
    mostraTensoes();
    delay(500);
    
    
  }
  media=soma/10;
  
  Serial.print("Media: ");
  Serial.println(media,3);
  


  float vetor1;
  media1=0;
  float soma1=0;

    for (int i=0;i<10;i++){
    //tensaoA0 = (lePorta(A0) * aRef) / 1023.0;
    vetor1=tensaoA0;
    soma1=soma1+vetor1;
    mostraTensoes();
    delay(500);
  }

  media1=soma1/10;
  
 
  
  
  
  
  
}

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