C is a natural choice to program in on the Raspberry Pi. It's very powerful, usable on virtually all hardware platforms and really similar to lots of other programming languages such as Java, PHP, C# and objective C. As popular programming languages go its as powerful as it gets, with only assembler beating it in terms of programming to the bare metal of a hardware platform.  Its also what Linux itself is written in.

The notes on this site are largely focused on programming in C and C++ and we typically do this running on the Raspbian operating system.  If you are a beginner don't worry about the distinction between C and C++ too much.  You can start programming in a C++ project just using C and move into using the more fancy C++ concepts later on – you don't have to choose one or the other at the outset.  Once you start using some of the higher level features of C++ you can cause problems by also using straight C, but by the time you are comfortable doing that you should have learnt enough about the language to avoid those sorts of issues so don't worry about it at the outset.

Getting Started On Your Raspberry Pi For C & C++ Programming

Here's our step by step guide to getting up and running for C development on a Raspberry Pi using an IDE (Integrated Development Environment) so you don't have to program using the Linux command line.

1) Download the Raspbian Wheezy SD card image from the Raspberry Pi website downloads page

2) Install it on a SD card using win32diskimager (if you are running Windows) or use the new noobs installer.

3) Boot your RPi, log in and start the GUI

4) Geany will already be installed.

5) If you want to control the IO pins of your Raspberry Pi install the bcm2835 library by Mike McCauley

5) Create a new Geany project

That's it, happy coding!

Programming Your Raspberry Pi From Windows

This is very much do-able and the best solution for this we've found is using NetBeans, see here.

How Do We Used To Do It (Before NetBeans – This section is here still just for archive reasons)?

[Update 2015-02: This section was written before the release of the Raspberry Pi 2, which makes programming in an IDE directly on the Raspberry Pi a more realistic proposition with the version 2 performance boost.  The method of programming mentioned here is still very useful though if you want to be able to edit your code from a powerful PC running Windows etc]

We work primarily on Windows and our ideal is to be able to program using a good Windows IDE (Integrated Development Environment application).  We do that to program all sorts of embedded micro controllers and other processor boards so for us its an obvious choice to make for programming on the RPi too.  However we've not yet found the perfect solution. You'll notice in this section of the site various different approaches are documented and this is simply us making notes as we've tried different things searching for an optimum solution and learning the hard way (for instance Linux heads in forums swearing QEMU is the way to go, but finding out after a day of banging our head against a wall its seriously flawed until someone uber expert creates a more powerful hardware file for it).

The main problem – the RPi is amazing but its slow for an IDE and efficient fast desktop workers.  Sure you can program on the command line (and you'll find plenty of Linux heads telling you its best) but like marmite only certain people can bear to program in such a confined way and its definitely not for us. If you are new to programming then using Geany on the RPi is a brilliant way to get going creating a single file program or a multiple file program using a makefile like the one on this page. Once you get into programming large projects the sluggishness of the RPi platform is likely going to annoy you though. Its not just that the basic text editor in Geany is sluggish, its that you are likely also switching between Geany and web pages, pdf's, etc and having to wait for the OS to catch up all the time can be a massive pain.

This is how we've dealt with it for now (we keep looking for new better ways):

For projects that are using standard C libraries and simple to copy over RPi libraries we use eclipse on Windows with a cross compiler solution as documented here.

When we're programming applications using libraries with a lot of dependencies (e.g. GTK+), or if working on a PC where we don't want to go through the arduous process of setting up eclipse for windows cross compiler  programming we do the following to do "sort of" windows programming with eclipse!

We setup a network file share on the RPi using SMB as documented here. This lets us access the RPi via windows networking (it becomes a network device in Windows explorer)

We create a project in Geany on the RPi (various .c and .h files with the makefile on this page.

We then close Geany and run Eclipse on Windows.  We open the RPi .c and .h files in eclipse via the network drive and use eclipse to write our code.

We save the files using CTRL+SHIFT+S for save all and then we build the project from the RPi command line, or using LX Terminal if we're using the desktop, by moving to the project directory (e.g. cd projects/my_project/ ) and entering:


make

The results of the make are shown and if there are errors we have to reference them by line number in the files (eclipse show line numbers option is in: Menu > preference > general > editors > text editors > show line numbers).

Once we have a successful build we run the application on the RPi from the command line or LX Terminal using


sudo ./my_application.a

Its not ideal as the compiler is slower running on the RPi, we can't just double click on errors to be taken to the offending line in our code and we can't debug by stepping through the code, but the benefit of programming in a fast editor on a fast PC and getting to use the PRi with its amazing capabilities from the Linux OS and libraries makes this a pretty good compromise solution a lot of the time.

 

 





USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.

Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

  • Pingback: Windows Eclipse Programming of the RPi « Raspberry Pi Projects()

  • Howard Pratt

    Very useful. I will be trying this out with my students this week

  • heydar

    Thank you

  • met4000

    Couldn’t download the Image; downloaded and came as a blank ZIP folder!

  • Rub Av

    Or you can forward X11 and use geany directly in windows but remote connected to Pi.

  • zoli meder

    is useful, but i’ve done over SSH and the dubigging was available, slower but available

  • Francis Yu

    Hi, I am new to the Raspberry Pi environment. I got two Raspberry Pi
    boards to experiment, the A+ and 2B. I downloaded Mike McCauley’s
    BCM2835 I/O driver package. In it there is a sample program called
    Blink, which just toggles the I/O PIN 11. I tried this program on my A+
    board and it works, but when I ran it on the 2B board nothing happened.
    At first I thought that my 2B board was defective, so I have gotten
    another one, but it behaved the same as the first 2B board. Is there
    something I overlooked, like the I/O block address is different between
    the CPUs on the A+ board and the 2B board? Any help is appreciated.
    Thanks.

  • Francis Yu

    After I post the above question, I searched a bit more and found it mentioned somewhere that I/O base address is 0x3F000000 for BCM2836, and the BCM2835 is 0x20000000. After I made this change, I can toggle the I/O pins on the 2 B boards now. I have read that over and over again, that the Raspberry Pi A+ and 2B are almost identical except for that the A+ is the stripped down version of 2B. But this difference in I/O base address is huge, how come no body had mentioned this? Am I missing something, like the I/O base address can be mapped through program control so that the same program can be run on both A+ and 2B?

  • Hi, I did install the Wheezy image but after boot of the RaspberyPi I do not see anything on the screen. Yet I can see a boot is taking place because of the blinking LEDs op the RPi and the alighting LEDs on my keyboard. I am using the 7″ Touchscreen Display.

  • I cannot get the Wheezy disk image to boot after installation with win32diskimager. I am using the 7″ Touch Screen and it does not show anything after a boot. I can see the system is booting as the RPi led’s are blinking and the keyboard led’s also. Everything goes well with a NOOBS install.