Creating C# application’s on Raspberry Pi

  1. Buy (and receive) : Raspberry Pi kit (Raspberry Pi 2, HDMI cable, Wi-Fi Adapter/LAN wire, USB charger/normal USB driver mobile charger, Memory Card with NOOBS preinstalled)… Done
  2. You would have got NOOBS preinstalled…so OS is ready….Done
  3. Connect Raspberry Pi to internet using your Wi-Fi Adapter.
    •  Open command prompt and type in
      sudo iwlist wlan0 scan
      

      This will list all the Wi-Fi networks available. You would need to note the ESSID of the network you wish to connect.1

    •  Open the “wpa_supplicant” file as below
      sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
      

      Go to the bottom of the file and type in

      network={
      ssid="The_ESSID_from_earlier"
      psk="Your_wifi_password"
      }
      
    •  Now save the file by pressing Ctrl+X then Y, then finally press Enter.
    •  Reboot your Pi :
       sudo reboot  
    • You can verify if it has successfully connected using
       ifconfig wlan0  

      If the “inet addr” field has an address beside it, the Pi has connected to the network. If not, check your password and ESSID are correct.

  4. Now to write C# applications we need to intall Mono on our Pi
    $ sudo apt-get update
    $ sudo apt-get install mono-runtime
    
  5. To make your mono applications make a REST based calls we would need to install trusted roots certificate from Mozilla as below
    $ sudo mozroots --import --ask-remove --machine
    
  6.  Now open Visual Studio and create any simple “Hello Word” Console Application. Build and generate the ‘.exe’ file.using System;
    public class HelloWorld
    {
    static public void Main ()
    {
    Console.WriteLine ("Hello from Raspberry Pi");
    }
    }
  7. Download FileZilla Client from: https://filezilla-project.org/  . This is used for transferring your files from your desktop to Raspberry Pi.
  8. Once download and install click File -> Site Manager.
    Host: Ip Address of Raspberry Pi ( use command ip addr to get the Ip from Rasp)
    Protocol: SFTP
    Logon Type: Normal
    User: pi
    Password: raspberryThen you will be able to transfer the file.2
  9. Once you have copied your Release folder into Raspberry Pi. I have create a folder called Code and dumped the Debug file. Our Rasp will look as below3
  10. In Raspberry Pi you will be able to run your application as ,
    mono /home/pi/Code/Debug/Device.exe
    

 

In our Next Blog, we will learn how to use Azure IOT and connect our Raspberry Pi to Azure and receive messages.

One thought on “Creating C# application’s on Raspberry Pi

Leave a comment