Skip to content

Commit 22c7fa1

Browse files
committed
add pigpio
1 parent 963cf06 commit 22c7fa1

22 files changed

Lines changed: 4059 additions & 0 deletions

deploy/dev/PiGPIO/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.jl.cov
2+
*.jl.*.cov
3+
*.jl.mem
4+
.DS_Store

deploy/dev/PiGPIO/LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The PiGPIO.jl package is licensed under the MIT "Expat" License:
2+
3+
> Copyright (c) 2016: aviks.
4+
>
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in all
13+
> copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
> SOFTWARE.
22+
>

deploy/dev/PiGPIO/Project.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name = "PiGPIO"
2+
uuid = "bb151fc1-c6dc-5496-8ed6-07f94907e623"
3+
version = "0.2.1"
4+
5+
[compat]
6+
Aqua = "0.8"
7+
Sockets = "1"
8+
Test = "1"
9+
julia = "1"
10+
11+
[deps]
12+
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
13+
14+
[extras]
15+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
16+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
17+
18+
[targets]
19+
test = ["Aqua", "Test"]

deploy/dev/PiGPIO/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# PiGPIO.jl
2+
3+
#### Control GPIO pins on the Raspberry Pi from Julia
4+
5+
[![][docs-stable-img]][docs-stable-url]
6+
[![documentation dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaberry.github.io/PiGPIO.jl/dev/)
7+
8+
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg
9+
[docs-stable-url]: https://juliahub.com/docs/PiGPIO/
10+
11+
[![PiGPIO](https://img.youtube.com/vi/UmSQjkaATk8/0.jpg)](https://www.youtube.com/watch?v=UmSQjkaATk8)
12+
13+
PiGPIO.jl is a Julia package for the Raspberry which communicates with the pigpio
14+
daemon to allow control of the general purpose
15+
input outputs (GPIO).
16+
17+
This package is an effective translation of the python package for the same.
18+
Which can be found [here](http://abyz.me.uk/rpi/pigpio/python.html)
19+
20+
Click [here](https://medium.com/@imkimfung/using-julia-to-control-leds-on-a-raspberry-pi-b320be83e503) for an **in-depth tutorial** on how you can control GPIO pins such as LEDs from Julia on the Raspberry Pi.
21+
22+
> [!IMPORTANT]
23+
> This package relies on the [pigpio daemon which does not support Raspberry Pi 5](https://github.com/JuliaBerry/PiGPIO.jl/issues/24). If you have a Raspberry Pi 5, consider to use
24+
[WiringPi.jl](https://github.com/stensmo/WiringPi.jl/)
25+
### Features
26+
27+
* OS independent. Only Julia 1.0+ required.
28+
* Controls one or more Pi's.
29+
* Hardware timed pulse width modulation.
30+
* Hardware timed servo pulse.
31+
* Callbacks when any of GPIO change state.
32+
* Create and transmit precise waveforms.
33+
* Read/Write GPIO and set their modes.
34+
* Wrappers for I2C, SPI, and serial links.
35+
36+
Once a pigpio daemon is launched on the pi this package can connect to
37+
it and communicate with it to manipulate the GPIO pins of the pi. The actual
38+
work is done by the daemon. One benefit of working this way is that you can
39+
remotely access the pi over a network and multiple instances can be connected
40+
to the daemon simultaneously.
41+
42+
## The daemon process `pigpiod`
43+
44+
On Raspberry Pi OS, the daemon `pigpiod` can be installed and launched by using the following shell commands:
45+
46+
```bash
47+
# install pigpiod
48+
sudo apt-get install pigpiod
49+
# enable pigpiod via system D
50+
sudo systemctl enable pigpiod
51+
# start pigpiod now
52+
sudo systemctl start pigpiod
53+
```
54+
55+
The daemon can also be launched manually with `sudo pigpiod` in the terminal.
56+
57+
## Installation and Usage
58+
59+
```julia
60+
using Pkg
61+
Pkg.add("PiGPIO")
62+
63+
using PiGPIO
64+
65+
pi=Pi() # connect to the pigpiod daemon on localhost
66+
```
67+
68+
## Example Usage
69+
70+
The `pin` number corresponds to the GPIO pins
71+
(General Purpose Input/Output, aka "BCM" or "Broadcom") and not
72+
to the physical pin numbers.
73+
74+
```julia
75+
set_mode(pi::Pi, pin::Int, mode)
76+
get_mode(pi::Pi, pin::Int)
77+
# mode can be PiGPIO.INPUT or PiGPIO.OUTPUT
78+
79+
PiGPIO.read(pi, pin)
80+
PiGPIO.write(pi, pin, state)
81+
# state can be PiGPIO.HIGH, PiGPIO.LOW, PiGPIO.ON, PiGPIO.OFF
82+
83+
PiGPIO.set_PWM_dutycycle(pi, pin, dutycyle)
84+
# dutycyle defaults to a range 0-255
85+
```

deploy/dev/PiGPIO/docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/
2+
site/
3+
src/examples/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"

deploy/dev/PiGPIO/docs/make.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Documenter
2+
using PiGPIO
3+
using Literate
4+
5+
Literate.markdown(joinpath(@__DIR__, "..", "examples", "01_blink.jl"), joinpath(@__DIR__, "src", "examples"))
6+
Literate.markdown(joinpath(@__DIR__, "..", "examples", "02_blink_twice.jl"),joinpath(@__DIR__, "src", "examples"))
7+
Literate.markdown(joinpath(@__DIR__, "..", "examples", "03_rgb.jl"), joinpath(@__DIR__, "src", "examples"))
8+
9+
makedocs(
10+
sitename = "PiGPIO",
11+
format = Documenter.HTML(),
12+
modules = [PiGPIO],
13+
# examples need to be run on a Raspberry Pi
14+
doctest = false,
15+
draft = true,
16+
pages = [
17+
"index.md",
18+
"Tutorial" => "tutorial.md",
19+
"API Docs" => "api.md",
20+
"Examples" => [
21+
"Blink Once" => "examples/01_blink.md",
22+
"Blink Twice" => "examples/02_blink_twice.md",
23+
"Red-Green-Blue" => "examples/03_rgb.md"
24+
]
25+
]
26+
)
27+
28+
deploydocs(;
29+
repo="github.com/JuliaBerry/PiGPIO.jl",
30+
)

deploy/dev/PiGPIO/docs/src/api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# PiGPIO API
2+
3+
```@index
4+
```
5+
6+
```@autodocs
7+
Modules = [PiGPIO]
8+
```
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PiGPIO.jl
2+
3+
Documentation for PiGPIO.jl
4+
5+
## Control GPIO pins on the Raspberry Pi from Julia
6+
7+
[![PiGPIO](https://img.youtube.com/vi/UmSQjkaATk8/0.jpg)](https://www.youtube.com/watch?v=UmSQjkaATk8)
8+
9+
PiGPIO.jl is a Julia package for the Raspberry which communicates with the pigpio
10+
daemon to allow control of the general purpose
11+
input outputs (GPIO).
12+
13+
This package is effectively a translation of the python package of the same.
14+
Which can be found [here](http://abyz.me.uk/rpi/pigpio/python.html)
15+
16+
## Features
17+
18+
* OS independent. Only Julia 1.0+ required.
19+
* Controls one or more Pi's.
20+
* Hardware timed pulse width modulation.
21+
* Hardware timed servo pulse.
22+
* Callbacks when any of GPIO change state.
23+
* Create and transmit precise waveforms.
24+
* Read/Write GPIO and set their modes.
25+
* Wrappers for I2C, SPI, and serial links.
26+
27+
Once a pigpio daemon is launched on the pi this package can connect to
28+
it and communicate with it to manipulate the GPIO pins of the pi. The actual
29+
work is done by the daemon. One benefit of working this way is that you can
30+
remotely access the pi over a network and multiple instances can be connected
31+
to the daemon simultaneously.
32+
33+
## Launching the Daemon
34+
35+
Launching the daemon requires sudo privileges. Launch by typing `sudo pigpiod`
36+
in the terminal.
37+
38+
## Installation and Usage
39+
40+
```julia
41+
using Pkg
42+
Pkg.add("PiGPIO")
43+
44+
using PiGPIO
45+
46+
pi=Pi() #connect to pigpiod daemon on localhost
47+
```
48+
49+
## Example Usage
50+
51+
```julia
52+
set_mode(p::Pi, pin::Int, mode)
53+
get_mode(p::Pi, pin::Int)
54+
# mode can be INPUT or OUTPUT
55+
56+
PiGPIO.read(p, pin)
57+
PiGPIO.write(p, pin, state)
58+
#state can be HIGH, LOW, ON, OFF
59+
60+
PiGPIO.set_PWM_dutycycle(p, pin, dutycyle)
61+
#dutycyle defaults to a range 0-255
62+
```
63+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
## Overview
2+
Via this tutorial, we shall be going over the entire process of installation and use of the Julia Programming language on a Raspberry Pi. We will be using the [PiGPIO.jl](https://github.com/JuliaBerry/PiGPIO.jl) library for controlling GPIO elements (namely LEDs). We shall be building a simple circuit of two alternately blinking LEDs.
3+
4+
## What you'll need
5+
You will require a Raspberry Pi (I am using a Raspberry Pi 3 model B+), along with the standard peripherals(keyboard, mouse, display, power supply), 1 breadboard, 2 resistors, 2 LEDs and jumper wires. I am assuming that you have the Raspbian OS set up and running on the Raspberry Pi. If not, take a look at [this tutorial.](https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up)
6+
7+
## Setting up Julia
8+
9+
In your __Raspbian commmand line__, simply run:
10+
11+
```
12+
sudo apt install julia
13+
```
14+
Next, we need to launch a __pigpio daemon__, which PiGPIO.jl can connect to and control the GPIO pins. To do this, run the following command.
15+
```
16+
sudo pigpiod
17+
```
18+
Then, run this to enter the __Julia REPL__
19+
```
20+
julia
21+
```
22+
now run the following commands to install the __PiGPIO__ library:
23+
24+
```
25+
using Pkg
26+
Pkg.add("PiGPIO")
27+
```
28+
You should now be ready to start with the circuit
29+
30+
## Building the Circuit
31+
32+
connect the __cathode__ of both the LEDs to the __ground rail__ of the breadboard. Connect the __anode__, via an appropriate resistor (I used 82 ohm) to __GPIO pins 2 and 3__ of the Raspberry Pi.
33+
34+
### circuit diagram for reference:
35+
36+
![](https://github.com/NandVinchhi/JuliaGPIO/blob/master/circuit.png)
37+
38+
You are now ready to launch Julia and start coding. PiGPIO.jl should be installed by now.
39+
40+
## The Code
41+
You can run this code through an __external text editor__ or in the __Julia REPL__ itself.
42+
First we need to import the package with the __using__ keyword. Next, we need to initialize the Raspberry Pi by creating an object variable and initialising it to __Pi()__
43+
44+
```Julia
45+
using PiGPIO
46+
pi = Pi()
47+
```
48+
49+
Next, we need to intitialize the GPIO pins and their state (__INPUT/OUTPUT__ --> in this case __OUTPUT__).
50+
51+
```Julia
52+
pin1 = 2 # GPIO pin 2
53+
pin2 = 3 # GPIO pin 3
54+
55+
set_mode(pi, pin1, PiGPIO.OUTPUT)
56+
set_mode(pi, pin2, PiGPIO.OUTPUT)
57+
# ^ initialization
58+
```
59+
60+
Now we shall use a for loop to implement the blinking LEDs
61+
62+
```Julia
63+
num_loops = 20 # The number of times you want the lights to blink.
64+
for i = 1:num_loops
65+
PiGPIO.write(pi, pin1, HIGH) # setting GPIO pin state
66+
PiGPIO.write(pi, pin2, LOW)
67+
sleep(1) # delay in seconds
68+
PiGPIO.write(pi, pin1, LOW)
69+
PiGPIO.write(pi, pin2, HIGH)
70+
sleep(1)
71+
end
72+
```
73+
74+
You should be getting blinking LEDs when you run this code.
75+
76+
### pictures of the final working model:
77+
![](https://github.com/NandVinchhi/JuliaGPIO/blob/master/pic1.jpg)
78+
79+
![](https://github.com/NandVinchhi/JuliaGPIO/blob/master/pic2.jpg)
80+
81+
This project was made by Nand Vinchhi for the purpose of __GCI 2019__.
82+
83+
Circuit diagrams drawn with [circuit-diagram.org](https://www.circuit-diagram.org/)

0 commit comments

Comments
 (0)