Click here to Skip to main content
15,879,095 members
Articles / Internet of Things / Raspberry-Pi

Creating C# Applications on Raspberry Pi

Rate me:
Please Sign up or sign in to vote.
4.00/5 (10 votes)
14 Mar 2016CPOL2 min read 33.4K   25   4
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)


Written By
Software Developer (Senior)
India India
Passionate about Microsoft Technologies like WPF, Windows Azure, ASP.NET, Win Phone and also on Cross platform Mobile Apps, Mongo DB's, IOT & WOT. I love learning and working with (or) Creating Design Patterns . Writer | Technology Evangelist | Technology Lover | Microsoft Developer Guidance Advisory Council Member | Cisco Champion | Speaker |

Blog : http://adityaswami89.wordpress.com/

Comments and Discussions

 
QuestionWhy not W10 IoT Core? Pin
Haechtsuppe1-Apr-16 1:50
Haechtsuppe1-Apr-16 1:50 
AnswerRe: Why not W10 IoT Core? Pin
adityaswami891-Apr-16 19:24
professionaladityaswami891-Apr-16 19:24 
QuestionWhy not Raspberry PI 3 instead of 2...3 was release before March 1st date of your article Pin
Des Nolan2-Mar-16 7:35
Des Nolan2-Mar-16 7:35 
AnswerRe: Why not Raspberry PI 3 instead of 2...3 was release before March 1st date of your article Pin
adityaswami893-Mar-16 5:27
professionaladityaswami893-Mar-16 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.