Error: expected primary-expression before "." token

Could someone please tell me what to put into this code to fix the errors? i have no knowledge or programming terms or anything, and i can't figure out what a primary expression is.

#include <LiquidCrystal.h>

#include <dht.h>

#include <LiquidCrystal.h>

// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"

// set the DHT Pin
#define DHTPIN8

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11 DHT dht (DHTPIN, DHTTYPE);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  dht begin();
  
  // Print a message to the LCD.
  lcd.print("Temp:  Humidity:");
}

void loop() {
  delay(500);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // read humidity
  float h = dht.readHumidity();
  //read temperature in Fahrenheit
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

  lcd.print(f);
  lcd.setCursor(7,1);
  lcd.print(h);  
}

/code]


Arduino: 1.6.11 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/shelbyreid/Downloads/sketch_aug26b/sketch_aug26b.ino: In function 'void loop()':
sketch_aug26b:33: error: expected primary-expression before '.' token
   float h = dht.readHumidity();
                ^
sketch_aug26b:35: error: expected primary-expression before '.' token
   float f = dht.readTemperature(true);
                ^
exit status 1
expected primary-expression before '.' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

First off, this should help you understand what the commands mean:

http://playground.arduino.cc/Main/DHTLib

It looks like you need to capitalize DHT. Arduino coding is case-sensitive, so that would effect whether or not it understands what you typed.

#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>

Maybe you need to include this library a few more times...

capitalizing didn't work, the error was <"DHT" not declared in this scope>

shelbykate19:
capitalizing didn't work, the error was <"DHT" not declared in this scope>

No, that was NOT the exact error message.

You included two files - dht.h and DHT.h. Only one of them actually exists. Get rid of the other one.

Once you have included the definition of the class (whether it is DHT or dht), you MUST create an instance of the class. YOU can determine whether the class name is dht or DHT by looking in the .h file that actually exists.

that isn't the problem I'm having though, that isn't what the program is giving me an error for.

Looking through all the Arduino website's examples, this is a consistent thing before the setup.

dht DHT;

Try replacing #include "DHT.h" with the line above.

Before we continue, are you using the standard one from Arduino or a dowloaded one from Github? The standard Arduino one uses

#include <dht.h>

if it is downloaded, look at the class documentation and examples provided on its github page for proper setup

And just to be sure, you capitalized the dth's in the loop and not in the #include? I should have been more specific, but I was referring to the ones in the loop should be capitalized.

that isn't the problem I'm having though

What isn't? You are trying to use a variable called dht that you have not defined. The way that the variable is being used indicates that it is supposed to be an instance of the dht or DHT class, whichever is correct.

For being dense, you get to tell us which file, dht.h or DHT.h you actually have, AND what the class line in that file looks like, BEFORE you can expect any more help.

Before we continue, are you using the standard one from Arduino or a dowloaded one from Github? The standard Arduino one uses

#include <dht.h>

i believe i am using a standard one arduino program. yes i did capitalize them in the loop, i thought that would work but it didn't :frowning:

I see some similarities with this.

You are missing the dot in dht.begin(); and #define DHTTYPE DHT11 DHT dht (DHTPIN, DHTTYPE); should be split in two lines

shelbykate19:
i believe i am using a standard one arduino program. yes i did capitalize them in the loop, i thought that would work but it didn't :frowning:

If you didn't download any separate library, then you're using the standard Arduino library.

This is what the beginning of your program should look like:

#include <LiquidCrystal.h>
#include <dht.h>
dht DHT;

