|
| 1 | +# PiGPIO.jl |
| 2 | + |
| 3 | +#### Control GPIO pins on the Raspberry Pi from Julia |
| 4 | + |
| 5 | +[![][docs-stable-img]][docs-stable-url] |
| 6 | +[](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 | +[](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 | +``` |
0 commit comments