-
Notifications
You must be signed in to change notification settings - Fork 3
/
GPIO_Thread.html
51 lines (43 loc) · 4.9 KB
/
GPIO_Thread.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<HTML>
<head>
<title>GPIO_Thread</title>
<META NAME="AUTHOR" CONTENT="Jamie Boyd">
</head>
<H2>Documentation for GPIO Thread</H2>
<p>GPIO_Thread is a collection of different projects that subclass pulsedThread to control the GPIO peripheral hardware on the Raspberry Pi. These include general purpose pulses or trains of pulses, pulse trains specialized for certain hardware, and special functions like controlling the PWM peripheral. The goals were 1) to make everything threaded, with timing control baked in first, instead of bolted on later, 2) to make things modular so the different projects don't depend on each other too much but do call the same low level code, 3) to make an interface that can be easily controlled from Python. For each project, represented by the placeholder XX, the general organization is:
<ul>
<li>XX.cpp/XX.h pair describing a C++ class that subclasses pulsedThread</li>
<li>XX_tester.cpp, or XX_runner.cpp, that makes a small stand-alone application using XX, mostly for testing purposes</li>
<li>XX_Py.cpp file that describes a Python/C module, ptXX, that wraps the C++ class methods with Python calls</li>
<li>often, PTXX.py that wraps a "Pythonic" object interface around the Python/C module</li>
<li>XX_setup.py that builds and installs the Python/C module and, if present, PTXX.py</li>
<li>Occasionally, PTXX_tester.py that tests some of the functions of the Python module</li>
</ul>
To install the Python module for a project, XX, use<br>
sudo python3 XX_setup.py install<br>
This will install both the Python/C module, and its Python wrapper module, if present.</p>
<p>Before compiling/installing any of the GPIO_Thread projects, you first need to install the <a href="https://github.com/jamieboyd/pulsedThread">pulsedThread library</a>, as it is used by all the projects in GPIO_Thread:<br>
<ol><li>sudo apt-get install python3-dev</li>
<li>git clone https://githib.com/jamieboyd/pulsedThread</li>
<li>cd pulsedThread</li>
<li>make</li>
<li>sudo make install</li>
</ol>
This installs the pulsedThread library, C++ header files, and a C++ file with functions for using pulsedThread from a Python/C module.</p>
<p>In most cases, no external libraries other than pulsedThread are used. Access to the GPIO hardware is done through memory mapping and reading/writing directly to peripheral registers, or through the /sys/ pseudo file system for polling. Constants, macros, and functions for low level access to Raspberry Pi peripherals such as GPIO and PWM are contained in pair of files, <a href = "./GPIOlowLevel.html">GPIOlowlevel.cpp/.h.</a>. All of the projects include these two files.</p>
<p>A define statement in GPIOlowlevel.h on line 23 sets the compiler to use the correct address offsets for the Raspberry Pi models 2 and 3. If you wish to compile for running on a Raspberry Pi model 1, you need to comment out this define statement and uncomment the define statement for the Raspberry Pi 1 on the next line. It is not expected that many people will need to do this.</p>
<p>Some of the projects use only the GPIO peripheral. These can be run without the need of sudo or gksudo. If a class uses any peripheral other than GPIO (PWM or Clock, e.g.), or if the project accesses /sys/ for polling, then programs using it will need to be run with sudo, or gksudo.</p>
<H3>GPIO Thread Projects</H3>
<ol>
<li><a href = "./SimpleGPIO.html">Simple GPIO</a> -- ouputs digital pulses, trains, and infinite trains from a single GPIO pin</li>
<li><a href = "./HX711.html">HX711</a> -- controls an HX711 load cell amplifier, writing clock pulses on one GPIO pin and reading data on another</li>
<li><a href= "./PWM_thread.html">PWM Thread</a> -- controls the Pi's PWM (Pulse Width Modulation) peripheral</li>
<li><a href = "./lever_thread.html">Lever Thread</a> -- controls a lever whose force can be controlled and position monitored, for a special behavioral task</li>
</ol>
<h2>Acknowledgements</h2>
<p>The register addresses and offsets for the low level GPIO code, plus general tips on working with peripherals, were gleaned from various sources, including Gordon Henderson's <a href = "http://projects.drogon.net/raspberry-pi/wiringpi/">WiringPi</a>, Joan's <a href = "http://abyz.co.uk/rpi/pigpio">pigpio</a>, Pieter-Jan Van de Maele's <a href = "https://www.pieter-jan.com/node/15"> Low Level Programming of the Raspberry Pi in C</a>, plus the forums at raspberrypi.org, especially the <a href = "http://www.raspberrypi.org/forums/viewtopic.php?t=37770" a> no-waiting PWM example code </a> of user WAHa06x36.</p>
<H2>Programming Notes</H2>
<p>The timing and threading is controlled by the functions provided by pulsedThread. All of the pulsedThread functions for getting and setting timing and number of pulses can be used in the subclasses in GPIO_Thread. The biggest part of a new project's original code is providing an appropriate task data structure, an initialization function, and the HIGH and LOW functions.</p>
</body>
</html>