Qwiic Pro Micro USB-C Serial connectivity

I am trying to use my Arduino to control some motors through the USB virtual serial port. It seems to work flawlessly through the Arduino port monitor, through TeraTerm also seems to work well, but I am having issues communicating from my C# software that we use for other motor controllers (we are trying to emulate the interface). The C# code is rock-solid, and is not suspect - we have used it for years now - the only caveat is the serial data must be terminated with LF. When we send data from the C# code to the Arduino, the Rx light flashes as it sees data come in, but I don’t get any data coming into the C# side. I have repeated this effort using the Microsoft SerialChat example: https://stackoverflow.com/questions/905 … in-c-sharp, and see the same results. Both of these programs work as expected if I use an FTDI serial converter with pins 2/3 tied together - everything I send shows on the receive side within the C# code.

I have also tried to detect if the serial port is closing on the Arduino side, and it seemed like this might be part of the issue, but I seem to not be able to end/start the connection if I detect the port closing. I am not sure if this is a red herring or not.

I am really wanting to use the USB virtual com port, but I am having trouble getting past this. I have reduced my code to the following example:

int RXLED = 17;  // The RX LED has a defined Arduino pin

void setup()
{ 
  pinMode(RXLED, OUTPUT);  // Set RX LED as an output

  // set up serial port for output
  Serial.begin(115200);
  //while (!Serial)
  //{
  //}
  Serial.setTimeout(100);
  //Serial.println("START");
}

// https://stackoverflow.com/questions/9072320/split-string-into-string-array
String Split(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++)
  {
    if(data.charAt(i)==separator || i==maxIndex)
    {
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }

  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}

void loop()
{
  //or, perhaps we get serial commands
  //check to see if we have data waiting on the serial port
  if (Serial.available() > 0)
  {
    Serial.println("1\n");
    //String lcCmd = Serial.readStringUntil('\n');
    String lcCmd = Serial.readString();
    lcCmd.trim();
    lcCmd.toLowerCase();
    Serial.println(lcCmd);
    Serial.println("2\n");
    //todo/fix - we need to split our string
    if (lcCmd.equals("err?") == true)
    {
      Serial.print("0  -  (error 0 - \"No error\")\n");
    }
    else if (lcCmd.equals("ver?") == true)
    {
      Serial.print("FW_DSP: V1.2.3\n");
    }
    Serial.print("Cmd: " + lcCmd + "\n");
  }
  
  if (Serial == false)
  {
  //  Serial.end();
    Serial.begin(115200);
    Serial.setTimeout(100);
    Serial.flush();
    //digitalWrite(MOT0_ENA, 0);
  }
  else
  {
    //digitalWrite(MOT0_ENA, 1);
  }
  Serial.println("0\n");
  //Serial.flush();
  //delayMicroseconds(50);
  
  digitalWrite(RXLED, LOW);   // set the RX LED ON
  TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
  delay(1000);              // wait for a second

  digitalWrite(RXLED, HIGH);    // set the RX LED OFF
  TXLED1; //TX LED macro to turn LED ON
  delay(1000);              // wait for a second
}

I am a bit lost for which direction to go. My instincts tell me to ditch the USB port and just wire up the RX/TX to my FTDI converter to see how this changes things. I am guessing I have a timing issue, but I thought I would reach out for advice first. I have done quite a bit of searching online, but I am overwhelmed with results that don’t seem to fit my issue.

Are you trying to connect your motors via USB to the pro micro? If so, that unfortunately will not work. You will need to use regular serial and ditch USB. You might be able to do this with a Pi though.

YellowDog - why do you say this won’t work? It is more ideal to use the USB, because if I have to use the external serial TX/RX pins, then I will still need to plug in a USB cable to power the device, and that is an extra cable, and well, just weird from the perspective of the wiring for my project.

To clarify, the motors are connected using the analog and digital pins with an external motor driver. I am also able to control the motors using a joystick and pushbutton to switch which motor is enabled, and all of that bit seems to work great. It even seems to work great when I use the Arduino debug terminal to issue commands, just not from my C# software.

You can connect the pro micro (usb device) to a computer (usb host) and send commands too it to control your motor. You can’t connect a pro micro via usb to another usb device though because both are devices. (USB has to be device to host.)

I see your point, but I am treating the Pro Micro as a device, talking to it with a computer. The motors are not USB, but analog (PWM) and digital.

Try not commenting out the while (!Serial) section and see if that helps.