Integrated development environments (IDEs) are great for programmers to quickly write code.
The problem with some IDEs is that they can be resource hungry. This is bad news for the Raspberry Pi with its limited CPU power and memory.
But there is Geany! Geany is a lightweight text editor with basic IDE functionality. This is perfect for the Raspberry Pi as it will not hog all of the Pi's resources.
Here is a tutorial on how to setup a Geany project to use the WiringPi library.
The WiringPi library is a C library that allows access to the GPIOs on the Raspberry Pi via the C programming language.
First off, make sure you have the WiringPi library installed on your Raspberry Pi. The official website covers how to do this. http://wiringpi.com/download-and-install/
Next, it's time to install geany. Open a terminal on your Pi. Type the following commands:
To launch geany type:
Note: The & (ampersand) after the program name prevents the locking of the terminal.
geany's main window |
Next click, on Project -> New |
Name it something such as geany_WiringPi. Hit Create. |
Click OK to create the directory. |
Copy and paste the following code:
Save the file as: main.c
This code, when ran will turn on Pin 1 (GPIO1) on for 5 seconds, then turn Pin 1 off, then exit.
Save the file as: main.c
This code, when ran will turn on Pin 1 (GPIO1) on for 5 seconds, then turn Pin 1 off, then exit.
Pin out for the WiringPi library |
But first we need to make a makefile for our project. Here is a great tutorial for making a makefile:
http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html
Go to File -> New
Copy and paste the following code:
Save the file as: makefile
http://www.cs.umd.edu/class/fall2002/cmsc214/Tutorial/makefile.html
Go to File -> New
Copy and paste the following code:
Save the file as: makefile
Notice the library includes:
-I/usr/local/include -L/usr/local/lib -lwiringPi
Make note of -lwiringPi, this is needed for the WiringPi library.
geany should be setup to run your makefile. But not your executable. Since, the WiringPi library needs superuser access for the GPIO control. The execute command needs to be changed.
Click OK.
Now it is time to compile!
-I/usr/local/include -L/usr/local/lib -lwiringPi
Make note of -lwiringPi, this is needed for the WiringPi library.
geany should be setup to run your makefile. But not your executable. Since, the WiringPi library needs superuser access for the GPIO control. The execute command needs to be changed.
Go to Build -> Set Build Commands |
Then change your Execute command to: sudo ./a.out |
Now it is time to compile!
Go to Build -> Make, or press Shift+F9 |
Hit Execute to launch the program! |
And there it is... how to use geany with the WiringPi library!
The code is available on the GitHub at:
https://github.com/sonnysung/Pi430/tree/master/2013_16_07__Geany_WiringPi