Getting Mono running on Intel Edisons Yocto Linux

Intro

 

Hi there,

after Intel rejected Edison and Co. I was not sure, what to do with the neat piece of hardware, I am owning. Despite of not getting any Support and updates and so forth it is still Hardware, that has WiFi, Bluetooth, SD Card,… onboard. So it has enough capabilities to build cool things. So I decided, not to throw away 😉 and see, what I can do with it from another perspective.

With that in mind, I asked myself, if it isn’t possible, to get my favorite dev setup running on Intel Edison: .Net Framework with C#

For half a year, I gave it already a try, but it was a little bit tricky, by downloading the whole package and compiling it on the Edison (Install Mono by hand [“David’s Random Projects and Documents Web Page”]). In my case, there were problems with storage and compile errors. But then, there was a package update for use with opkg, so that I was able, to get Mono Environment installed and usable. Read here, how things work…

Install Mono

Please make sure, that you added these unofficial packages to your /etc/opkg/base-feeds.conf

src/gz all http://repo.opkg.net/edison/repo/all
src/gz edison http://repo.opkg.net/edison/repo/edison
src/gz core2-32
http://repo.opkg.net/edison/repo/core2-32

After that, type

root: opkg update 
root: opkg upgrade

(if necessary – it upgrades all packages, it can eat up your free space ) in to your bash.

 

Having that done, only
opkg install mono
is needed and everything is ready to use (takes a moment, to download and configure).

Testing Mono installation

You should have a look to your mono version, that is now installed.

root: Mono --version

The output should display something similar to this, where Mono compiler version is 4.2.2. that maps to .NetFramework 4.6 (I thought, please correct me, if I am wrong).

Writing code

After that, you could write your first test app in C#

Create a test folder (like in screenshot above)

root: Mkdir mono_test cd mono_test vi tests.cs

(typing ‚I‘ for Insert | for Save: ESC ‚:‘ after that ‚x‘)

using System;
namespace Tests{
    public class Programm{
        static void Main(string[] args){
           Console.WriteLine("This is my first C# App on Intel Edison!");      
        }    
    }
}

For compiling your first App, type mcs tests.cs  this builds the code to tests.exe
ls -lh  shows up tests.exe in your Folder. Running your app is easy, just type
mono tests.exe  and this is the result:

Adding Hardware access (GPIO,…)

But writing only C# Apps on Intel Edison is not that, what the device is made for, so I needed some access to the underlying hardware. At first I tried to access the mraa libs from Intel by P/Invoke them, but thankfully that guy here Mayuki Sawatari wrote an assembly, that has everything in it (ありがとうございます, すごいです。).

I tried to get everything compiled at my Edison under Yocto Linux, but that was not possible, therefore I cloned it to my Windows machine and opened the solution file with Visual Studio 2017. The build was successful and I could copy over the resulting Dll to my home directory on Edison, where I now have this available for further development.

git clone https://github.com/mayuki/MraaSharp.git
Again, create a file (e.g. pinTest.cs) and copy this code here (It’s slightly modified version from what you can find inside that Git Repository – I adapted it to my Intel Edison Arduino Breakout Board):

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
 
using MraaSharp;
 
namespace PinTests
{
  class Program
  {
    static void Main(string[] args)
    {
      Mraa.Initialize();
      Console.WriteLine("Version: {0}", Mraa.Version);
      Console.WriteLine("PlatformName: {0}", Mraa.PlatformName);
 
      var gpio = new Gpio(MraaIntelEdison.Gp128, MraaGpioDir.Out);
      Console.WriteLine("Gpio Pin: {0}", gpio.Pin);
      Console.WriteLine("Gpio PinRaw: {0}", gpio.PinRaw);
 
      while (true)
      {
        gpio.Write(MraaGpioValue.High);
        Thread.Sleep(1000);
        gpio.Write(MraaGpioValue.Low);
        Thread.Sleep(1000);
      }
    }
  }
}

 

This Code is a working Blink example, which blinks onboard LED every second.

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.