Device connection failed

I cannot run the very first board example. “Oscilloscope”. Processing sees 2 COM ports, tries to connect to one and then the other, but then announces “failed to connect”. Please help (board is blinking BLU at 2 Hz)

Console report
16:24:56 Detected serial port: COM1 COM3
16:24:56 Attempt to connect COM1…
16:24:59 Attempt to connect COM3…
16:25:1 Device connection failed

Hello @UZEW8 ,

Please provide a link to the code (Processing and microcontroller) you are using.

Which microcontroller are you using?
Operating system?
Processing version?

:)

Thanks for the quick response

My DELL All-In-One computer info is

I’m using Processing 4.4.1

My hardware is:

Starter Kit ESP32
FNK0047 A3B0

From the starter user guide Chapter 1 - Oscilloscope and SerialDevice (first project “ellipse” works OK)

Email disallows any more attachments

Hello,

I am not familiar with this hardware or the protocols they are using.

Is there a very simple serial communication example that you can start with just to verify a connection?

:)

Thank you for engaging

Starter Kit ESP32
FNK0047 A3B0

My Dell All-In-One computer

The Processing tutorial I am working to - Chapter 1 of Processing.pdf 4/23/2025

[image]

The Sketch where I run into trouble. Processing Version 4.4.1

[image]
Library Oscilloscope and
SerialDevice

V 4.4.1 Preferences

[image]

Hi @UZEW8, Please would you look in Device Manager, at the Ports (COM & LPT) (No Processing program trying to talk to the Arduino while you are doing this.)

image

While watching that please connect your Arduino, wait at least 10 sec, and disconnect. You should see an extra com port appear and disappear. (None shown in my image) When it is there it should be normally coloured (as shown) without a yellow triangle. Try each port on your PC. If this works correctly you know the driver is creating the COM port correctly, and you know the correct name.

Richard
This is what I get before and after connecting the board to USB

COM4 goes away when I disconnect the board.
When connecting to other USB ports I get COM5 and COM6. A similar “connection failed” results.
Steve

Hi Steve, It’s good that the COM port is created and shows up cleanly in Device Manager. The board has the CH340 chip (usb-serial interface). A feature (?) of this chip and driver is that the COM port number is differen depending on which usb socket you connect to. The serial properties of the port don’t matter, the sketch will set what it wants.

The Oscilloscope sketch seems to be trying each port, looking for something, not finding what it wants. Have you loaded the Arduino with whatever software does the scope’s data gathering? If you have why is it not working? Hmm… Suggest you examine the sketch where it looks and rejects. You are using an ESP32? Is that the only Ard/ESP you have? We may need another channel to see what’s going on e.g. LCD screen, software serial, WEB? (slow to put together but I have used it).

Richard
This board is an ESP32 and is my first and only Arduino. And this is the first sketch I have tried. I’m going to load and try this on another Windows 10 laptop. Next.
Steve

Steve, I have these progs loaded on a W7 laptop and an Arduino Nano. Considering this is a published example for new users I’m surprised it doesn’t work first time. Please confirm that I’m using the same 4 files:

I’m trying to see why it’s not going. I don’t think another PC will help. I asked about ESP/Ard because if you are investigating and repeatedly loading then ESP is much slower to load. I poke at this for a little longer but don’t let me stop you or anyone else trying anything.

Richard
Here is my SerialCommand - looks the same
/*
Class SerialCommand
Author Ethan Pan @ Freenove
Date 2016/8/8
Brief This class is used to save serial command.
Copyright Copyright © Freenove
License Creative Commons Attribution ShareAlike 3.0

Here is my SerialDevice - different
/*
Sketch SerialDevice
Author Zhentao Lin @ Freenove
Date 2020/07/11
Brief This sketch is used to communicate to Processing sketch running
on PC. The Processing sketch will automatically detect and
connect to this board which use the same trans format.
Copyright Copyright © Freenove
License Creative Commons Attribution ShareAlike 3.0
*/
#include “SerialCommand.h”

Hello @UZEW8,

Please give programs below a try to test communication between Arduino and Processing with your system, software and hardware.

