Setting up the Raspberry Pi for programming from Mac OS X

In this article I will explain how I set up my Raspberry Pi to be programmable from my macbook pro. I didn't want to use an external monitor & keyboard, nor did I want to connect my Pi to the router of my home network as this setup would not be very mobile. To achieve this, I made use of SSH and the mac's ability to share its internet with other computers. I will not use any GUI to do the programming, as I find that running a GUI on a small embedded computer like this is overkill. Instead I will do all the programming from the command line. A small example of how to do this is included here as well. This article was mainly written as a future reference for myself, but I hope it can be useful for others as well.

Step 1: Prepare the SD-card

First of all, you will need an SD-card with a bootable linux image. I recommend using the "Raspbian Wheezy" image, which is an optimized version of debian. It is downloadable from http://www.raspberrypi.org/downloads/. Instructions for putting the image on the card properly can be found on the eLinux website.

Preparing SD card

If this has succeeded, you can boot up your Raspberry Pi! For the initial boot we will need an external monitor & keyboard, so we can set everything up properly.

Step 2: Basic configurations

The easiest way to do the basic setup is by making use of the raspi-config tool, it should start up automatically on your first boot.


If it doesn't start automatically, you can also launch it with:
sudo raspi-config
I would recommend starting off by setting configure_keyboard and change_timezone. As we won't use any GUI for our programming, it is a good idea to set up memory_split so that the ARM gets 240MB of RAM and the VideoCore only 16MB as this will speed up things a lot. If you have a large SD-card (> 4G) you might want to consider using expand_rootfs to enable all this space. The downside of this is that backups of your SD image will be significantly larger.

The most important thing we had to do here, was to enable SSH. The more recent versions of raspbian have this enabled by default though.

If you have used configure_keyboard, you should run:

sudo setupcon
to avoid a massive delay in the boot process.

Step 3: Find out the Raspberry Pi's IP adres

At this point, we need our Pi connected to the internet. If you have a router close to your working environment, plugging it in there would be fine. If you don't however, it is very easy to use the "internet sharing" option on a mac to provide internet to your Raspberry Pi. On your mac, go to: "System Preferences > Sharing".


As you can see, I chose to share my macbook's wifi through the ethernet port. If I plug in my Raspberry there, it will have internet.

Now go back to the Raspberry Pi's monitor & keyboard. To be able to connect to the Pi through SSH, we need to know the IP adres it is using. To find it out, we enter the following command:
ifconfig
You should see something like "inet addr: 192.168.2.2".

Step 4: Connect to the Raspberry Pi from your mac

Now we know everything we need to know and everything is set up properly, we can disconnect the monitor & keyboard from our Pi (forever). To connect establish the SSH connection, go to the mac terminal and type (you should of course change the IP with the one you found earlier):

ssh -lpi 192.168.2.2

If it is the first time you connect to this device, you will probably see something like "The authenticity of the host can't be ... blabla". You can answer "yes" to this.

You will be prompted for the password now. If you did not change this in step 2, and you are using the recommended raspbian image, the password is "raspberry". Enter this, and you are now logged in to the Pi! You should see something like this:

Step 5: Setup a basic programming environment

You don't need much to programming from the command line in linux, but you do need a good text editor. I use vim. If this is the first time you work with vim, I recommend taking 10 minutes time to check out a good tutorial. To install vim on your raspberry pi, simply type:

sudo apt-get install vim

Because I think syntax highlighting and line numbering are essential programming tools, I want to enable these by default. You can do this by editing (or creating) the .vimrc file in your user directory. We'll do this using vim:

vim ~/.vimrc
Then add the following two lines:
syntax on
set number

Now it's time to test our tools! If you write a very simple "Hello World!"-program with vim, it should look like this:

If you name the file "main.cpp", you can compile it with:

g++ main.cpp -o HelloWorld
If you then run it with:
./HelloWorld
you can sit back, and enjoy the most simple program in the world!

If you're interested in doing some more advanced programming of your Raspberry Pi, check out my article on Low Level Programming of the Raspberry Pi.

Comments

Hello,
I found your article about "Setting up the Raspberry Pi for programming from Mac OS X" very interesting, but I have not been able to connect by ethernet my "Raspberry Pi" with my "Mac Pro". It seems that the configuration to share an "Internet connection" is more complicated than what you've shown.
Can you help me?

My configuration :
- LAN with router and DHCP server (ADSL BOX)
- Mac Pro with "OS X Mountain Lion" and Wifi connection with DHCP client (192.168.0.xx)
- ethernet cross-over cable between "Mac pro" and "Raspberry Pi"

Can you be more specific about the problems you are having with my approach? I have checked this on another computer and it works just fine. Are you sure you are using the correct cables etc.? Thanks

Yes, the cable is OK!
When I connect it to the BOX/ADSL, I get an IP address automatically via DHCP: 192.168.0.35.
When I connect it to the Mac, the ethernet connection on the Mac gives me the following IP address 169.254.32.59 with the subnet mask 255.255.0.0, and, of course, I followed the "Step 3". But I don't get an IP address on the "Raspberry Pi"!
Below is a copy of the result of the command "ifconfig" (I masked the MAC address)
pi@raspberrypi ~ $ ifconfig
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:90 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
RX bytes:11865 (11.5 KiB) TX bytes:7931 (7.7 KiB)

After I made a short-circuit on my raspberry pi, I had the same problem as you. I solved it by turning the "internet sharing" option on my mac off and on again. It worked instantly. Let me know if this works for you too. Sorry you had to wait so long for another reply from me. Maybe you have to connect your Raspberry Pi to the mac first, and then enable internet sharing?

Any way to get started with Pi without ever using an external monitor? All I have are laptops in my home, no external screens. Suggestions welcome :):)

