Git Product home page Git Product logo

Comments (7)

Dalvany avatar Dalvany commented on August 15, 2024 2

I read the diff between versions and came accross this bce0dc9#diff-a9f55f7fcb9cb447f152c9128faea88fL166

    // !!! Found in experimental way, that additional pause should exist
    // between export pin to work with and direction set up. Otherwise,
    // under the regular user mistake occures frequently !!!
    //
    // Sleep 150 milliseconds
    // sleep_usec(150*1000);

Uncommenting this sleep_usec fix the issue as stated in the comment.

from go-dht.

d2r2 avatar d2r2 commented on August 15, 2024 1

Hi @hyzhak. Nice to hear that you found workaround! It is curious that without sudo it doesn't work...
Suppose, https://github.com/adafruit/Adafruit_Python_DHT works, because, I guess, it use another approach (/dev/mem), but here I employ GPIO.

I can't recall why I did not face with this problem, but probably this can help: https://stackoverflow.com/questions/30938991/access-gpio-sys-class-gpio-as-non-root

from go-dht.

Dalvany avatar Dalvany commented on August 15, 2024 1

Hello, I got the same error and sudo seems to 'fix'. I dig a little more and find that the commit adding support for DHT12 introduce this behavior
Here is a go.mod that works :

module dht

go 1.13

require (
        github.com/d2r2/go-dht v0.0.0-20181222061613-42fe873fbabb
        github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e // indirect
        github.com/d2r2/go-shell v0.0.0-20190508080434-6fd313082bbf // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
)

With the following one, I got the failed to open pin X direction for writing error :

module dht

go 1.13

require (
        github.com/d2r2/go-dht v0.0.0-20190315195559-bce0dc951e46
        github.com/d2r2/go-logger v0.0.0-20181221090742-9998a510495e // indirect
        github.com/d2r2/go-shell v0.0.0-20190508080434-6fd313082bbf // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
)

from go-dht.

ezplanet avatar ezplanet commented on August 15, 2024 1

I have the same problem, but 'sudo' does not solve it:

I get the following on pin 29:
2023-07-04T15:56:12.905 [ dht] WARN Error during call C.dial_DHTxx_and_read(): failed to export pin 29

and on pin 35:
2023-07-04T15:48:14.201 [ dht] WARN Error during call C.dial_DHTxx_and_read(): failed to open pin 35 direction for writing

Using iono Pi max with Rpi 3 CM Lite

Needless to mention that all good with Adafruit python library.

from go-dht.

hyzhak avatar hyzhak commented on August 15, 2024

hm, sudo solved that problem:

sudo ./main

from go-dht.

hyzhak avatar hyzhak commented on August 15, 2024

oh! great it is very helpful, I'd try to avoid sudo as much as possible :)

from go-dht.

Merlinux-source avatar Merlinux-source commented on August 15, 2024

got the same issue, it doesn't work with sudo

pflanze@pflanzen:~/read_dht22 $ go build
pflanze@pflanzen:~/read_dht22 $ ./main 
2024-05-07T04:44:11.329 [    main] NOTICE  ***************************************************************************************************
2024-05-07T04:44:11.329 [    main] NOTICE  *** You can change verbosity of output, to modify logging level of module "dht"
2024-05-07T04:44:11.329 [    main] NOTICE  *** Uncomment/comment corresponding lines with call to ChangePackageLogLevel(...)
2024-05-07T04:44:11.329 [    main] NOTICE  ***************************************************************************************************
2024-05-07T04:44:11.330 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:12.831 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:14.332 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:15.833 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:17.334 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:18.835 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:20.336 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:21.838 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:23.339 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:24.840 [     dht] WARN  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
2024-05-07T04:44:26.341 [    main] FATAL  Error during call C.dial_DHTxx_and_read(): failed to export pin 2
pflanze@pflanzen:~/read_dht22 $ cat main.go 
package main
import (
        "github.com/d2r2/go-dht"
        logger "github.com/d2r2/go-logger"
)

var lg = logger.NewPackageLogger("main",
        logger.DebugLevel,
        // logger.InfoLevel,
)

func main() {
        defer logger.FinalizeLogger()

        lg.Notify("***************************************************************************************************")
        lg.Notify("*** You can change verbosity of output, to modify logging level of module \"dht\"")
        lg.Notify("*** Uncomment/comment corresponding lines with call to ChangePackageLogLevel(...)")
        lg.Notify("***************************************************************************************************")
        // Uncomment/comment next line to suppress/increase verbosity of output
        logger.ChangePackageLogLevel("dht", logger.InfoLevel)

        // sensorType := dht.DHT11
        sensorType := dht.AM2302
        // sensorType := dht.DHT12
        // Read DHT11 sensor data from specific pin, retrying 10 times in case of failure.
        pin := 2
        temperature, humidity, retried, err :=
                dht.ReadDHTxxWithRetry(sensorType, pin, false, 10)
        if err != nil {
                lg.Fatal(err)
        }
        // print temperature and humidity
        lg.Infof("Sensor = %v: Temperature = %v*C, Humidity = %v%% (retried %d times)",
                sensorType, temperature, humidity, retried)
}
pflanze@pflanzen:~/read_dht22 $ cat /proc/version 
Linux version 6.6.28+rpt-rpi-v8 ([email protected]) (gcc-12 (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40) #1 SMP PREEMPT Debian 1:6.6.28-1+rpt1 (2024-04-22)

is this project abandoned?

from go-dht.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.