They were Google Gemini generated.
I asked for a simple program to send data from Arduino to Processing.
It could have been simplified.
It works!

Arduino side:

// Arduino Code to send a simple counter value to Processing

int counter = 0; // Initialize a counter variable

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud rate
                      // This speed must match the Processing sketch
}

void loop() {
  Serial.println(counter); // Print the counter value followed by a newline character
                           // The newline character is important for Processing to read full lines
  counter++;               // Increment the counter
  if (counter > 255) {     // Reset counter to keep it within a reasonable range (0-255 for byte)
    counter = 0;
  }
  delay(100);              // Wait for 100 milliseconds before sending the next value
                           // This prevents overwhelming Processing with too much data
}

Processing:

// Processing Code to receive data from Arduino

import processing.serial.*; // Import the serial library

Serial myPort;  // Create a Serial object
int val;        // Variable to store the incoming data

void setup() {
  size(400, 300); // Set the window size (optional, but good practice)

  // Print a list of available serial ports to the console
  println(Serial.list());

  // IMPORTANT: Replace "COM3" (or "dev/cu.usbmodem1411" on Mac/Linux)
  // with the actual serial port your Arduino is connected to.
  // You can find this in the Arduino IDE under Tools > Port, or by looking at the output of Serial.list()
  String portName = Serial.list()[0]; // Assumes Arduino is the first port in the list, adjust if needed
                                       // A more robust way is to specifically look for your Arduino's port
  myPort = new Serial(this, portName, 9600); // Initialize the serial port at 9600 baud rate
                                              // This speed must match the Arduino sketch
}

void draw() {
  background(0); // Clear the background
  // Check if there's data available in the serial buffer
  if (myPort.available() > 0) {
    // Read the incoming data as a line (until a newline character is encountered)
    String inString = myPort.readStringUntil('\n');

    if (inString != null) { // Make sure the string is not null
      inString = trim(inString); // Remove leading/trailing whitespace (especially the newline)
      try {
        val = Integer.parseInt(inString); // Convert the string to an integer
        println("Received from Arduino: " + val); // Print the received value to the console
      } catch (NumberFormatException e) {
        println("Error parsing integer: " + inString);
      }
    }
  }

  // You can use the 'val' variable to do something in your Processing sketch,
  // like drawing a rectangle or changing its color based on the received value.
  fill(val, 100, 200); // Example: Use the received value to control the red component of a color
  rect(width/2 - 50, height/2 - 50, 100, 100);
}

void serialEvent(Serial p) {
  // This function is an alternative way to read serial data,
  // it's called automatically when new data arrives.
  // For this simple example, reading in draw() is sufficient,
  // but for more complex scenarios, serialEvent can be useful.
  // String inString = p.readStringUntil('\n');
  // if (inString != null) {
  //   inString = trim(inString);
  //   try {
  //     val = Integer.parseInt(inString);
  //     println("Received (serialEvent): " + val);
  //   } catch (NumberFormatException e) {
  //     println("Error parsing integer (serialEvent): " + inString);
  //   }
  // }
}

This is what you should see in the Processing console:

I have been embracing AI tools for some code generation.
Do not assume AI code is always correct or the best example and do a thorough examination of code and scrutinize it.
As an experienced programmer I can use these tools effectively and getting better at being a prompt engineer.

Google Gemini responded to above with:

That’s an excellent approach! It’s smart to leverage AI for code generation while maintaining a critical eye. As an experienced programmer, you’re perfectly positioned to use these tools effectively. You know that AI-generated code, while often a great starting point, benefits immensely from careful review, optimization, and validation to ensure it meets your specific project requirements, performance needs, and best practices.

It’s like having a very fast junior developer: they can draft a lot of code quickly, but the experienced hand is essential for quality control and bringing it up to production standards. Keep up the great work!

You must still strive to understand the code.

References can be found here:
Libraries / Processing.org < Serial library!
Prompt engineering - Wikipedia

Here to help if you have any questions!

I did try the oscilloscope code from here but was not successful:
https://store.freenove.com/products/fnk004

:)