Arduino Nano ESP32 keeps disconnecting after code is uploaded

Hi, after uploading my code via usb my arduino nano esp32 is disconnecting from my laptop.

I've been testing with an example program and immediately after the code is uploaded, the board disconnects and the on-board led flashes blue/red/green. It .continues to do this and won't reconnect until the re-set button is pressed and the board is physically disconnected from my laptop

I am not getting any error message

1 Like

Hi @charlottehh. Please post your full sketch. I'll take a look and see if I can spot the problem.

I'll provide instructions you can follow to do that:

  1. Auto Format your code by following these instructions:
    • If using Arduino IDE: select Tools > Auto Format from the menus.
    • If using Arduino Cloud Editor: press the Ctrl+B keyboard shortcut.
  2. Click on the window that contains your sketch code.
  3. Press the Ctrl+A keyboard shortcut.
    This will select all the text.
  4. Press the Ctrl+C keyboard shortcut.
    This will copy the selected text to the clipboard.
  5. Open a forum reply here by clicking the "Reply" button.
  6. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  7. Press the Ctrl+V keyboard shortcut.
    This will paste the compilation output into the code block.
  8. Move the cursor outside of the code block markup before you add any additional text to your reply.
  9. Repeat the above process if your sketch has multiple tabs.
  10. Click the "Reply" button to post the output.

When your code requires a library that's not included with the Arduino IDE please post a link to where you downloaded that library from, or if you installed it using Library Manager (Sketch > Include Library > Manage Libraries... in Arduino IDE or Libraries > Library Manager in "Arduino Cloud Editor") then say so and state the full name of the library.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels


#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);  
  
  
  void setup() {
  display.clearDisplay();

  display.setTextSize(2); // Draw 2X-scale text
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(10, 0);
  display.println(F("50"));
  display.display();  
  }

  void loop(){

  }

  

OK, great. I was able to reproduce the problem by uploading your sketch to my Nano ESP32.

I noticed that you forgot to add a call to display.begin in your setup function before attempting to use the display. Once I added this line to the top of the setup function to the sketch, the problem went away:

display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);

So please try doing that. You can learn about this function by studying the examples for the library. You can access the examples via the File > Examples > Adafruit SSD1306 menu in Arduino IDE.

A post was split to a new topic: Port disconnects after I upload my sketch