Comments (7)
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.
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.
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.
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.
hm, sudo solved that problem:
sudo ./main
from go-dht.
oh! great it is very helpful, I'd try to avoid sudo as much as possible :)
from go-dht.
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)
- The driver would suddenly fatally exit after ten or more hours. HOT 5
- Installation failure on macOS HOT 16
- Code fails on RPI-Zero but not on RPI-3 HOT 1
- On app termination long output of "2018/10/01 11:18:47 Signal received, cancel context" messages HOT 1
- Golang compiler warnings for functions HOT 6
- golint warnings HOT 1
- Beaglebone question HOT 5
- cross compilations techniques compile error HOT 1
- Cross compilation is not working in macOS for raspberry HOT 2
- Can't compile if set env for raspberry pi
- Ubuntu Server 20.04.1 on Raspberry Pi 3B V2.1: "NewDHT error: pin out high error: sysfs-gpio (GPIO17): sysfs gpio is not initialized" HOT 2
- AM2301 support? HOT 3
- pins could be 4 characters on 64bit RPIs
- DHT11 Compatibility HOT 2
- fix compiler warnings HOT 2
- RPI Zero-W using pin 5.. HOT 6
- ./dht.go.h:73:23: error: unknown type name 'int32_t' HOT 1
- Decimal part of the temperature / humidity value for the DHT11 HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-dht.