read temperature from DHT11, using pi4j

前端 未结 6 2095
甜味超标
甜味超标 2021-02-06 12:55

I\'m trying to read temperature data from a DHT11 temperature sensor, using pi4j. I followed the code written in c and python in this site: http://www.uugear.com/portfolio/dht11

6条回答
  •  野性不改
    2021-02-06 13:27

    I got a solution with Java Native Interface JNI and WiringPi.

    I am using java openjdk 7 in the raspberry pi. This is important to for support JNI capabilites of the JVM. I connected the DHT11 sensor to GPIO1 or pin 1.

    From the package root at src/main/java you can install the library. I prepared a script in that you can run with the command:

    sudo sh jniDHT11SensorReaderBuilder.sh

    Then to test if it works try to run the DHT11SensorReader class with the command

    sudo java org.mandfer.dht11.DHT11SensorReader

    If it is all fine and you want more values every 1.5 seconds try to run the exercise 20 from the project root folder.

    sh runPi.sh org.mandfer.sunfunpi4j.Ex20_DHT11_Native

    If you have any issue, leave me a comment.

    I hope it helps. Marc Andreu,

提交回复
热议问题