Unable to read Raspberry Pi Pico Serial output from C#


Last year I picked up an Uno for a lockdown project. That went well and I’ve just bought a Raspberry Pi Pico for more speed and memory. However the Serial communication code that worked fine with Uno/C# comms isn’t working with Pico/C# comms.

Using Serial.write on the Pico will cause the output to appear in the Arduino IDE’s Serial Monitor but C# won’t find anything to read.

For a test I’ve stripped it down to this:

void setup() {
  while (!Serial) { }  

void loop() {
  Serial.write( "Hello World\n" );
  delay( 1000 );

As expected, the Serial Monitor is full of “Hello World”, but this test C# snippet gets nothing.

SerialPort serialPort = new SerialPort( "COM6", 9600 );
while ( true )
    Console.WriteLine( $"Received: {serialPort.ReadExisting()}" );

Note: I do not have the Serial Monitor and the C# app trying to connect at the same time as I know that will cause problems.

Does the Pico do something different with its Serial output that the monitor is aware of but I’m missing in my SerialPort setup in C#?

Any help would be much appreciated.

1 Like

My experience: The Pico only sends after a change from .close () to .open () in the C # program.
After restarting the Pico, I do this sequence in the C # program.

Ok, I might have a solution. Doing some digging into general USB CDC/C# serial problems and I found this suggestion. In C# I also need to set the following flags.

serialPort.RtsEnable = true;
serialPort.DtrEnable = true;

With those I could merrily receive data in C# from the Arduino Pico.

However the same problem presented itself when C# tried to send to the Arduino Pico. Initial experiments seem to indicate I need to poll for data using Serial.available in loop() rather than rely on serialEvent, but I need to poke this particular problem further.


This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.