Hello everyone, I have recently built and a simple weather station and finally got it to work. As I was trying to tinker with the code a little bit in order to make it read the data from a DHT11 sensor at a 30 minute interval instead of without any delay for stability purposes, I've encountered an issue..
It returns this error whenever I try to verify the program:
exit status 1
expected unqualified-id before '.' token
and it highlights:
"lcd.print(dht.temperature, 1);"
Though, I believe all of my lcd.xxx lines have gone BAD.
I kept on trying to meddle with it to the extent of my abilities but to no end..
I'm really new to arduino, this is actually my first "complex" project so I don't have a lot of experience and I don't really know what I'm doing so any kind of information will prove useful to me.
Thank you very much for your time!
Components:
TinyRTC I2C
16x2 LCD
DHT11 Sensor
#include <LiquidCrystal.h>
#include <dht.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#define lcd LiquidCrystal
#define dht DHT
int DHT11_PIN = 2;
unsigned int DHTcheck = 0;
int RSPin = 6;
int EnablePin = 7;
int DS4 = 9;
int DS5 = 10;
int DS6 = 11;
int DS7 = 12;
int LCDColumns = 16;
int LCDRows = 2;
long LastCheck = 0;
const long interval = 1800000;
void setup ()
{
LiquidCrystal lcd(RSPin, EnablePin, DS4, DS5, DS6, DS7);
lcd.begin(LCDColumns, LCDRows); //Configure the LCD
setSyncProvider(RTC.get); //Declare RTC as time data source
}
void loop()
{
digitalClockDisplay();
DHTsensor();
}
void digitalClockDisplay () {
lcd.setCursor(0, 0);
lcd.print(hour());
lcd.print(":");
lcd.print(minute());
lcd.setCursor(6, 0);
lcd.print(day());
lcd.print(".");
lcd.print(month());
lcd.print(".");
lcd.print(year());
}
void DHTsensor () {
unsigned long CurrentTime = millis();
if (CurrentTime - LastCheck >= interval) {
LastCheck = CurrentTime;
DHTcheck = DHT.read11(DHT11_PIN);
}
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.print(DHT.humidity, 1);
lcd.setCursor(9, 1);
lcd.print("T:");
lcd.print(dht.temperature, 1);
}
That's what you get for naming a class instantiation after the class name:
lcd.print(DHT.humidity, 1);
lcd.setCursor(9, 1);
lcd.print("T:");
lcd.print(dht.temperature, 1);
See how one is upper case and the other isn't? Pick a decent name like "tempSensor" or something for your sensor object and this won't happen again.
Wow! That was fast. Thank you.
}
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.print(DHT.humidity, 1);
lcd.setCursor(9, 1);
lcd.print("T:");
lcd.print(DHT.temperature, 1);
}
Though you were totally right and I was totally blind, I swapped dht with DHT and i still seem to get the same error..
Where are the delay()'s you mention? Did you post the right code?
I'm sorry for misleading you, there are no delays present as I tought they would somehow interfere with my RTC as it has no 3v battery for now, so I tried using millis() for the first time.
ReRenamed it.
Edit: Still the same error.
#include <LiquidCrystal.h>
#include <dht.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#define lcd LiquidCrystal
#define Sensor DHT
int DHT11_PIN = 2;
unsigned int DHTcheck = 0;
int RSPin = 6;
int EnablePin = 7;
int DS4 = 9;
int DS5 = 10;
int DS6 = 11;
int DS7 = 12;
int LCDColumns = 16;
int LCDRows = 2;
long LastCheck = 0;
const long interval = 1800000;
void setup ()
{
LiquidCrystal lcd(RSPin, EnablePin, DS4, DS5, DS6, DS7);
lcd.begin(LCDColumns, LCDRows); //Configure the LCD
setSyncProvider(RTC.get); //Declare RTC as time data source
}
void loop()
{
digitalClockDisplay();
DHTsensor();
}
void digitalClockDisplay () {
lcd.setCursor(0, 0);
lcd.print(hour());
lcd.print(":");
lcd.print(minute());
lcd.setCursor(6, 0);
lcd.print(day());
lcd.print(".");
lcd.print(month());
lcd.print(".");
lcd.print(year());
}
void DHTsensor () {
unsigned long CurrentTime = millis();
if (CurrentTime - LastCheck >= interval) {
LastCheck = CurrentTime;
DHTcheck = Sensor.read11(DHT11_PIN);
}
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.print(Sensor.humidity, 1);
lcd.setCursor(9, 1);
lcd.print("T:");
lcd.print(Sensor.temperature, 1);
}
This should not be in setup()
LiquidCrystal lcd(RSPin, EnablePin, DS4, DS5, DS6, DS7);
Also I see no attempt to create a dht object.
I played with the code a little bit (I don't know if I've actually changed anything..) and I still get the same error, also I don't really think I know what you mean by defining an DHT object? Including and using the lib and setting the pin is not enough for proper functioning?
#include <SimpleDHT.h>
#include <LiquidCrystal.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#define screen LiquidCrystal
#define sensor SimpleDHT11
int DHT11_PIN = 2;
unsigned int DHTcheck = 0;
int RSPin = 6;
int EnablePin = 7;
int DS4 = 9;
int DS5 = 10;
int DS6 = 11;
int DS7 = 12;
int LCDColumns = 16;
int LCDRows = 2;
LiquidCrystal screen(RSPin, EnablePin, DS4, DS5, DS6, DS7);
long LastCheck = 0;
const long interval = 1800000;
void setup ()
{
screen.begin(LCDColumns, LCDRows); //Configure the LCD
setSyncProvider(RTC.get); //Declare RTC as time data source
}
void loop()
{
digitalClockDisplay();
DHTsensor();
}
void digitalClockDisplay () {
screen.setCursor(0, 0);
screen.print(hour());
screen.print(":");
screen.print(minute());
screen.setCursor(6, 0);
screen.print(day());
screen.print(".");
screen.print(month());
screen.print(".");
screen.print(year());
}
void DHTsensor () {
unsigned long CurrentTime = millis();
if (CurrentTime - LastCheck >= interval) {
LastCheck = CurrentTime;
DHTcheck = sensor.read11(DHT11_PIN);
}
screen.setCursor(0, 1);
screen.print("H:");
screen.print(sensor.humidity, 1);
screen.setCursor(9, 1);
screen.print("T:");
screen.print(sensor.temperature, 1);
}
May I ask, what is this line supposed to do?
#define sensor SimpleDHT11
...and suddenly you've switched libraries, without any comment on the subject? 
To see how a sensor object is defined (it is an instantiation of a class), see the example sketches that come with the library.
I want to thank everyone for the time invested in this thread, you've been nice, fast and helpful and I'm really glad that I decided to use the forum.
I redid most of the code and I think the biggest problem I had was not declaring DHT object properly.
Everything seems to work fine for now.
[#include <dht.h>
#include <LiquidCrystal.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#define lcd LiquidCrystal
dht DHT;
int DHT11_PIN = 2;
int RSPin = 6;
int EnablePin = 7;
int DS4 = 9;
int DS5 = 10;
int DS6 = 11;
int DS7 = 12;
int LCDColumns = 16;
int LCDRows = 2;
LiquidCrystal lcd(RSPin, EnablePin, DS4, DS5, DS6, DS7);
long interval = 3600000;
long LastCheck =0;
void setup ()
{
lcd.begin(LCDColumns, LCDRows); //Configure the LCD
setSyncProvider(RTC.get); //Declare RTC as time data source
}
void loop()
{
digitalClockDisplay();
DHTsensor();
}
void digitalClockDisplay () {
lcd.setCursor(0, 0);
lcd.print(hour());
lcd.print(":");
lcd.print(minute());
lcd.setCursor(6, 0);
lcd.print(day());
lcd.print(".");
lcd.print(month());
lcd.print(".");
lcd.print(year());
}
void DHTsensor () {
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.setCursor(9, 1);
lcd.print("T:");
int Sensor = DHT.read11(DHT11_PIN);
unsigned long CurrentTime = millis();
if (CurrentTime - LastCheck >= interval) {
LastCheck = CurrentTime;
lcd.setCursor(2,1);
lcd.print(DHT.humidity, 1);
lcd.setCursor(11,1);
lcd.print(DHT.temperature, 1);
}
}