Arduino MKR 1010 freezes

Hello everyone,

I am encountering a strange problem with Arduino MKR 1010. I have an inverter with an RS232 interface for communication. I am using this converter between inverter and Arduino. I disconnected the DB 9 female on converter. I got a 1.5-meter cable with three wires (TX, RX, and GND) and connected one end to DB 9 male (going to inverter) and the other side to the converter. I connected RX, TX, GND, VCC from Arduino to the converter. The communication works fine.

The problem is that the Arduino sometimes freezes suddenly and then no data would come to the Serial Monitor. Not only this, but I am not able to upload a new sketch. IDE shows the message that device is not found or the device is not available on the port. Then I have to power off the Arduino and connect it back to make it work again.

I am working remotely, therefore, I have a raspberry Pi that is powering the Arduino. Arduino is connected to the router via Wi-Fi and Pi through LAN. The whole setup looks like this.

I have another sketch to run on this system but I thought it might be the original software problem. Therefore, I made this test sketch and even on this sketch the arduino freeze. So, it doesn't seem to be the software problem.

#include <WiFiNINA.h>

char ssid[] = "MyWiFi";                                                            // your network SSID (name)
char pass[] = "12345678";                                                 // your network password (use for WPA, or use as key for WEP)

int counter = 0;

void connect_WiFi() {

  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);                                                              // Connect to network
  byte COUNTER = 0;

  while (WiFi.status() != WL_CONNECTED) {                                              // Wait for connection
    WiFi.begin(ssid, pass);                                                            // Connect to network
    COUNTER++;
    Serial.print("Loop "); Serial.print(COUNTER); Serial.println(" of 50, and then reset board.");
    if (COUNTER == 50) {
      COUNTER = 0;
      NVIC_SystemReset();
    }
  }

  Serial.println();
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  Serial.println();
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  connect_WiFi();
}

void loop() {
  // put your main code here, to run repeatedly:
  if (WiFi.status() != WL_CONNECTED) {                                                 // Reconnect WiFi if connection is lost
    Serial.println();
    Serial.println("Wi-Fi disconnected...");
    delay(1000);
    connect_WiFi();
  }

  Serial.println(counter);
  counter++;
  delay(1000);
}

Last time, the counter reached 1560 and stopped. I tried to upload a new sketch but didn't work. I tried to ping the Arduino but it showed that device is unreachable. The WiFi is not stable enough, but at least it will reconnect and this won't freeze the Arduino as far as I know.

I think this problem is coming from the inverter or the rs232 converter side. This seems to disturb the serials and freezes the Arduino. Can someone please verify if that could be the problem and how could it be fixed? Thank you all.

Check the powering of the entire setup.
It looks like the router powers the lot. It can be a reason for trouble. Check the router capacity, then then Rbpi....

Thank you @Railroader for the response.

I am working remotely on Rasp pi, the Pi is constantly showing me the low voltage warning message. And as the Pi is powering the Arduino, then probably it could be the reason that Arduino is hanging.

I have changed the sketch where I am not using the Wi-Fi but just communicating with the inverter. Let's see if the trouble appears again.

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial1.begin(9600);
  delay(5000);
}

void loop() {

  const byte message [] = {0x01, 0x03, 0x00, 0x3B, 0x00, 0x1D, 0xF4, 0x0E};             // message to read 29 register
  byte incomingBytes[63];

  Serial.println("Sending request message...");
  Serial1.write(message, sizeof(message));                                             // send request message to inverter
  delay(500);
  while (Serial1.read() >= 0);                                                         // clear the buffer
  Serial1.write(message, sizeof(message));                                             // send request message again
  delay(500);

  if (Serial1.available()) {
    Serial1.readBytes(incomingBytes, sizeof(incomingBytes));
  }

  int inverterStatus = incomingBytes[4];
  
  int32_t powerBytes = incomingBytes[59] << 24 | incomingBytes[60] << 16 | incomingBytes[57] << 8 | incomingBytes[58];
  float Watts = (float)powerBytes / 10.0;

  Serial.print("Inverter Status: ");
  Serial.print(inverterStatus);
  Serial.println();

  Serial.print("AC Output power: ");
  Serial.print(Watts);
  Serial.println(" watts");
  Serial.println();
  delay(10000);
}

Do You have a multimeter so You could measure the Vcc on the Pi, on the Arduino, on the RS232 converter?
Also check the router users manual regarding its capacity of delivering current.

Unfortunately, I am working on the system remotely and I am unable to measure these voltages. But I feel the problem is occurring due to the power. Arduino is powered through USB from Pi and Pi seems unable to give enough power to the Arduino especially when Wi-Fi is connected. I am running a simple sketch in which the communication between Arduino and inverter taking place and no disruption occurred till now.

For the last two day, the Arduino is running normal. I have now plugged the Arduino directly from a 5V phone charger, before it was getting from Raspberry Pi. So, it was the power issue. Thank you @Railroader for your assistance.

Thanks for telling!
Power issues are sad to say way to common among people new in this game. There's no nuclear power plant in any PP3 battery, not in any voltage out pin on controllers. Some where there's a limit and it's exceeded far too often.
You can flag the post solving the issue as "solution".

And the Arduino freezes again. With the independent 5V given to the board via USB, the Arduino almost worked for two days but it suddenly hang and the power LED and the charging LED (which normally blinks when battery is not connected) turned off. After a hard reset, it ran smoothly again. The hanging was more frequent when powered from Pi, but even powered independently, it freezed again.

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