Cannot open serial monitor "selected port is closing"


Getting this error message when I click on serial monitor to open it.

I am using an arduino uno and the web editor.

Any ideas what this error means?

I think it must be on my code. Other same hello world serial print simple programs work with the same arduino cable and hardware.

Here is the code I am trying to run.

/* -- New project -- 
This source code of graphical user interface has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.13 or later version download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
  - for ANDROID 4.15.01 or later version;
  - for iOS 1.12.1 or later version;

This source code is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
*/

//////////////////////////////////////////////
// RemoteXY include library
//////////////////////////////////////////////

// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__SOFTSERIAL
#include <SoftwareSerial.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600

#include <RemoteXY.h>

// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 73 bytes
{ 255,7,0,0,0,66,0,19,0,0,0,0,31,1,200,84,1,1,6,0,
  5,5,5,72,72,32,2,26,31,4,85,6,24,72,0,2,26,1,118,14,
  24,24,0,2,31,0,1,155,3,24,24,0,2,31,0,1,135,54,24,24,
  0,2,31,0,1,170,39,24,24,0,2,31,0 };

// this structure defines all the variables and events of your control interface 
struct {
  // input variables
  int8_t joystick_01_x; // from -100 to 100 
  int8_t joystick_01_y; // from -100 to 100 
  int8_t slider_01; // from 0 to 100 
  uint8_t button_01; // =1 if button pressed, else =0 
  uint8_t button_02; // =1 if button pressed, else =0 
  uint8_t button_03; // =1 if button pressed, else =0 
  uint8_t button_04; // =1 if button pressed, else =0 

  // other variable
  uint8_t connect_flag; // =1 if wire connected, else =0 
} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
// END RemoteXY include
/////////////////////////////////////////////

// Variables to store previous values for change detection
int8_t prev_joystick_01_x = 0;
int8_t prev_joystick_01_y = 0;
int8_t prev_slider_01 = 0;
uint8_t prev_button_01 = 0;
uint8_t prev_button_02 = 0;
uint8_t prev_button_03 = 0;
uint8_t prev_button_04 = 0;
uint8_t prev_connect_flag = 0;

void setup() {
  RemoteXY_Init();
  
  // Initialize Serial communication for printing variables
  Serial.begin(9600);

}

void loop() {
  RemoteXY_Handler();
  
  // Print variables when they change or if connection status changes
  printVariablesIfChanged();
  
  // Use RemoteXY_delay() instead of delay()
 
}

void printVariablesIfChanged() {
  // Check if connection status changed
  if (prev_connect_flag != RemoteXY.connect_flag) {
    prev_connect_flag = RemoteXY.connect_flag;
    if (RemoteXY.connect_flag) {
      Serial.println("Connected to RemoteXY app");
    } else {
      Serial.println("Disconnected from RemoteXY app");
    }
  }
  
  // Only print when connected and values change
  if (RemoteXY.connect_flag) {
    // Check joystick X
    if (prev_joystick_01_x != RemoteXY.joystick_01_x) {
      prev_joystick_01_x = RemoteXY.joystick_01_x;
      Serial.print("Joystick X: ");
      Serial.println(RemoteXY.joystick_01_x);
    }
    
    // Check joystick Y
    if (prev_joystick_01_y != RemoteXY.joystick_01_y) {
      prev_joystick_01_y = RemoteXY.joystick_01_y;
      Serial.print("Joystick Y: ");
      Serial.println(RemoteXY.joystick_01_y);
    }
    
    // Check slider
    if (prev_slider_01 != RemoteXY.slider_01) {
      prev_slider_01 = RemoteXY.slider_01;
      Serial.print("Slider: ");
      Serial.println(RemoteXY.slider_01);
    }
    
    // Check button 1
    if (prev_button_01 != RemoteXY.button_01) {
      prev_button_01 = RemoteXY.button_01;
      Serial.print("Button 1: ");
      Serial.println(RemoteXY.button_01 ? "PRESSED" : "RELEASED");
    }
    
    // Check button 2
    if (prev_button_02 != RemoteXY.button_02) {
      prev_button_02 = RemoteXY.button_02;
      Serial.print("Button 2: ");
      Serial.println(RemoteXY.button_02 ? "PRESSED" : "RELEASED");
    }
    
    // Check button 3
    if (prev_button_03 != RemoteXY.button_03) {
      prev_button_03 = RemoteXY.button_03;
      Serial.print("Button 3: ");
      Serial.println(RemoteXY.button_03 ? "PRESSED" : "RELEASED");
    }
    
    // Check button 4
    if (prev_button_04 != RemoteXY.button_04) {
      prev_button_04 = RemoteXY.button_04;
      Serial.print("Button 4: ");
      Serial.println(RemoteXY.button_04 ? "PRESSED" : "RELEASED");
    }
  }
}

Hi, this has also happened to me before. I just waited around 15 seconds and pressed it again. Also, are you using the built in serial port or a library? I am asking because I see #include <SoftwareSerial.h> in your program and I only have experience with the built in serial (that being Serial.print("your text here"); to send and Serial.begin(9600); to start it)

Have a great day!

1 Like

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