Skip to main content

In this tutorial, We will learn to communicate with an Arduino board connected to a Linux PC (Ubuntu, Linux Mint, Fedora etc.) serial port using C# and .NET Platform.

With the release of the opensource .NET Platform by Microsoft, it becomes possible to run .NET programs on other operating systems like Linux and macOS. Earlier similar capability was provided by the Mono Platform. 

One disadvantage of the .NET platform on Linux is absence of support for WinForms and WPF GUI Library. In our case it won't matter as we are going to be building a command line program for serial communication with Arduino.

Source Codes 

C# and Arduino Source Codes for communicating from a Linux PC using Serial Port can be downloaded from our GitHub Repo (link below).

 

Install .NET SDK & runtime on Linux

The easiest and best way to install the .NET SDK and Runtime is to go to Microsoft Website and check for instructions for your preferred Linux distro.

Microsoft website manages instructions for installing .NET SDK on commonly used Linux distribution's like Ubuntu, Alpine, RedHat etc. You can then select your Ubuntu version and install the SDK and runtime on your system.

installing .net sdk on ubuntu for serial port programming

 

Here is an example of installing .NET SDK 8 on Ubuntu 

sudo apt-get install -y dotnet-sdk-8.0

 how to install  (.net ) sdk on linux for serial port programming

dotnet-sdk-8.0 is the name of the SDK and may change in the future. Replace it with the correct version number of the latest available SDK.

You can check the installed .NET SDK using the  command.

dotnet --list-sdks

how to list the installed dotnet sdks on Linux systems for C# programming

Command for  viewing the installed .NET  runtimes on Ubuntu Linux.

dotnet --list-runtimes

 

Creating a C# .NET Project on Linux 

First thing is to download the C# Serial Port source codes from the GitHub Repo.

How Serial Ports are Mapped in Linux

Managing User/Group permissons in Linux 

Running the C# Serial Port Codes on Linux