bcm2835-d 0.0.4
High-level D bindings around the WiringPi library
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
bcm2835-d
D wrapper for WiringPi (Raspberry Pi GPIO library) complete with nice abstractions and a clear implementation.
How to use
It's very easy. First add the package with:
dub add bcm2835-d
Then write some code like this:
import bcm2835;
import std.stdio;
import core.thread : Thread, dur, Duration;
void main()
{
writeln("Startup");
// initialize the driver (this may throw an exception)
auto driver = new BCM2835();
writeln("Got driver: ", driver);
// set the pins as outputs
Pin pin_1 = 18;
Pin pin_2 = 23;
Pin pin_3 = 24;
driver.output(pin_1, pin_2, pin_3);
// drive them all low
driver.low(pin_1);
driver.low(pin_2);
driver.low(pin_3);
driver.setState(pin_1, pin_2, pin_3, State.Low);
Thread.sleep(dur!("seconds")(1));
driver.setState(pin_1, pin_2, pin_3, State.High);
Thread.sleep(dur!("seconds")(1));
driver.setState(pin_1, pin_2, pin_3, State.Low);
Thread.sleep(dur!("seconds")(1));
// do a fancy little light affect
Duration wait = dur!("msecs")(100);
while(true)
{
writeln("red");
driver.setState(pin_1, State.High);
driver.setState(pin_2, State.Low);
driver.setState(pin_3, State.Low);
Thread.sleep(wait);
writeln("blue");
driver.setState(pin_1, State.Low);
driver.setState(pin_2, State.High);
driver.setState(pin_3, State.Low);
Thread.sleep(wait);
writeln("green");
driver.setState(pin_1, State.Low);
driver.setState(pin_2, State.Low);
driver.setState(pin_3, State.High);
Thread.sleep(wait);
}
}
You can also see an example in the testing/
directory,
run the following to try it out (it will use root to run
as we need access to the GPIO):
cd testing/
./test.sh
Debugging
Set the build flag DBG_PRINT
for debug prints to be enabled.
Building
You can build by running:
dub build
Note, that you may want to specify the WPI_NEW_SETUP
flag on the command-line (or via your project's dub.json
with the "versions"
array) if you want to make use of the newer functions from the WiringPi library that are only available in version 3 and later; by default we use the version 2 methods.
Todo
- [ ] Remove
gogga
dependency when not in debug build - [ ] Add
stateRead
(digitalRead()
) support - [ ] If I really want to I could also add support for the plethora of other features WiringPi offers
Dependencies
You need to install the libwiringpi-dev
package so that the share
object files required during link time are available.
The actual linking is handled all automatically by Dub, so you need not worry about manually specifying the library's name.
License
The license for this project is the LGPL-2.1-only.
Licenses of included components
The wiringPi.h
header file, used for type definitions, is stored
at source/bcm2835/wiringPi.c
(extension renamed for ImportC compatiblility). This is from the WiringPi project which itself is licensed under the LGPL v3.
Special thanks
I am very thankful for the team behind the WiringPi project not only for creating a library that exposes the GPIO in a simple way but also for licensing it in the way they did.
I highly recommend that you donate to them - you can go and open up an issue on their GitHub repository and send them some money!
- Registered by Tristan B. Velloza Kildaire
- 0.0.4 released 10 days ago
- deavmi/bcm2835-d
- LGPL-2.1-only
- Copyright © 2025, Tristan B. Velloza Kildaire
- Authors:
- Dependencies:
- gogga, niknaks
- Versions:
-
0.0.4 2025-Mar-22 0.0.3 2025-Mar-21 0.0.2 2025-Mar-17 0.0.1 2025-Mar-17 ~master 2025-Mar-22 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
9 downloads this month
-
9 downloads total
-
- Score:
- 0.6
- Short URL:
- bcm2835-d.dub.pm