Call Us On : 044 4203 2818 / 9751800789
Raspberry Pi C programming

Execellent guidance for new user of raspberry pi baord . In this

web page how to start raspberry pi board using c programming

for projects. 1CRORE PROJECTS WILL PROVIDE 100% real time

guidance for your technical problems through online or direct

training.


call us 044 4203 2818 / 9751800789 .

Email :1croreprojects@gmail.com

1CRORE PROJECTS Specialist  in giving Embedded system training IN INDIA FOR multiple micro controller and processors with real time projects as examples and syllabus.



GENERAL PURPOSE I/O PORT GPIO IN RASPBERRY PI BOARD.











RASPBERRY PI C PROGRAMMING USING GPIO EXAMPLES:


For using GPIO using C programming first driver for Bcm 2835 should be installed by following method then only GPIO access will be possible.

Using your RPi download the .tar.gz file from the library page to your "/home/pi/" root directory.

Open the command prompt using Menu > Other > LXTerminal Install the library files using the following commands Unzip the downloaded file (Change the file version number to match your downloaded version)

tar zxvf bcm2835-1.8.tar.gz

The files will be unzipped into a folder called "/home/pi/bcm2835-#.#" where # is the version number. (The following instructions are based on the instructions in the bcm2835.h file so if something doesn't work check there to see if the instructions have changed).

Change to the directory the files we're unzipped into (Change the directory version number to match your downloaded version)

cd bcm2835-1.8
Run the configure exe
./configure
Execute the makefile

make
Then
# as root:
Then
make check
Then
sudo make install
(The sudo is needed to elevate permissions to the root user)
The library is now ready to use.
Once above installation is completed and create C source file using cmake IDE which is inbuilt with Raspberry pi os installation.
First c program example:
#include
int main()
{ /* print a string to the string */
printf(“/in the beginning …\n”);
/* return 0 to signal success. */
Return 0;
}
Edit , compile and run
The first.c program should typed in using a text editor . for this nano is used as an example . This nano editor is in built in your Lxterminal by typing sudo nano. Some useful nano commands are given in the table below.
For opening a file type a command like below
: nano file.c ---- open a new or existing file called file.c
: Ctrl+o -- Write the current file to disk.
: Ctrl+x -- Exit and ask if the current file should be written.
: Ctrl+W Ctrl+t 10 – Navigate to line no 10.
Open two terminal windows , one for nano and the other for compilation. ( Using the default Raspberry PI Debian image , a terminal window can be opened by clicking on accessories and then LXterminal).
Use nano to create a new file called first.c . Type the program and save it as first.c by typing Ctrl+0 and file name first.c and save it . Before a C program can be run it has to be compiled in Linux the GNU C compiler (gcc) is used to compile C source code . In the other terminal window, compile
: gcc –o first first.c ( o – alphabet o)
The gcc compiler will then attempt to compile the C program and link it together with the standard libraries to form an executable called first. If the compiler is successful , no messages will be printed on the screen . if an error is reported by the compiler check the line number where the error is reported and try to compile the program after makes changes again. When the program has been successfully compiled, run the executable by typing ./first .
This will print the string into the screen and return zero to the operating system. In the Bash shell the output value from this return statement is stored in the $? Variable. This variable holds the return statement from the previous command only . Type echo $? To print the value of $? On the screen.
Printing a String :
The Execution of the first.c program starts from the main() function. The function has integer (int) return value , which is given to the left of the function name array arguments passed into the function would go within the parantheses().
In this function would go within the paranthesses(). In this case , no arguments are passed into the main function. The body of the function is defined by the brackets { } , which is referred to as a compound statement . A semicolon is used to complete each line or statement within the compound statement. In the first program there are only two statements , (i) a print f function call to print a string to the screen and (ii) the return statement . The printf function is a standard library function , but for the program to be compiled its declaration has to be included by including stdio.h . The linker then finds the library that contains the implementation of this function and forms an executable.
There are many standard library functions defined in the stdio.h header file . these functions can be used to read from the keyboard and write the screen . input values can be read from the keyboard using the scanf function.
#include
Int main()
{
int age ;
printf (“ how old are you ? “) ;
scanf (“%d” , &age);
printf (“ you are %d years old . \ n , age);
}
In the age.c program an integer variable is declared to hold a value . The integer variable corresponds to a space in the memory of the computer, which is allocated to hold the value. The user is asked their age. Then the program waits for input from the keyboard. The input is read from the keyboard using the scanf function. The character code %d tells scanf to read an integer from the keyboard and it is stored on &age variable. The age value is then written back to the screen using printf.