Monday, August 18, 2014

Getting Started with the Raspberry Pi (Part 2 of 5)

The first thing we need to do is choose which operating system we want to load on our Raspberry Pi. There are quite a few different options available. For example if you want to use your Raspberry Pi as a XBMC server you can install RASPBMC. But for us we are going to install a version of Linux using RASPBIAN. You can checkout all the builds here: I will link to the exact Image I used at the bottom of this post.

After downloading the image we're going to need to burn it to our micro SD card. I used a USB micro SD reader on my laptop like this one.

Flash SD Card on Windows
Flashing you SD card is very easy on a windows machine. I used Win32DiskImager from It automatically formatted and imaged my SD card without any issues. Below is a screenshot of Win32DiskImager in action.

Flash the SD Card on Mac
  1. Start by opening "Disk Utility"
  2. Select your SD card
  3. Repartition it to 1 partition and format it using MS-DOS (FAT)
    See the screenshot below:

After the format is done we need to verify the location of the drive. Click the newly created partition, then select “First Aid” and finally click the “Verify Disk” button. This will reveal our SD cards true location. It should look like “/dev/disc1s1” just like the screenshot below.

Right-click on the newly created partition and select the “Unmount” option. We are now ready to load the image file onto our SD drive. Make sure you know the location of your image. I put mine in the root of my harddrive to make the command easy to type.

In the terminal type:
sudo dd if=/raspbian.img of=/dev/disk1 bs=4m

You will need to open a terminal window and type in the command shown above. You will want to double-check your disk number and the path to the image file.

After 10 minutes or so your terminal will look like the image below and you are now able to boot your SD card in your Raspberry Pi.

Connect to TV
When developing for the Raspberry Pi, I connected the pi up to a television and used the television as a large monitor. You could SSH into your Raspberry Pi but for now I recommend just using your television as a monitor.

Initial Set-up
The first time you boot the Raspberry Pi you will need to be connected to a TV and you will also need a keyboard. I recommend expanding the file system and changing the password from the set-up menu. The default user name is pi and the default password is raspberry.

SSH into the Pi
SSH will give you a remote terminal but you cannot boot into any graphical user interfaces. SSH is great for command line only functionality. You will need to get your Raspberry Pi’s IP address. If you have it hooked up to a television you can type “ifconfig”. If you do not have a television available you will need to look at your router logs to find the correct IP address.

Mac use Terminal
ssh pi@192.168.1.??

Windows use Putty

Auto Login
Normally I am not a big fan of auto login but in this case I want a standalone device that will automatically restart if power is ever lost. Because we are working in the terminal, I recommend using SSH so we can copy and paste the commands below.

In the terminal type:
sudo nano /etc/inittab
Arrow down to:
1:2345:respawn:/sbin/getty --noclear 38400 tty1
Comment the line out like below:
#1:2345:respawn:/sbin/getty --noclear 38400 tty1
Add this line below the line you just commented out:

1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

Press Ctrl+X to exit, then Y to save followed by an enter

Install Mono
sudo apt-get update
sudo apt-get install mono-complete -y

Start X Windows
Now that we installed the mono framework we can start writing C# code that will run on our Raspberry Pi. We could write a console application or a GUI application. In the next post I will cover writing a simple GUI application. To get to the graphic interface just type:

Files Used in this Post

Thursday, August 14, 2014

Overview of the Raspberry Pi (Part 1 of 5)

By this point in time I'm guessing many of you already know what the Raspberry Pi is or probably already own one. For those of you that are interested in learning how to write Microsoft C# on the Raspberry Pi this blog series is for you.

I want to start the series by talking about the hardware. As an overview the Raspberry Pi is a small computer that has special pins that can be used to read input or turned hot for output and you can manipulate them through code. It also has a built in HDMI port so you can use your TV as a monitor. The thing that got me excited was the low cost of the hardware. You can pick up a new Raspberry Pi for about $35. People use them for a wide variety of tasks like multimedia players or controlling things like a garage door.

I bought one a few years back when they first came out and I was waiting for the perfect project, well that project never came and I felt like I needed to do something with this piece of hardware because it was sitting on my shelf for way to long. I decided like many others that I would make a garage door opener. I figured since I already knew how to write iPhone apps this would be a perfect way of tying these two technologies together.

The thing that makes the Raspberry Pi so powerful is the GPIO pins. First off GPIO is an acronym for (General Purpose Input Output). These are the pens that I needed to test if my garage door was open or closed and if I sent a signal to open my garage I needed to turn one of the pins hot so that way the garage door would open. For my project I used GPIO 4 to test the current status of the garage door and GPIO 17 to push the garage opener button. I could have chosen any of the GPIO pins in the image below. The GPIO ports are light green in color.

As I work through this blog series we will get to a point where we can actually test the current pins and change the status of the pins. Each post will walk you through the exact process I went through in order to get everything working correctly. I will also include all the software that I use in each project as well. By no means am I trying to take any credit for any of the 3rd party software I used. I'm only including it as a mirror because at some point I will want this software again and I don’t want to risk not finding the correct version.