From e0da8dc2761aaecac321b0eda7823e3355727a98 Mon Sep 17 00:00:00 2001 From: Daniel Ledda Date: Sat, 31 Oct 2020 16:40:23 +0100 Subject: [PATCH] finding a bug --- main.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 862e941..d0f6f67 100644 --- a/main.go +++ b/main.go @@ -2,11 +2,10 @@ package main import ( "fmt" - "errors" "github.com/warthog618/gpio" "math" - "time" "strconv" + "time" ) const Timeout = math.MaxInt32 @@ -62,16 +61,18 @@ func readDataFromDHT(pin *gpio.Pin) ([5]byte, error) { pin.Low() pin.Output() time.Sleep(1100 * time.Microsecond) - pin.PullUp() + pin.High() + time.Sleep(40 * time.Microsecond) pin.Input() - time.Sleep(20 * time.Microsecond) + time.Sleep(80 * time.Microsecond) + time.Sleep(80 * time.Microsecond) // Wait for low high signal - if cyclesForReading(pin, gpio.Low) == Timeout { - return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "low")) - } - if cyclesForReading(pin, gpio.High) == Timeout { - return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "high")) - } + //if cyclesForReading(pin, gpio.Low) == Timeout { + // return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "low")) + //} + //if cyclesForReading(pin, gpio.High) == Timeout { + // return [5]byte{}, errors.New(fmt.Sprintf(TimeoutErrInitial, "high")) + //} pulsesAsCycles := readPulsesAsCycles(pin) receivedInput, err := storeCycleCountsAsBinarySequence(&pulsesAsCycles) if err != nil {