I thought i could get away from using a debian-based Docker image for .Net Core… *sigh…
For now an Alpine-based Docker image is available for .NET Core on amd64. But the runtime-deps can also be installed to an arm32v6 architecture which Alpine-Linux support so the possibility is almost there.
I wan't to try .Net Core on linux-arm64... but unfortunately, there's no available yet except Win-arm64 and linux-arm32. For this one we'll use a bcm2835 library but later a C# version of this library i had which is on-hold until today.
Extract bcm2835-1.55.tar.gz anywhere you like, because where going to remove it once we have `libbcm2835.so`.
1
2
3
4
tar zxvf bcm2835-1.55.tar.gz
cd bcm2835-1.52/src
gcc -fPIC -c bcm2835.c
gcc -shared bcm2835.o -o libbcm2835.so
You can now remove the bcm2835-1.55 folder and be sure to put libbcm2835.so inside /lib/aarch-~ folder.
We'll create a simple console app using these command dotnet new console -o testapp.
Then modify Program.cs with these codes. What it does is we use libbcm2835.so C internal commands into our C# app using PInvoke.
Take note of the PIN Numbering: bcm2835 library use physical numbering so RPI_GPIO_P1_07 is equal to GPIO4 of our RPi3.
Then issue the command while inside the testapp folder. And copy testapp-linux-arm folder to your Raspberry Pi 3.
Assuming you know how to and already hook up our test circuit: a led attach to our GPIO4 or rather PIN7 on the RPi3 physical Pin header. Please be careful and you should know how to properly hook up our test led to avoid breaking your RPi3.
In RPi3, let us run the docker image then test our testapp on it.
1
docker run -it --privileged --rm -v /home/pi3:/home/share dotnet
--privileged - To give docker access rights to /dev/gpiomem. --rm - the container is removed when it exits or when the daemon exits
Make sure that you have libbcm2835.so inside the /lib/aarch64-~ folder or it will complain about running it in SDK.
Then run our testapp like so...