DHT11 - Adafruit - liefert falsche Werte

L I V E Stammtisch ab 20:30 Uhr im Chat
  • Hallo liebe Community!

    Ich bin gerade dabei eine überwachten Pflanzenanzuchtkasten zu bauen.
    Hab jetzt alles soweit eingebaut und mit den Tests begonnen. Der Anzuchtkasten hat im inneren einen Sensor(DHT11) und einen weiteren Sensor außen auf der Kiste(DHT11).
    Der innen Sensor funktioniert einwandfrei und liefert brauchbare Werte.

    Problem ist der außen Sensor - hier bekomme ich immer falsche Werte zurück. Sprich der Sensor liefert immer Werte ca. 10° Grad und um die 145% Luftfeuchtigkeit.

    Folgendes hab ich schon getestet:
    - Die beiden Sensoren getauscht - Fehler bleibt - der Sensor(außen) funktioniert mit der Verkabelung vom innen Sensor und der innen Sensor funktioniert mit der Verkabelung vom außen Sensor nicht
    - Weiters hab ich vom Breadboard ein neues Kabel zum Sensor gelegt - Gleich "falsche" Werte.

    Zum Auslesen der Werte verwende ich Adafruit_DHT11.
    Hat jemand von euch eine Idee was da falsch sein könnte? Kann es ein Timing Problem bei der Abfrage der Werte sein? Die Leitung vom Bradoard(Raspi) bis zum Sensor sind ca. 3m.

    Danke für Eure Unterstützugn.

    lg
    Thomas

  • Hallo,

    wie schon Anfangs geschrieben habe ich die Verkabelung bereits getauscht. Der Sensor funktioniert wenn man ihn direkt am Breadboard ansteckt. Verwende ich ein Kabel ca. 3m bekomme ich verfälschte Werte.
    Die Werte werden mit AdafruitDHT.py ausgelesen. Das ist ein Python Script aus der Adafruit Repository.

    >> sudo ./AdafruitDHT.py 11 4

    in diesem Python Script wird das C-Script pi_dht_read.c Script mit folgendem Inhalt aufgerufen.

    // Copyright (c) 2014 Adafruit Industries
    // Author: Tony DiCola

    // Permission is hereby granted, free of charge, to any person obtaining a copy
    // of this software and associated documentation files (the "Software"), to deal
    // in the Software without restriction, including without limitation the rights
    // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    // copies of the Software, and to permit persons to whom the Software is
    // furnished to do so, subject to the following conditions:

    // The above copyright notice and this permission notice shall be included in all
    // copies or substantial portions of the Software.

    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    // SOFTWARE.
    #include <stdbool.h>
    #include <stdlib.h>

    #include "pi_dht_read.h"
    #include "pi_mmio.h"

    // This is the only processor specific magic value, the maximum amount of time to
    // spin in a loop before bailing out and considering the read a timeout. This should
    // be a high value, but if you're running on a much faster platform than a Raspberry
    // Pi or Beaglebone Black then it might need to be increased.
    #define DHT_MAXCOUNT 32000

    // Number of bit pulses to expect from the DHT. Note that this is 41 because
    // the first pulse is a constant 50 microsecond pulse, with 40 pulses to represent
    // the data afterwards.
    #define DHT_PULSES 41

    int pi_dht_read(int type, int pin, float* humidity, float* temperature) {
    // Validate humidity and temperature arguments and set them to zero.
    if (humidity == NULL || temperature == NULL) {
    return DHT_ERROR_ARGUMENT;
    }
    *temperature = 0.0f;
    *humidity = 0.0f;

    // Initialize GPIO library.
    if (pi_mmio_init() < 0) {
    return DHT_ERROR_GPIO;
    }

    // Store the count that each DHT bit pulse is low and high.
    // Make sure array is initialized to start at zero.
    int pulseCounts[DHT_PULSES*2] = {0};

    // Set pin to output.
    pi_mmio_set_output(pin);

    // Bump up process priority and change scheduler to try to try to make process more 'real time'.
    set_max_priority();

    // Set pin high for ~500 milliseconds.
    pi_mmio_set_high(pin);
    sleep_milliseconds(500);

    // The next calls are timing critical and care should be taken
    // to ensure no unnecssary work is done below.

    // Set pin low for ~20 milliseconds.
    pi_mmio_set_low(pin);
    busy_wait_milliseconds(20);

    // Set pin at input.
    pi_mmio_set_input(pin);
    // Need a very short delay before reading pins or else value is sometimes still low.
    for (volatile int i = 0; i < 50; ++i) {
    }

    // Wait for DHT to pull pin low.
    uint32_t count = 0;
    while (pi_mmio_input(pin)) {
    if (++count >= DHT_MAXCOUNT) {
    // Timeout waiting for response.
    set_default_priority();
    return DHT_ERROR_TIMEOUT;
    }
    }

    // Record pulse widths for the expected result bits.
    for (int i=0; i < DHT_PULSES*2; i+=2) {
    // Count how long pin is low and store in pulseCounts[i]
    while (!pi_mmio_input(pin)) {
    if (++pulseCounts[i] >= DHT_MAXCOUNT) {
    // Timeout waiting for response.
    set_default_priority();
    return DHT_ERROR_TIMEOUT;
    }
    }
    // Count how long pin is high and store in pulseCounts[i+1]
    while (pi_mmio_input(pin)) {
    if (++pulseCounts[i+1] >= DHT_MAXCOUNT) {
    // Timeout waiting for response.
    set_default_priority();
    return DHT_ERROR_TIMEOUT;
    }
    }
    }

    // Done with timing critical code, now interpret the results.

    // Drop back to normal priority.
    set_default_priority();

    // Compute the average low pulse width to use as a 50 microsecond reference threshold.
    // Ignore the first two readings because they are a constant 80 microsecond pulse.
    uint32_t threshold = 0;
    for (int i=2; i < DHT_PULSES*2; i+=2) {
    threshold += pulseCounts[i];
    }
    threshold /= DHT_PULSES-1;

    // Interpret each high pulse as a 0 or 1 by comparing it to the 50us reference.
    // If the count is less than 50us it must be a ~28us 0 pulse, and if it's higher
    // then it must be a ~70us 1 pulse.
    uint8_t data[5] = {0};
    for (int i=3; i < DHT_PULSES*2; i+=2) {
    int index = (i-3)/16;
    data[index] <<= 1;
    if (pulseCounts[i] >= threshold) {
    // One bit for long pulse.
    data[index] |= 1;
    }
    // Else zero bit for short pulse.
    }

    // Useful debug info:
    //printf("Data: 0x%x 0x%x 0x%x 0x%x 0x%x\n", data[0], data[1], data[2], data[3], data[4]);

    // Verify checksum of received data.
    if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) {
    if (type == DHT11) {
    // Get humidity and temp for DHT11 sensor.
    *humidity = (float)data[0];
    *temperature = (float)data[2];
    }
    else if (type == DHT22) {
    // Calculate humidity and temp for DHT22 sensor.
    *humidity = (data[0] * 256 + data[1]) / 10.0f;
    *temperature = ((data[2] & 0x7F) * 256 + data[3]) / 10.0f;
    if (data[2] & 0x80) {
    *temperature *= -1.0f;
    }
    }
    return DHT_SUCCESS;
    }
    else {
    return DHT_ERROR_CHECKSUM;
    }
    }

  • was meinst du mit Codeansicht? den Code samt den Einrückungen?
    jap es funktionieren beide gleichzeitig am Breadboard, bzw. beide Sensoren sind mit einem Kabel mit dem Breadboard verbunden.
    Spannung ist +5V - auf beiden Sensoren gleich

  • naja nachdem der Sensor funktioniert wenn ich ihn direkt auf das Breadboard stecke ist es eher unwahrscheinlich das der PIN schuld ist oder?
    ich habs aber ehrlichgesagt noch nicht probiert... ich werd das am We mal testen.
    Das es sich um ein Timing-Problem handelt glaubst du nicht?


  • was meinst du mit Codeansicht?


    Du kannst hier im Forum Code zwischen Codetags setzten: [+code+]Code[+/code+] (Pluszeichen weglassen)
    Wenn beide DHT11 gleichzeitig, also nicht nacheinander ausprobiert, sondern nur mit kurzem Kabel, am Breadboard funktionieren, kann es nicht der GPIO sein. Bleibt eigentlich nur die Verkabelung. Das Kabel schon mal durchgemessen?

  • Ok - ich stell den Code am Abend nochmal richtig rein.
    Naja genau aus dem Grund dachte ich das es vielleicht ein Timing Problem beim auslesen der Werte ist.
    Ich hab ja das bestehende Kabel gegen ein neues ausgetauscht - brachte keine Verbesserung.
    Ich hab mit dem Prüfgerät das Kabel durchgemessen da ich vermutet habe das eine Lize kaputt ist - sind aber alle Ok.

  • Das zweite Kabel mit dem ich getestet habe war ein anderes (dickeres) wie das fix installierte. Hab allerdings keine Ahnung für wieviel Volt das Kabel ausgelegt ist.
    Ich habe bei beiden Sensoren das gleiche Kabel verwendet, und bei einem funktionierts - denke das sollte nicht as Problem sein.
    Kann man das Messen wieviel Volt ein Kabel supportet?

  • jap sind beide am Breadboard mit +5V gesteckt! Auf dem 3V Pin hab ich zwei StromRelais hängen.

    Ich werd am We mal ein Kabel mit einem dickeren Durchschnitt tesetn und weiters einen anderen GPIO Pin.
    Da es anscheinend niemanden gibt der glaubt das das Problem vom Script bzw. dem Timing beim Auslesen verursacht wird - kann es ja nur ein installations Problem sein...

  • Mit welchen zeitlichen Abständen hast du denn gemessen? Der DHT11 ist nämlich sehr langsam. Ansonsten kannst du ja auch mal andere Software versuchen.

    Code
    git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code
    cd ./Adafruit-Raspberry-Pi-Python-Code
    cd ./Adafruit_DHT_Driver
    make
    sudo ./Adafruit_DHT 11 4

    Einmal editiert, zuletzt von kes (14. Oktober 2014 um 19:19)

  • Wie anfangs schon beschrieben verwende ich genau diesen Code(Software) zum Auslesen der Werte.
    Zeitliche Abstände hab ich mehrere probiert - zum Schluss hab ich dann den innenSensor der funktioniert abgeschloßen und nur den außen Sensor angeschlossen. Leider auf kein Erfolg.

    Gibt es irgendwelche Testtools mit dem man das Kabel bzw. die Verbindung testen kann?

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!