Arduino 2.3.2 Serial port hang

If I translate and upload certain ino file it hangs up the serial port. The program itself loaded, but the serial port hungs up and I get a Time out error.The only way I could reset the serial port to reset the uf2 serial communication by pressing the white button while connect the USB port on RP2040 and tanslate and upload the working ino file. Any solution?

Your topic was moved. Do not post in "Uncategorized"; please read the sticky topics in Uncategorized - Arduino Forum.

Please post code and schemmatic. Use code tags for the code.

//#include <SPI.h>
#include <TS_Display.h>
//#include <XPT2046_Touchscreen_TT.h>
//#include <Arduino.h>
//#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
//#include <U8g2_for_Adafruit_GFX.h>
//#include <u8g2_fonts.h>


// ILI9341 LCD kijelző konfiguráció (Soros SPI mód)
#define TFT_CS 17
#define TFT_DC 22
#define TFT_RST 21
#define TFT_LED 28  // Háttérvilágítás vezérléséhez
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

// XPT2046 touch screen konfiguráció (SPI mód)
#define TOUCH_CS 26   // A touch screen chip select pinje
#define TOUCH_IRQ 27  // Interrupt pin
#define TOUCH_MOSI 19
#define TOUCH_MISO 16
#define TOUCH_SCK 18
#define PLUS_ARM_LEN 10

// Pointer to touchscreen object.
XPT2046_Touchscreen* ts;

// Pointer to touchscreen/TFT LCD display object.
TS_Display* ts_display;

const int SCREEN_WIDTH = 320;  // 320x240 kijelző
const int SCREEN_HEIGHT = 240;
const int TEXT_BOX_X = 20;
const int TEXT_BOX_Y = 100;
const int TEXT_BOX_WIDTH = 220;
const int TEXT_BOX_HEIGHT = 50;
char inputText[50] = "";  // Növeljük a buffer méretét a hosszabb szövegek kezelésére
int textIndex = 0;

// Kalibrációs értékek a megadott adatok alapján
const int TS_MINX = 8171;
const int TS_MAXX = 4895;
const int TS_MINY = 7999;
const int TS_MAXY = 4607;
/////////////////////////////////////////////////////////////////////////////////////////////
// Variables.
/////////////////////////////////////////////////////////////////////////////////////////////


// TFT display UL and LR calibration positions and corresponding touchscreen
// calibration coordinates.
int16_t x_UL, y_UL, x_LR, y_LR;
int16_t TSx_UL, TSy_UL, TSx_LR, TSy_LR, Tpress;


void setup() {
  pinMode(TFT_LED, OUTPUT);
  digitalWrite(TFT_LED, HIGH);  // Képernyő háttérvilágítás bekapcsolása
  // SPI inicializálása
  SPI.begin();
  tft.begin();
  ts->begin();
  tft.setRotation(1);  // Állítsd be megfelelően a rotációt, ha szükséges
  tft.fillScreen(ILI9341_BLACK);
  Serial.begin(115200);  // A Serial-Monitor helyett közvetlenül használjuk a Serial-t
  delay(1000);
  Serial.println("Enter text to display on the TFT screen:");

  // Szövegmező rajzolása
  tft.drawRect(TEXT_BOX_X, TEXT_BOX_Y, TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT, ILI9341_WHITE);

  // Touch screen inicializálása
  ts->begin();
  ts->setRotation(1);  // A touch screen rotációját állítsd be, ha szükséges

  // Debug: teszt szöveg megjelenítése a kezdeti helyzetben
  drawText("Teszt");
}

