Hardware programming in .NET at DWX 2014

Once again I was invited to give a talk at the DWX – Developer Week in Nuremberg, Germany.  Last year I was speaking about “Continuous Integration in .NET”. This year it is a time to give “Hardware programming in .NET” a try. I will show how to create software for Netduino, Tinkerforge and Raspberry Pi using .NET Micro Framework, .NET Framework and Mono. Oh, and I’m planning to build the circuits the talk! It should be a lot of fun. And here a small example of RGB LED attached to Raspberry Pi and programmed in Mono.

 

CODEFUSION’s Illuminated RaspberryPi

 

To get mono to your Raspberry Pi issue following commands:

sudo apt-get update

sudo apt-get isntall mono-runtime

sudo apt-get install mono-mcs

And here is the source code for the blinking LED:

using RaspberryPiDotNet;
namespace HelloRaspberryPi
{
    class Program
    {
        static void Main(string[] args)
        {
            GPIOMem ledRed = new GPIOMem(GPIOPins.Pin_P1_22);
            GPIOMem ledGreen = new GPIOMem(GPIOPins.Pin_P1_18);
            GPIOMem ledBlue = new GPIOMem(GPIOPins.Pin_P1_16);
            while (true)
            {
                ledRed.Write(true);
                System.Threading.Thread.Sleep(1500);
                ledRed.Write(false);
                ledGreen.Write(true);
                System.Threading.Thread.Sleep(1500);
                ledGreen.Write(false);
                ledBlue.Write(true);
                System.Threading.Thread.Sleep(1500);
                ledBlue.Write(false);
            }
        }
    }
}

Prototype is showed showed on the following picture.

2014-04-17 17.01.59

The image below shows the used Raspberry Pi pins used. For Description and matching PIN names to numbers see here http://elinux.org/RPi_Low-level_peripherals. I have used the GPIOPins.Pin_P1_22 = GPIO25 for red, GPIOPins.Pin_P1_18 = GPIO24 for green and GPIOPins.Pin_P1_16 = GPIO23 for blue. Plus the P1-20 for the grounding. I was using 3 220 Ohm resistors connected the the colors (+).

image

To get it running you will have to reference and use the RaspberryPiDotNet.dll from https://github.com/cypherkey/RaspberryPi.Net/ and have the BCM2835 library compiled. You can get install it using following commands:

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.3.tar.gz

tar -zxvf bcm2835-1.3.tar.gz

cd bcm2835-1.3.tar.gz

./configure

make

sudo make install

cd src

cc -shared bcm2835.o -o libbcm2835.so

And compile your program using Mono.

sudo msc ./Program.cs –r: ./RaspberryPiDotNet.dll

and to run it

sudo mono ./Program.exe

Voila!

If you happen to attend the Developer Week / .NET Developer in conference between 14th and 17th July 2014 please drop by to see my talk!

PS. My mono is enclosed in a self printed case (using our 3D printer) with my company CODEFUSION logo.

Leave a Reply

Your email address will not be published. Required fields are marked *