https://github.com/stensmo/wiringpi.jl
WiringPi in Julia
https://github.com/stensmo/wiringpi.jl
gpio gpio-library i2c julia pwm raspberry-pi raspberry-pi-5 spi wiringpi
Last synced: 3 months ago
JSON representation
WiringPi in Julia
- Host: GitHub
- URL: https://github.com/stensmo/wiringpi.jl
- Owner: stensmo
- License: mit
- Created: 2025-05-07T15:28:17.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-05-23T12:45:03.000Z (5 months ago)
- Last Synced: 2025-06-23T15:08:02.424Z (4 months ago)
- Topics: gpio, gpio-library, i2c, julia, pwm, raspberry-pi, raspberry-pi-5, spi, wiringpi
- Language: Julia
- Homepage: https://stensmo.github.io/WiringPi.jl/dev/
- Size: 4.07 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WiringPi in Julia
Raspberry Pi 5 support for GPIO, SPI, I2C (will also work on older models)
**NOTE:** You must run Julia as root (or fiddle with permissions), to allow direct memory acces to GPIO.
**NOTE:** More documentation can be found at https://github.com/WiringPi/WiringPi/
**NOTE:** Will only run on a Raspberry Pi (tested on a Raspberry Pi 5). Remember to enable SPI and I2C using "sudo raspi-config".
Install Julia by running: curl -fsSL https://install.julialang.org | sh
Run julia by typing: sudo $HOME/.juliaup/bin/julia
It's even possible to generate code via Gemini (Google AI Studio). Example prompt: "Generate julia code: Draw image on SSH1106 connected to a Raspberry Pi 5 using WiringPi.jl"
Examples:
```juliausing WiringPi
# You can cut & paste simple examples in C and run it
wiringPiSetupGpio();
pinMode(17, INPUT);
pullUpDnControl(17, PUD_DOWN);value = digitalRead(17)
```
Data acquisition
```julia
# Connect an ADS1115 to the I2C bus (several more chips are supported)
using WiringPi#Pin base is where the virtual pins should start (4 of them for an ADS1115). This is almost like a variable name
pinBase=100
i2cAddress=0x48 # Default for ADS1115
ads1115Setup(pinBase, i2cAddress)#Sets gain to ADS gain 6
digitalWrite(100, ADS1115_GAIN_6)#Sets data rate
digitalWrite(101, ADS1115_DR_64)value1 = analogRead(100)
value2 = analogRead(101)
value3 = analogRead(102)
value4 = analogRead(103)voltages=[6.144,4.096,2.048,1.024,0.512,0.256]
# ADS1115_GAIN_6 = 6.144 volt
volt1=(value1/32767)*voltages[ADS1115_GAIN_6+ 1 ]```
Working with interrupts:
```julia
using WiringPiwiringPiSetupGpio();
pinMode(17, INPUT);
pullUpDnControl(17, PUD_UP);function myInterrupt()::Cvoid
println("Triggered")
endconst myInterruptC = @cfunction(myInterrupt, Cvoid, ())
wiringPiISR(17, INT_EDGE_FALLING, myInterruptC)
```
SPI
```julia
using WiringPi
using RandomwiringPiSPISetup(0, 1000000)
myData = Vector{Cuchar}(undef, 4096)
size = 4096# Populate the data with some random info. Normally you would not overwrite the vector above.
myData = rand(UInt8, 4096)# A copy
sentData = deepcopy(myData)wiringPiSPIDataRW(0, myData, size)
# If you connect MOSI to MISO, the buffer will have the same data as sent. Otherwise it will be zeroes
sentData == myData
```
Full example where WiringPi is driving an e-paper display, and draws a diagram using Makie. Can also be used for displaying SVG.
[WiringPi.jl drive an e-paper display ](https://github.com/stensmo/WiringPi.jl/tree/main/docs/examples)