mattlewis
Posts: 103
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Update on diozero - Java Device I/O library

Fri Feb 12, 2016 12:33 pm

Almost ready for a 1.0 release, see https://github.com/mattjlewis/diozero for details.
I was getting some odd behaviour with wiringPi, Pi4j and JDK Device I/O so I knocked together a pigpio JNI wrapper library (there was one already but was only partially implemented). This is currently my preferred provider for Raspberry Pi.
Again I understand the overlap in functionality between this and Pi4j, in particular the new device capabilities in v1.1-SNAPSHOT. However as previously stated I wanted to ensure maximum portability across devices as well as present a clean object-orientated API similar to that offered by the Python GPIO Zero.

Usage example:
1. Controlling an LED with a button

Code: Select all

try (Button b = new Button(buttonPin, GpioPullUpDown.PULL_UP); LED led = new LED(ledPin)) {
	b.whenPressed(led::on);
	b.whenReleased(led::off);
	Logger.info("Waiting for 10s - *** Press the button connected to pin {} ***", Integer.valueOf(buttonPin));
	SleepUtil.sleepSeconds(10);
}
2. Doing the same via a MCP23017 GPIO expansion board:

Code: Select all

try (MCP23017 mcp23017 = new MCP23017(intAPin, intBPin)) {
	try (Button button = new Button(mcp23017, inputPin, GpioPullUpDown.PULL_UP);
			LED led = new LED(mcp23017, outputPin, false, true)) {
		button.whenPressed(led::on);
		button.whenReleased(led::off);
		Logger.debug("Waiting for 10s - *** Press the button connected to MCP23017 pin {} ***", Integer.valueOf(inputPin));
		SleepUtil.sleepSeconds(10);
}
As always feedback is very welcome.

Matt
http://www.diozero.com/

mattlewis
Posts: 103
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Update on diozero - Java Device I/O library

Sat Feb 20, 2016 10:42 pm

Uploaded another snapshot build to the Maven repository - newest addition is support for all MCP30/32/34 ADCs as well as WS281x / NeoPixel LEDs (via a JNI wrapper around the rpi_ws281x library).
Slowly working on the documentation at http://rtd.diozero.com.

Matt
http://www.diozero.com/

mattlewis
Posts: 103
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Update on diozero - Java Device I/O library

Wed Jun 07, 2017 7:42 pm

If anyone is interest this library continues to be actively developed; it now works on all flavours of Pi, Beaglebone Black, Asus Tinker Board, CHIP and CHIP Pro, Odroid C2 as well as Arduino's connected via USB using the Firmata protocol. All device control is handled by dynamically loaded providers, including pigpio (both local and socket), Pi4j, wiringPi and one for the BBB based on BBBiolib. There is also a built in fallback implementation using sysfs / SMbus that can be easily ported to any Linux based SBC.

I have a work in progress provider that uses a Java native memory mapped ByteBuffer for high speed GPIO control that works on Pi as well as Odroid C2.

I'm gradually adding in support for more devices, recent ones include SSD1306 display, MCP EEPROMs and the MFRC522 rfid reader.

Give it a try and let me know how you get on. Feedback always welcome!

http://www.diozero.com

Matt
http://www.diozero.com/

Return to “Java”

Who is online

Users browsing this forum: No registered users and 4 guests