Slide 1: Accessing the Real World
Lecture 7
Uli Raich
UCC semester 2017/2018
Slide 2: Access libraries
As we have already seen, the Raspberry Pi flat cable connector
and the cobbler + bread board, give access to external hardware though
- gpio
- I2C bus
- SPI
- serial port interface
Dedicated interfaces to camera and display
Slide 3: Software access
Of course you can access the external hardware through
the BCM-2837 interfaces and their registers directly, however,
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
To my knowledge there are 2 such libraries around
(at least these are the most popular ones):
Slide 4: How to download and install
Both libraries can be downloaded as git source archives,
which 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 check out the current version,
work on it and you can 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, or it may be a 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.
Slide 5: Getting the LED blink program to work
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:
Slide 6: Creating blink.c
As you would expect, wiringPi has its own include file
which you 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.
Slide 7: The C code of blink.c
Slide 8: The Makefile to build blink
Slide 9: Ohm's law
If you consider that the LED has no resistance and the Raspberry Pi
drives the GPIO pins with 3.3V and you connect as shown in the circuit diagram,
then what is the current flowing through the LED?
Slide 10: WiringPi functions
The library has functions to
- Setup and initialize the library
This will open the needed device drivers and give access to them
- Core functions: Functions to
- set gpio pins to input or output and
- to read and write from /to them
- define pull-ups/pull-downs
- Some Pi specific functions liking getting the version no
- Timing functions (e.g. delays)
Slide 11: WiringPi functions (2)
- Priority, interrupts, threads
- I2C bus functions
- Serial line functions
- SPI functions
- Miscellaneous function
Slide 12: The gpio command
In addition to the library functions a new command:
gpiois provided. This can be used to set gpio pins from bash
It has however many more options. Look them up in its man page.
--
Uli Raich - 2017-09-27
Comments