void loop() {
  if (/*ts->tirqTouched() &&*/ ts->touched()) {
    TS_Point p = ts->getPoint();
    ts_display->GetCalibration_UL_LR(PLUS_ARM_LEN + 2, &x_UL, &y_UL, &x_LR, &y_LR);
    delay(300);

    // Kalibráció és érintési koordináták konvertálása
    int touchX = map(p.x, TS_MINX, TS_MAXX, 0, SCREEN_WIDTH);
    int touchY = map(p.y, TS_MINY, TS_MAXY, 0, SCREEN_HEIGHT);
    Serial.printf("X: %d\t", touchX);
    Serial.printf("Y: %d\t", touchY);
    Serial.printf("p.x: %d\t", p.x);
    Serial.printf("p.y: %d\t", p.y);
    Serial.printf("\n");


    // Érintés helyének ellenőrzése és karakter hozzáadása
    if (touchX > TEXT_BOX_X && touchX < (TEXT_BOX_X + TEXT_BOX_WIDTH) && touchY > TEXT_BOX_Y && touchY < (TEXT_BOX_Y + TEXT_BOX_HEIGHT)) {
      Serial.printf("Érintés a szövegdobozban\n");
      delay(300);
    } else Serial.printf("Érintés a szövegdobozon kívül\n");
  }

  // Serial input kezelése
  if (Serial.available() > 0) {
    String input = Serial.readStringUntil('\n');
    input.trim();  // Töröljük a felesleges whitespace karaktereket
    input.toCharArray(inputText, sizeof(inputText));
    drawText(inputText);
  }
}

void drawText(const char* text) {
  // Tisztítsuk meg a szövegdobozt
  tft.fillRect(TEXT_BOX_X + 1, TEXT_BOX_Y + 1, TEXT_BOX_WIDTH - 2, TEXT_BOX_HEIGHT - 2, ILI9341_BLACK);

  // Szöveg megjelenítése a szövegdobozban középen
  int16_t x1, y1;
  uint16_t w, h;
  tft.getTextBounds(text, TEXT_BOX_X, TEXT_BOX_Y, &x1, &y1, &w, &h);
  int16_t cursorX = TEXT_BOX_X + (TEXT_BOX_WIDTH - w) / 2;
  int16_t cursorY = TEXT_BOX_Y + (TEXT_BOX_HEIGHT - h) / 2 + (h / 2);

  tft.setCursor(cursorX, cursorY);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
[rp balancer.pdf|attachment](upload://vVUYlYchF0rJx3VFMjDyLgMwl11.pdf) (20,4 kB)
[rp balancer.pdf|attachment](upload://vVUYlYchF0rJx3VFMjDyLgMwl11.pdf) (20,4 kB)

  tft.print(text);
}

rp balancer.pdf (20,4 kB)

Please place the picture here, not links. Downloading is not popular.
Does serial use the same port as the download? Via USB?

Here is the schematics . Yes serial and download both use COM 6. With an other ino file centirozo.ino what is also use the same hardware has no this problem

The problem caused by the ino file pointer mispointing!!!

What on Earth does that mean ?

The serial communication failed, because in the .ino file I use a pointer in a wrong way. After I correct it, translate and reset the COM6 by putting virtual drive mode and upload the serial communication on the virtual USBserial COM6. Perhaps this uploaded file cause some wrong feedback to the IDE so hung up the serial communication.

Or no feedback at all.

I'm not familiar with your board and the board packages for it.

The usual way how this works for board with native USB like an Arduino Leonardo (and more than likely yours)

  1. Your board is reset by the IDE when you start the upload by opening and closing the port with a baudrate of 1200 baud (you can check what it does if you enable verbose output during upload under file/preferences in the IDE).
  2. Your board will than go into upload mode (for the Leonardo, that will result in the bootloader being invoked, for your board it will go into uf2 mode. In Windows device manager you will probably see that COM6 disappears (and for a Leonardo another port shows).
  3. Transfer of the code starts.
  4. Once the code is loaded, the board will leave the bootloader (or uf2 mode) and start executing the loaded code.
  5. The IDE will start looking for the original COM port (COM6). If your code does not contain bugs, it will find a COM port (usually the same one).

In your case your code resulted undefined behaviour of the loaded program. For boards with native USB the loaded program will contain functionality to

  1. Identify the board to the operating system.
  2. React on the the reset mentioned under (1).

You have invoked undefined behaviour in your code which can result in either functionality not working (e.g. by overwriting variables used by those functionalities); in your case that the board no longer identifies itself properly to the operating system and hence the IDE can't find it and you get the timeout.