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: http://www.raspberrypi.org/downloads/. 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 http://sourceforge.net/projects/win32diskimager/. 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:
startx



Files Used in this Post



No comments:

Post a Comment