| gpio | General-purpose input/ouput |
| I2C bus | Inter-integrated Circuit (I2C) -- I-Squared-C |
| SPI | Serial Peripheral Interface |
| serial port interface |
External hardware through the BCM-2837 interfaces and their registers directly.
This is not for the faint-hearted (read the 200 page manual first!)
The easier way to access these devices are ready made libraries giving you a simpler API for access
The most popular easier access libraries are;
Both libraries can be downloaded as git source archives.
Git download allows you to have the very latest version and to keep your version up to date.
Git is a revision control system allowing many developers to work on the same project.
You can check out the current version of a software, work on it and upload to the git server the modifications you made.
You can also create a new code branch where you implement new functionality which may be specific to what you want to use the code for
You may also try to implement new options which may later be discarded or, in case everybody is interested in this new functionality it may be merged back into the main branch.
We download the source code of the library from git to where we want to install it in our file system.
To obtain WiringPi using GIT:
cd
git clone git://git.drogon.net/wiringPi
To build/install there is a new simplified script:
cd ~/wiringPi
./build
we compile with ./build. This is a shell script!
In order to keep the library up to date we have to
cd ~/wiringPi
git pull origin
This will update the source code to the latest version
Here is the installation manual of wiringPi.
The wiringPi library has included a few example programs to show its use.
The most simple one is a program making a LED blink.
!WiringPi has its own numbering system for the GPIO pins:
wiringPi has its own include file which must use in order to access the library:
#include <wiringPi.h>
On our systems we have installed this include file is in /usr/include
On the Pi file system while the library itself is in /usr/lib
As these are the standard positions for include files and libraries on a
Linux system all we have to do in the Makefile is to add -lwiringPi to the LDLIBS macro.
The LED has no resistance and the Raspberry Pidrives the GPIO pins with 3.3V.
You must ALWAYS use resistors to connect LEDs up to the GPIO pins of the Raspberry Pi.
The Raspberry Pi can only supply a small current (about 60mA).
The LEDs will want to draw more, and if allowed to they will burn out the Raspberry Pi.
Resistors specifically limit the amount of ‘current’ that flows in a circuit.
The measure of resistance is called the Ohm (Ω), and the larger the resistance, the more it limits the current.
If we connect LED with circuit diagram shown below, then what is the current flowing through the LED?
Setup and initialize the library:- This will open the needed device drivers and give access to them.
Core functions:
sets the mode of a pin to either INPUT, OUTPUT, PWM_OUTPUT or GPIO_CLOCK
void pinMode (int pin, int mode)
read and write from /to pin mode
int digitalRead (int pin) ; the value HIGH or LOW (1 or 0) to the given pin
void digitalWrite (int pin, int value); It will be HIGH or LOW (1 or 0) depending on the logic level at the pin.
sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input.
void pullUpDnControl (int pin, int pud)
Some Pi specific functions liking getting the version no
Timing functions (e.g. delays)
Priority, interrupts, threads
I2C bus functions
Serial line functions
SPI functions
Miscellaneous function
Assignments
a=`ls -l` # Assigns result of 'ls -l' command to 'a'
Conditional statements 
Loops
There is the gpio command, which is part of wiringPi.
It has many options. Please have a look at its man page!
One option allows to read and write GPIO pins:
gpio write $PIN $ON_OFF
If PIN is 0 and ON_OFF is 1 then the LED connected to GPIO pin 0 will go on.
String handling functions
Some bit handling function
Exiting a program gracefully
Compare strings strcmp and strncmp
strcmp(string1, string2); #Compare strings
strncmp(string1, string2, n); #Compare first n charaters
Copy strings strcpy and strncpy
strcpy(destination, source); #Copy from source to destination
strcpy(destination, source, n) ; #Copy n character from source to destination
Locate a sub-string strstr
sine
rectangular
triangular
sawtooth
lowest significant,
medium significant and
highest significant bits
The data nibble (4 bits of data)
The register selection (0,1,2)
The read/write bit
| I | Attachment | Action | Size | Date | Who | Comment |
|---|---|---|---|---|---|---|
| |
blink.png | manage | 48 K | 16 Oct 2018 - 20:18 | IsaacArmahMensah | |
| |
blinkMake.png | manage | 6 K | 16 Oct 2018 - 20:59 | IsaacArmahMensah | |
| |
check.png | manage | 19 K | 18 Oct 2018 - 04:15 | IsaacArmahMensah | |
| |
comarg.png | manage | 8 K | 18 Oct 2018 - 03:21 | IsaacArmahMensah | |
| |
condition.png | manage | 13 K | 17 Oct 2018 - 20:58 | IsaacArmahMensah | |
| |
endlessloop.png | manage | 5 K | 18 Oct 2018 - 03:21 | IsaacArmahMensah | |
| |
gpio1.png | manage | 157 K | 16 Oct 2018 - 19:48 | IsaacArmahMensah | |
| |
install.png | manage | 40 K | 18 Oct 2018 - 03:27 | IsaacArmahMensah | |
| |
loop.png | manage | 12 K | 17 Oct 2018 - 20:58 | IsaacArmahMensah | |
| |
resistor.png | manage | 7 K | 17 Oct 2018 - 04:18 | IsaacArmahMensah | |
| |
rootuser.png | manage | 11 K | 18 Oct 2018 - 03:27 | IsaacArmahMensah | |
| |
strstr.png | manage | 18 K | 18 Oct 2018 - 04:10 | IsaacArmahMensah | |
| |
testarrange.png | manage | 32 K | 18 Oct 2018 - 04:15 | IsaacArmahMensah |