Send Data via USB

Hey,
is it possible to send data via USB to the PC as with the UNO?

How do I transfer them? I have:

void setup() {
  Serial.begin(19200);
}
void loop(){
  winkelAnalog = analog_in.read(winkelSensor);
  //Serial.println(winkelAnalog);
  winkelWert = map(winkelAnalog, 340, 57200, 0, 900) / 10.0;
  Serial.println(winkelWert, 2);
  Serial.println("-");
  Serial.write(winkelWert);
  delay(333);
}

In the console in the IDE the value is displayed but not in my other program which worked with the UNO.

USB-C is VCP UART: this can send data.
Also: breakout board with additional USB-A can send data to host (via USB).

If you use Serial (UART) - just check if it is the same COM port (on PC). Potentially, a different MCU, even a different board, will appear as a different COM port.

Do you have an example for transferring float via USB?
The COM port (COM5) is the same in the IDE and in my other program. However, nothing is displayed in the program.

I don't understand why nothing is output. Do I have to address the USB port other than:
Serial.print(value);
?

EDIT:
Or do I have to tell portenta first that usb is used?
Serial.begin(baudRate); <- currently in startup

You have to open (initialize) the serial connection, even the USB-C VCP based one. Yes, potentially you need such Serial.begin(baudRate);

As I understand: the name Serial, or Serial1 means (selects) if it is USB or another UART (e.g. via UART pins).

And a "float via USB"?
UART transmits bytes, it has no clue about float or int. You have to transfer the bytes for a float (like sending a memory copy).
Or: you convert your float into a string and you send the string.
Example (pseudo-code):

float f = 0.1;
char UARTbuffer[80];
sprintf(UARTbuffer, "My float is: %f\r\n", f);
Serial.Send(UARTbuffer);

I think, in Arduino with C++ code you can also do:

Serial.println(f);

It converts it for you into an ASCII string.

Alright, thanks!

Maybe i have to initialize Serial1 because Serial doesn´t work for me.
Serial.send(); is new for me, i always use Serial.print();.
I saw some code with Serial.write(); but it doesn´t work too.

I have sent my machine control back to the dealer, because the led 12V isn´t working and i think AnalogInput1 isn´t working too. Maybe it is a cause of more of my problems.

Thank you!

Hey,
Current status:
Transfer via the MicroUSB port of the PMC to a PC isn´t possible. Nobody has a solution for this problem. The support probably doesn't know anything either. I have even replaced my PMC, because I thought it was a hardware problem...

Is there any other way to send data to a USB port from a PC?

Assuming the USB as Micro-USB is similar to the USB-A on Portenta breakout board: there is support, I think. On Breakout board it works for me, assuming the same USB FS pins used, similar schematics on PMC - it should work as well.

Why cannot use the USB-C VCP UART on Portenta H7 board to bring your data to host?
Or what about network (ETH or WiFi)?

The USB-A and MicroUSB ports are unfortunately not 100% identical. USB-A cannot be used for programming, and this port does not connect to a PC like the MicroUSB port.

What exactly do you mean by VCP UART? Can´t find it on the Pinout :thinking:

The controller is installed in a machine and operated or read out with a laptop. Most laptops no longer have an RJ45 socket, only WLAN. Many desktop PCs do not have WLAN.
But all of them have USB ports. Therefore I would like to use this.

Another question: The control can but data transmission via RS232? If I use this and put it on a USB-A connector, it should also work? Or use an adapter RS232-USB.

Sure, the User USB is not initialized, there is nothing (except: USB-A can work to use the STM Bootloader in order to flash a FW, e.g. the Arduino Bootloader).

You have to initialize the USB. And it can act as device or host. VCP is a USB "protocol" so that you would see this USB like as UART on host. The USB connector "is the UART".
You have to initialize the USB. And with the correct "USB enumeration" (descriptors) it will be seen by host (PC) as UART.
There is nothing to wire, not a real UART peripheral involved in this case (and much faster as a real UART).

Otherwise, there is an UART available as real UART on the header pins (PA9, PA18). You would need an external UART device, e.g. as a UART-to-USB bridge, e.g.:
CP210x - USB-UART

As extension board:
CP2102N board UART-USB

Alright, thank you.

Do you have an example of how I initialize the USB port (MicroUSB or USB-A)?
I thought it was enough if:

void setup(){
 Serial.begin(9600);
 //Serial1.begin(9600); doesn't work too
}

?

I can't find an example of this anywhere?
Or do I have to do this via USB-A?

Problem solved.
Replace the PMC with another Control unit who works.

Thanks.