Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / IoT / Raspberry-Pi

Creating C# Applications on Raspberry Pi

4.00/5 (10 votes)
15 Mar 2016CPOL2 min read 34K  
Creating C# application’s on Raspberry Pi

Azure IOT Series

1. Azure IOT with Raspberry Pi : Azure IOT

  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:

      CSS
      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 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 World” Console Application. Build and generate the ‘.exe’ file.
    C#
    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: raspberry

    Then you will be able to transfer the file.

    2

  9. Once you have copied your Release folder into Raspberry Pi, I created a folder called Code and dumped the Debug file. Our Rasp will look as below:

    3

  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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)