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.