UNO R4 WiFi unnable to connect to WiFi

when I was coding a school project suddenly my R4 stopped being able to send or receive serial data, and the Tx/Rx LEDs were not turning on. I had to re-flash the firmware n the ESP32 as it wasn't even recognized by the IDE as an R4 WiFi. Now, my R4 has stopped working again, but this time partially. I can write a simple program and it works correctly but as soon as I try to connect it to the Arduino Cloud it crashes showing me this message:

Firmware name: "C:\Users\Miguel\AppData\Local\Temp\arduino\sketches\A972D38690D3AA1094BE11FD845DC34E/SketchCIencias.ino", compiled on: Jun  6 2024
Fault on interrupt or bare metal(no OS) environment
===== Thread stack information =====
  addr: 20007eb8    data: 200015fc
  addr: 20007ebc    data: 00006269
  addr: 20007ec0    data: 200009d8
  addr: 20007ec4    data: 000043a7
  addr: 20007ec8    data: 5adfa79d
  addr: 20007ecc    data: 09fd35ef
  addr: 20007ed0    data: 00000000
  addr: 20007ed4    data: 000151f1
  addr: 20007ed8    data: 0001f950
  addr: 20007edc    data: 40046f00
  addr: 20007ee0    data: 00000000
  addr: 20007ee4    data: 0001522f
  addr: 20007ee8    data: 0001f950
  addr: 20007eec    data: 0000db9f
  addr: 20007ef0    data: 0001f950
  addr: 20007ef4    data: 00012347
  addr: 20007ef8    data: 0001233d
  addr: 20007efc    data: 00002599
====================================
=================== Registers information ====================
  R0 : 00000000  R1 : 00000018  R2 : 200031a8  R3 : 00000000
  R12: 00000001  LR : 0000c7d7  PC : 00000000  PSR: 400f0000
==============================================================
Usage fault is caused by attempts to switch to an invalid state (e.g., ARM)
Show more call stack info by run: addr2line -e "C:\Users\Miguel\AppData\Local\Temp\arduino\sketches\A972D38690D3AA1094BE11FD845DC34E/SketchCIencias.ino".elf -a -f 00000000 0000c7d6 00006268 000043a6 000151f0 0001522e 0000db9e 00012346 0001233c

I have tried reflashing the firmware, I erased the firmware from the ESP32 (since its showing me that the firmware name is a random sketch name that I don't even have in my pc anymore) and flashed it again with esptool, but nothing works

As far as I know I'm running a normal sketch since I just use the Arduino IDE (and the cloud editor). I had to reflash the firmware using Powershell a couple of times, as I said, since the board wasn't getting recognized. I can provide the sketch I'm currently working on (not finished) but I don't think it's the cause of the problem, since any other program that does not connect to the internet works as expected

#include <LCD_I2C.h>
#include <ADebouncer.h>
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/86fc0a30-f7d8-4a51-b2fc-f6c8f1024115 

  Arduino IoT Cloud Variables description

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

  float waterFlow;
  bool waterLevel;
  CloudTime lastResuply;

  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 <Wire.h>
//#include <RTC.h>
//#include <NTPClient.h>
#include "thingProperties.h"



LCD_I2C lcd(0x27, 16, 2);
ADebouncer resuply, dispensar;

// WiFiUDP Udp;  // A UDP instance to let us send and receive packets over UDP
// NTPClient timeClient(Udp);

// /*Variables y Constantes✨ */
float volDispensado;
float saldoAnterior = 0;
float saldoActual = 0;
#define COSTO_AGUA 1.50
bool DISPENSAR;
bool RESUPLY;
#define BOMBA 8
#define VALVULA 7
// unsigned long unixTime;

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

  // Defined in thingProperties.h
 // initProperties();

  // Connect to Arduino IoT Cloud
  //ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  lastResuply = ArduinoCloud.getLocalTime();  
  lcd.begin();
  lcd.backlight();
  resuply.mode(INSTANT, 250, HIGH);
  dispensar.mode(INSTANT, 250, HIGH);
  pinMode(12, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
}

void loop() {
  //ArduinoCloud.update();

  if (Serial.available() > 0) {

    saldoActual = Serial.parseFloat();
    
    
    
  }

  // RESUPLY = resuply.debounce(digitalRead(11));
  // if (RESUPLY == LOW) {
  //   lastResuply = ArduinoCloud.getLocalTime();
  //   Serial.println("Time updated");
  // }
  
  if (saldoActual != saldoAnterior) {
    saldoAnterior = saldoActual;
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.clear();
    lcd.setCursor(5, 0);
    lcd.print("Saldo"),
      lcd.setCursor(5, 1);
    lcd.print(saldoActual);
    Serial.print("Su saldo es: ");
    Serial.println(saldoActual);
  }

  DISPENSAR = dispensar.debounce(digitalRead(12));

  if (DISPENSAR == LOW && saldoActual != 0) {
  
    float volRequerido = saldoActual/COSTO_AGUA; 
      Serial.println(volRequerido);   
    do {
      hydraulicsON();
      
    } while (volDispensado < volRequerido);
  }

}

void hydraulicsON() {
  Serial.println("Dispensing");
  digitalWrite(BOMBA, HIGH);
  digitalWrite(VALVULA, HIGH);
  volDispensado = analogRead(A1);
}



When I try running the sketch it shows the usual "connecting to WiFi" serial text from the arduino cloud code, but then says that it cannot recognize the device id and crashes showing me the message I put here first. Currently I don't have anything plugged to the board (I would normally have an I2C LCD screen, two push buttons to digital pins 11 and 12 (as pullup with the internal resistor), and two outputs from pin 7 and 8 to some optocouplers, connected to some power MOSFETs (They do not share a ground connection with the Arduino, that's why I used the optocouplers)

Hey sorry for the late reply. And yeah the code pretty much works as expected when I don't connect it to the Cloud. I built the program using the default Cloud sketch from the Arduino Cloud as a baseline. The other libraries from what I'm aware don't rely on a specific architecture to work so I don't really know what could be happening. I have also tried uploading a blank Cloud sketch that just connects to the cloud and links some variables to a cloud Thing.

I am having the same issue. Any sketch that uses Arduino Cloud will give me this error. Not sure what I did but I can't find a solution anywhere.