void setup() {

You only need to include each library once, and you don't need to include "DHT.h"

The line dht DHT;, as I can only imagine, makes DHT a global variable, meaning it can be used anywhere in the code. Then, DHT will be recognized in the scope (meaning the variable can be used there) and it will be the primary expression. In theory, this should be the solution, or at least part of it. Just make sure you still have DHT capitalized in the loop.

It strikes me that you haven't got an entity called "dht", so "dht begin();" is nonsense, and "dht.readHumidity();" isn't going to do much good either.

sp. "condescension"

Gabriel_swe:
I see some similarities with this.
DHT-sensor-library/examples/DHTtester/DHTtester.ino at master · adafruit/DHT-sensor-library · GitHub

You are missing the dot in dht.begin(); and #define DHTTYPE DHT11 DHT dht (DHTPIN, DHTTYPE); should be split in two lines

Thats what i had before but they were giving me errors

shelbykate19:
Thats what i had before but they were giving me errors

But you are still using syntax specific to that library, like dht.readTemperature(true);

nunofyourbusiness:
The line dht DHT;, as I can only imagine, makes DHT a global variable, meaning it can be used anywhere in the code. Then, DHT will be recognized in the scope (meaning the variable can be used there) and it will be the primary expression. In theory, this should be the solution, or at least part of it. Just make sure you still have DHT capitalized in the loop.

thanks that fixed one part! it is now in the scope, although it still says expected primary expression

We can't see your code

#include "dht.h"

// include the library code:
#include <LiquidCrystal.h>

// set the DHT Pin
#define DHTPIN8

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11 DHT dht (DHTPIN, DHTTYPE);


#include <LiquidCrystal.h>
#include <dht.h>
dht DHT;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  DHT.begin();
  
  // Print a message to the LCD.
  lcd.print("Temp:  Humidity:");
}

void loop() {
  delay(500);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // read humidity
  float h = DHT.readHumidity();
  //read temperature in Fahrenheit
  float f = DHT.readTemperature(true);

  if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

  lcd.print(f);
  lcd.setCursor(7,1);
  lcd.print(h);  
}
/code]


Arduino: 1.6.11 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/shelbyreid/Downloads/sketch_aug26b/sketch_aug26b.ino: In function 'void setup()':
sketch_aug26b:21: error: 'class dht' has no member named 'begin'
   DHT.begin();
       ^
/Users/shelbyreid/Downloads/sketch_aug26b/sketch_aug26b.ino: In function 'void loop()':
sketch_aug26b:33: error: 'class dht' has no member named 'readHumidity'
   float h = DHT.readHumidity();
                 ^
sketch_aug26b:35: error: 'class dht' has no member named 'readTemperature'
   float f = DHT.readTemperature(true);
                 ^
exit status 1
'class dht' has no member named 'begin'

shelbykate19:

#include "dht.h"

// include the library code:
#include <LiquidCrystal.h>

// set the DHT Pin
#define DHTPIN8

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11 DHT dht (DHTPIN, DHTTYPE);

#include <LiquidCrystal.h>
#include <dht.h>
dht DHT;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  DHT.begin();
 
  // Print a message to the LCD.
  lcd.print("Temp:  Humidity:");
}

void loop() {
  delay(500);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // read humidity
  float h = DHT.readHumidity();
  //read temperature in Fahrenheit
  float f = DHT.readTemperature(true);

if (isnan(h) || isnan(f)) {
    lcd.print("ERROR");
    return;
  }

lcd.print(f);
  lcd.setCursor(7,1);
  lcd.print(h); 
}
/code]

Arduino: 1.6.11 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/shelbyreid/Downloads/sketch_aug26b/sketch_aug26b.ino: In function 'void setup()':
sketch_aug26b:21: error: 'class dht' has no member named 'begin'
  DHT.begin();
      ^
/Users/shelbyreid/Downloads/sketch_aug26b/sketch_aug26b.ino: In function 'void loop()':
sketch_aug26b:33: error: 'class dht' has no member named 'readHumidity'
  float h = DHT.readHumidity();
                ^
sketch_aug26b:35: error: 'class dht' has no member named 'readTemperature'
  float f = DHT.readTemperature(true);
                ^
exit status 1
'class dht' has no member named 'begin'

"sketch_aug26b:35: error: 'class dht' has no member named 'readTemperature'
float f = DHT.readTemperature(true);"

Now you no longer have reference to github dht library, but you still use syntax from it. Time to change to standard dht syntax. See here Arduino Playground - HomePage

Those errors mean that begin, readHumidity, and readTemperature are not in the standard library. However, it does mean that you have the library and the global variables set up.

What you have is you found code from a library that you don't have. This gives you 2 options.

  1. Try using code that is within the standard dht library.
  2. Download the library from where you found that code and use that library instead.