Arduino Code Fehler aber was ist falsch ?

OP #4791715
Lesenswert?
• ▲
▼
Hallo
Ich versuche seit Donnerstag dem arduino das laufen mit 2 verschindende 
Sensoren auf zudrucken.
Nur irgend wo ist noch ein Fehler der das auf spielen unterbindet.
Ich habe alle sensoren angeben.
Ich habe alle pins fest gelegt.
Habe es mit andern vorlagen verglichen nix.


#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#define DHTPIN = 10; //Am2301
#define OneWire  ds(2); // ds18B20

DeviceAddress sensor1 = { 0x28, 0xFF, 0x86, 0x2E,  0x74, 0x16, 0x3, 0xAF 
};
DeviceAddress sensor2 = { 0x28, 0xFF, 0x5, 0x72, 0x74, 0x16, 0x3, 0xE0 
};
DeviceAddress sensor3 = { 0x28, 0xFF, 0x2B, 0x3F, 0x73, 0x16, 0x5, 0x60 
};
DeviceAddress sensor4 = { 0x28, 0xFF, 0xC5, 0x11, 0x73, 0x16, 0x5, 0x7D 
};
DeviceAddress sensor5 = { 0x28, 0xFF, 0xC, 0x68, 0x74, 0x16, 0x3, 0x30 
};


char sensor1Name[] = "Temp1: ";
char sensor2Name[] = "Temp2: ";
char sensor3Name[] = "Temp3: ";
char sensor4Name[] = "Temp4: ";
char sensor5Name[] = "Temp5: ";

void setup(void)
{
  Serial.begin(9600);
  dht.begin();
}

void writeTimeToScratchpad(byte* address)
{
   ds.reset();
   ds.select(address);
  scratchpad
  ds.write(0x44,1);
   delay(2500);
}

void readTimeFromScratchpad(byte* address, byte* data)
{
    ds.reset();
    ds.select(address);
    ds.write(0xBE);
  for (byte i=0;i<9;i++){
    data[i] = ds.read();
  }
}

float getTemperature(byte* address)
{
int tr;
byte data[12];

writeTimeToScratchpad(address);

readTimeFromScratchpad(address,data);

//put in temp all the 8 bits of LSB (least significant byte)
tr = data[0];

if (address[0] == 0x10) // DS18S20
{
//check for negative temperature
if (data[1] > 0x80)
{
tr = !tr + 1; //two’s complement adjustment
tr = tr * -1; //flip value negative.
}

//drop bit 0
tr = tr >> 1;

//COUNT PER Celsius degree (10h)
int cpc = data[7];
//COUNT REMAIN (0Ch)
int cr = data[6];

return tr - (float)0.25 + (cpc - cr)/(float)cpc;
}
else // DS18B20
{
return ((data[1] << 8) + tr) * (float)0.0625;
}
}

void loop(void)
{
  float temp1 = getTemperature(sensor1);
  float temp2 = getTemperature(sensor2);
  float temp3 = getTemperature(sensor3);
  float temp4 = getTemperature(sensor4);
  float temp5 = getTemperature(sensor5);

  Serial.print(sensor1Name);
  Serial.print(temp1);
  Serial.println(" C");
  Serial.print(sensor2Name);
  Serial.print(temp2);
  Serial.println(" C");
  Serial.print(sensor3Name);
  Serial.print(temp3);
  Serial.println(" C");
  Serial.print(sensor4Name);
  Serial.print(temp4);
  Serial.println(" C");
  Serial.print(sensor5Name);
  Serial.print(temp5);
  Serial.println(" C");
   delay(2000);

  float h = dht.readHumidity();

  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }


  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
}

Fehlermeldung ist diesen hier:
ES läuft immer wieder auf das >ds< raus was ich aber mit Pin 2 oben 
verbunden habe.
------------------------------------------------------------------------ 
-
In function 'void setup()':

error: 'dht' was not declared in this scope

   dht.begin();

   ^

In function 'void writeTimeToScratchpad(byte*)':

 error: 'ds' was not declared in this scope

   ds.reset();

   ^

In function 'void readTimeFromScratchpad(byte*, byte*)':

error: 'ds' was not declared in this scope

   ds.reset();

   ^

In function 'void loop()':

error: 'dht' was not declared in this scope

   float h = dht.readHumidity();

             ^

error: 'f' was not declared in this scope

   if (isnan(h) || isnan(t) || isnan(f)) {

                                     ^

error: 'f' was not declared in this scope

   float hif = dht.computeHeatIndex(f, h);

                                    ^

exit status 1
'dht' was not declared in this scope


Ware SUPER wenn mir einer Hilfe Stellung geben kann.
Vielen DANK.
Gast #4791729
Lesenswert?
• ▲
▼
DAVID -. schrieb:
> In function 'void setup()':
>
> error: 'dht' was not declared in this scope
>
>    dht.begin();

Da steht doch, wo das Problem liegt:

Du sagst dem Compiler, er möge die Methode begin() des Objektes dht 
ausführen. Der Compiler weiss aber gar nicht, was für ein Objekt dht 
ist, da Du es nicht deklariert hast.
#4791731
Lesenswert?
• ▲
▼
ein Blick in das example (das wohl jeder arduino lib beiliegt) offenbart 
folgendes
1
// Initialize DHT sensor.
2
// Note that older versions of this library took an optional third parameter to
3
// tweak the timings for faster processors.  This parameter is no longer needed
4
// as the current DHT reading algorithm adjusts itself to work on faster procs.
5
DHT dht(DHTPIN, DHTTYPE);
OP #4791758
Lesenswert?
• ▲
▼
Ich habe die letzten tage damit zugebracht ist also NICHT gelogen ich 
habe beispiele vom Programm aber auch von Webseiten versucht.
Habe sogar in einer Verzweiflungstat alle verweise mal angefugt aber 
selbst damit gehts nicht.

#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#include "dht.h"
#define OneWire  ds(10);
#define DHT.PIN (2):
#define DHTTYPE.DHT21;
#define DHT dht(DHTPIN, DHTTYPE);

Die beispiele einzeln laufen zusammen aber nicht mehr.

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.