Control GPIO with .NET Core on Raspberry Pi

Background

I wanted to convert the Python code for the Traffic Pi over to .NET Core with C#. These are the steps that I followed to get it set up on the Raspberry Pi 3 that I have.

Move and Run Code on the Pi

Write Your Code

Write the code that you want the program to do. You can do this on your computer or on the Pi itself. I chose to do it on the computer and then transfer the files afterwards.

Software to Install on Pi

Run these commands to install the necessary software on the Pi. You only need to do them once.

sudo apt-get update
sudo apt-get install curl libunwind8 gettext apt-transport-https

Publish Your App

Then run the publish command on your app.

dotnet publish -r linux-arm

Copy the Files

Then copy the files from your computer to the Pi. I used SSH for this.

scp -pr bin/Debug/netcoreapp3.1/linux-arm/publish/* pi@trafficpi://home/pi/trafficpi

Run App On Pi

Run the program by calling the executable. This filename will be the name of your project.

./trafficpi

Conclusion

Since I was able to get this running on the traffic light, I am going to continue to build out the code to have the same functionality that it does with the Python code.

If you want to see the code that is being written, you can visit the project repo to see the code.

Updated: 2020-10-25 | Posted: 2020-10-25
Author: Kenny Robinson