What is LibPins?

Skip to first unread message

Chris Wolcott

Jul 8, 2020, 11:46:25 AM7/8/20
to Pi4J
I'm trying a program to read a DHT11 sensor.  In the code, they make use a method called LibPins.getPin(), but I can find NO reference to such an object.  What is it, and what do I replace it in this code with?

import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.pi4j.component.ObserveableComponentBase;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalMultipurpose;
import com.pi4j.io.gpio.Pin;
import com.pi4j.io.gpio.PinMode;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

public class DHT11 extends ObserveableComponentBase {

    public DHT11(int pin) {
        final GpioController gpio = GpioFactory.getInstance();
        dht11Pin = gpio.provisionDigitalMultipurposePin(LibPins.getPin(pin), PinMode.DIGITAL_INPUT, PinPullResistance.PULL_UP);


Frank Delporte

Jul 8, 2020, 2:25:39 PM7/8/20
to Pi4J
I found LibPins on GitHub

It seems to extend the RaspiPin of Pi4J.

gpioPins = new HashMap<Integer, Pin>();
gpioPins.put(1, RaspiPin.GPIO_01);
gpioPins.put(2, RaspiPin.GPIO_02)

So if you just replace it with the pin you want to use in your code, e.g. RaspiPin.GPIO_02


Chris Wolcott

Jul 8, 2020, 7:59:41 PM7/8/20
to Pi4J
Thanks for your response.  

I changed the offending line to:   DHT11Pin = gpio.provisionDigitalMultipurposePin(RaspiPin.getPinByAddress(pin), PinMode.DIGITAL_INPUT,PinPullResistance.PULL_UP);

Not sure if that is an effective replacement as I don't use that constructor, but it was a 'Best Guess' at the time.

Jim Darby

Jul 9, 2020, 12:57:41 AM7/9/20
to pi...@googlegroups.com

Hi Chris,

One of the issues with the DHT11 is its fussy timing requirements. You can use the checksum in the message block and retry but it's still a pain.

There are two solutions I can recommend.

The first is to use the kernel drivers on the Pi and read the data using that. None of that tedious GPIO mucking about, just open a file and read the data.

Option 2 is to use one of the mroe modern replacements. The DHT22 is not only more accurate but the variants of it come with I2C interfaces which make it a far easier experience to work with.

Hope this helps.


You received this message because you are subscribed to the Google Groups "Pi4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pi4j+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pi4j/51b2320d-f192-445e-9d46-bad2321ab8cfo%40googlegroups.com.
Reply all
Reply to author
0 new messages