Thanks!

Pieter-Jan, you must be from Holland. So am i, so will type in Dutch:

Ik heb problemen ervaren.

Ik ben nu bij stap 5. Ik wil VIM installeren op mijn Raspberry Pi door "sudo apt-get install vim" in te typen in de XL Terminal van de Raspberry. Als ik dat doe geeft de Raspberry aan wat hij wil installeren en vervolgens krijg ik de optie om door te gaan of te stoppen door "Y" of "N" in te typen. Als ik "Y" typ geeft ie aan dat pagina "404 not found" melding. Hier loop ik dus vast.

Ik heb evt. screenshots (foto's) gemaakt van de meldingen die ik je mogelijk kan mailen.

Je tutorial is duidelijk en ik waardeer het. Maar ik hoop dat je me verder kunt helpen.

Alvast bedankt!

B

I apologize! You're Belgian!

I finally fixed my previous problem, but now i have another one:

Its step 4. when it asks my password (which is still 'raspberry') in the terminal i can't type! So now im not able to enter the password! Please help!

Thanks in advance,

B

Hello, sorry for my late reply. If debian asks you for a password it will not show the characters you are typing. Just type the word and press enter. It should work.

Hello Pieter,
After hours of search, I am really glad to find your tutorial. Just what I'm trying to do.
I'm traveling, with a macbook Pro and a Raspberry in my luggage, trying to connect both of them without success through an ethernet cable. ( wifi Internet connection ).
… But I'm still having the same problem Ricardo Anaya told you, even after your advice of " turning the "internet sharing" option on your mac off and on again ". The IP address is still something like " 169.254.32.59 with the subnet mask 255.255.0.0 ".
The problem also is that I can't connect the Raspberry to another monitor to find out what it's IP is… is there a way to find it through the macbook Pro ? :/
Thank you for your help :) ! ®

Hello, does anyone know how I need to configure the Mac keyboard in the Raspberry PI configuration in order to use all keys e.g. to use square brackets, etc.?
Many thanks in advance, Tino

Hi! I searched for hours on this. Do you know if there is a way to now ssh to the pi via a computer on the wifi network (using the internet sharing)? I have my imac wired to the pi and it works fine with the same configuration as yours. I am wondering (and hoping) if I can cross the subnets, since the pi is in 192.168.2.x, and all other computers are in 192.168.1.x. Your help is greatly appreciated.
Al

Thanks for finally talking about >Add new comment | Pieter-Jan.com <Loved it!

Hi there! This article couldn't be written any better!
Looking at this article reminds me of my previous roommate!
He constantly kept preaching about this. I most certainly will send
this post to him. Pretty sure he's going to have a good read.
I appreciate you for sharing!

Hosatgator is amongst the best hosting services I've used.
I especially such as fact they provide discounts to your clients.
They may have excellent free tutorials to show you
detailed how to maske your own personal website.
I will be utilizing their baby gatkr insurance policy forr my website and I've never had any difficulty.

Recommended!

I drop a cоmment eɑch time Ι liҝе ɑ post on ɑ website or I ɦave something tօ add to
the discussion. Uѕually іt is caused bʏ thе passion displayed
іn the article Ӏ looked аt. And after thiѕ post Addd new comment | Pieter-Jan.com.
I waѕ actually excited enough to drop a leave a responsea response :-) I actuаlly
ԁο have 2 questions for yоu if іt's allright.
Could it be only me or ɗo sօme of tthe responses аppear lіke
written by brain dead visitors? :-P And, iif уou аrе posting on otɦer online sites,
I woulԁ likе to follow еverything new yoս havе to
post. Woul yߋu list еveгy one οf yߋur communal sites lіke your
twitter feed, Facebook pɑge ߋr linkedin profile?

What's Going down i am new to this, I stumbled upon this I've found It positively helpful and it has
helped me out loads. I am hoping to give a
contribution & aid other users like its helped me. Good job.

It's impressive that you are getting thoughts from this paragraph as
well as from our dialogue made at this time.

Thanks for the marvelous posting! I genuinely enjoyed reading it, you may be a great author.

I will always bookmark your blog and will often come back later on. I want to
encourage one to continue your great work, have a nice morning!

Hi, its pleasant piece of writing concerning media print,
we all know media is a great source of facts.

Link exchange is nothing else but it is just placing the other person's website link
on your page at proper place and other person will also do same for you.

It's amazing to visit this web page and reading the
views of all mates about this piece of writing, while I am also zealous of getting knowledge.

What's up it's me, I am also visiting this website regularly, this web site is in fact good and the people are in fact sharing
pleasant thoughts.

I am truly happy to read this blog posts which includes plenty of helpful facts, thanks for providing these information.

What's up, this weekend is fastidious in support of me,
as this point in time i am reading this wonderful informative
piece of writing here at my residence.

Wow, wonderfful blog layout! How llng have you
been blogging for? you made blgging look easy. Thhe overall look of your
site is excellent, let alone the content!

Howdy! This post could not be written any better! Looking at this post reminds me of my previous roommate!
He always kept preaching about this. I am going to forward this
information to him. Pretty sure he's going to have a very good read.
Thank you for sharing!

Stunning story there. What happened after?
Good luck!

That is really fascinating, You're a very skilled blogger.
I have joined your rss feed and stay up for in the hunt for extra of your
excellent post. Also, I've shared your website in my social networks

hi!,I love your writing so a lot! percentage we keep in touch more approximately your post on AOL?

I require an expert on this area to solve my problem.
May be that's you! Taking a look forward to peer you.

I know this site offers quality depending articles or reviews and other information, is
there any other site which offers these kinds of things in quality?

Pages

Add new comment