Weird errors from RTClib.h

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
iyeager
 
Posts: 12
Joined: Sat Oct 29, 2011 8:40 am

Weird errors from RTClib.h

Post by iyeager »

In my sketch I import the RTClib to use the DS1307 RTC. During compile I keep getting a load of errors from the RTClib.h file, undefined types, expected expressions before ;, etc...

Anyone got any ideas?

Code: Select all

#include <RTClib.h>
#include <SD.h>
#include <Wire.h>
#include <BMP085.h>

#define logInterval 2000;                           //Set the logging time in millis between logs
#define tempPin 3;                                  //The input pin that the thermistor will read on
BMP085 bmp;
int bmpTemp, bmpPress, tTemp, tCounter = 0;
int tempArray[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
volatile int bmpEOC = LOW;                          //Set up state for BMP085 EOC bit
volatile int startBit = LOW;                        //Set up state for 'start' button, set high here for no button start

void setup() {
  attachInterrupt(0, getI2C, RISING);               //Interrupt to read EOC bit
  attachInterrupt(1, start, RISING);                //Interrupt to read 'start' button press
  bmp.begin();                                      //Begin I2C communication as master
}

void loop() {
  if (bmpEOC == HIGH){
    get_bmpTemp_Press();                            //If conversion is done, get temp and pressure
  }
  tempArray[tCounter] = analogRead(tempPin) - 238;  //Get the thermistor temperature and add to array  
  tCounter++;                                       //Array count increased for thermistor averaging
  if (tCounter == 10){                        
    tTemp = average_tTemp(tempArray);               //Average every 10 samples
    tCounter = 0;                                   //...and reset the averageing counter
  }  
}

void getI2C() {
  bmpEOC = HIGH;                                    //Conversion is done, set bit high
}

void start() {
  startBit = HIGH;                                  //'Start' button has been pressed
}

void get_bmpTemp_Press() {
  bmpTemp = bmp.readTemperature();                  //Get temperature
  bmpPress = bmp.readPressure();                    //Get pressure
  bmpEOC = LOW;                                     //Reset conversion bit after reading I2C 
}

int average_tTemp (int array[10]){        
  int i, tempHolder = 0;
  for (i = 0; i < 11; i + 1){
    tempHolder += array[i];                         //Add all of the saved values in the array
  }
  return tempHolder/10;                             //...and divide by ten, returning a 10 sample running-average
}

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Weird errors from RTClib.h

Post by adafruit_support_bill »

Post the error messages

iyeager
 
Posts: 12
Joined: Sat Oct 29, 2011 8:40 am

Re: Weird errors from RTClib.h

Post by iyeager »

As follows;

In file included from bmp085.cpp:1:
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:7: error: expected `)' before 't'
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:8: error: expected `)' before 'year'
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:11: error: 'uint16_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:12: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:13: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:14: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:15: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:16: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:17: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:22: error: 'uint32_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:25: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:31: error: 'uint8_t' does not name a type
C:\Users\iyeager\Offline\Programming Stuffs Here\Arduino\arduino-0022\libraries\RTClib/RTClib.h:33: error: 'uint8_t' does not name a type
bmp085.cpp: In function 'void loop()':
bmp085:23: error: expected `)' before ';' token
bmp085:23: error: expected primary-expression before ')' token
bmp085:23: error: expected `;' before ')' token

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Weird errors from RTClib.h

Post by adafruit_support_bill »

Move your RTCLib include after the BMP085 include to fix most of the errors.

You also have a stray ';' in your define for 'tmpPin that causes problems further down.

iyeager
 
Posts: 12
Joined: Sat Oct 29, 2011 8:40 am

Re: Weird errors from RTClib.h

Post by iyeager »

Okay, so I get the ';'s screwing up everything below them, but why does it matter in what order you call your library's? Just wondering so I can pay attention to that stuff in the future and not have to bug the forums everytime I get it wrong.

-Ian

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Weird errors from RTClib.h

Post by adafruit_support_bill »

C++ is a 'one-pass' compiler. It needs to have everything defined before it is referenced.

In this case, RTCLib is dependent on definitions in the Wire.h include.

iyeager
 
Posts: 12
Joined: Sat Oct 29, 2011 8:40 am

Re: Weird errors from RTClib.h

Post by iyeager »

Is it possible that's what's causing these new errors as I'm adding more functionality to the program?

Code: Select all

#include <SD.h>
#include <Wire.h>
#include <BMP085.h>
#include <RTClib.h>

#define sensorAddr 40
#define logInterval 2000                                                //Set the logging time in millis between logs
#define tempPin 3                                                       //The input pin that the thermistor will read on
#define redLEDpin 11
#define greenLEDpin 12
#define sccAddress 40
BMP085 bmp;
RTC_DS1307 RTC;
File logfile;
const int chipSelect = 10;
int bmpTemp, bmpPress, tTemp, lPress, tCounter, pCounter, logTimer = 0;
float pressure = 0;
int tempArray[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int pressArray[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
volatile int bmpEOC = LOW;                                              //Set up state for BMP085 EOC bit
volatile int startBit = LOW;                                            //Set up state for 'start' button, set high here for no button start


void error (char *str){
  digitalWrite(redLEDpin, HIGH);
  while(1);
}

void setup() {
  attachInterrupt(0, getI2C, RISING);                                   //Interrupt to read EOC bit
  attachInterrupt(1, start, RISING);                                    //Interrupt to read 'start' button press
  bmp.begin();                                                          //Begin I2C communication as master
  pinMode(10, OUTPUT); 
  if (!SD.begin(chipSelect)) {
    return;
  }
  char filename[] = "LOGGER00.CSV";                                     //Create a file everytime startup occurs
  for (uint8_t i = 0; i < 100; i++) {                                   //...with a filename between LOGGER00 and LOGGER99
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (!SD.exists(filename)) {                                         //Don't create the file until a name 
      logfile = SD.open(filename, FILE_WRITE);                          //...is found that doesn't exist
      break;
    }
  }
  if (! logfile) {                                                      //Give an error if the logfile could not
    error("couldn't create file");                                      //be created.
    digitalWrite(redLEDpin, HIGH);
  }
  Wire.begin();      
  if (!RTC.begin()) {                                                   //If the RTC could not be communicated with
    logfile.println("RTC failed");                                      //...log the failure
    digitalWrite (redLEDpin, HIGH);                                     //...and light the error LED
  }
  logfile.println("Millis,Time,AmbPress,AmbTemp,LPress,LTemp");         //Attempt to write a header to the file
  if (logfile.writeError || !logfile.sync()) {                          //If the header file could not be written
    error("write header failure");                                      //...set an error code
    digitalWrite (redLEDpin, HIGH);                                     //...and light the error LED
  }
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
  logTimer = millis();
}


void loop() {
  if (bmpEOC == HIGH){
    get_bmpTemp_Press();                                                //If conversion is done, get temp and pressure
  }
  tempArray[tCounter] = analogRead(tempPin) - 238;                      //Get the thermistor temperature and add to array  
  tCounter++;                                                           //Array count increased for thermistor averaging
  if (tCounter == 10){                        
    tTemp = average_array(tempArray);                                   //Average every 10 samples
    tCounter = 0;                                                       //...and reset the averageing counter
  }
  
  if (millis()-logTimer == logInterval) {
    write_to_log(bmpPress, bmpTemp, lPress, tTemp);
  }
  
}

void getI2C() {
  bmpEOC = HIGH;                                                        //Conversion is done, set bit high
}

void start() {
  startBit = HIGH;                                                      //'Start' button has been pressed
}

void get_bmpTemp_Press() {
  bmpTemp = bmp.readTemperature();                                      //Get temperature
  bmpPress = bmp.readPressure();                                        //Get pressure
  bmpEOC = LOW;                                                         //Reset conversion bit after reading I2C 
}

int average_array (int array[10]){        
  int i, tempHolder = 0;
  for (i = 0; i < 11; i + 1){
    tempHolder += array[i];                                             //Add all of the saved values in the array
  }
  return tempHolder/10;                                                 //...and divide by ten, returning a 10 sample running-average
}

void get_SCC_data (byte *a, byte *b){
  Wire.requestFrom(sccAddress, 2);
  *a = Wire.recieve();
  *b = Wire.recieve();
}

int acquire_SCC_data (){
  byte aa, bb;
  boolean checkOk;
  int counts = 0;
  get_SCC_data(&aa, &bb);
  for (int i = 1; i < 3; i++){
    if(bitRead(aa, i) == 0){
    checkOk = true;
    }
  }
  if (checkOk == true){
    counts = aa + bb;
  }
  else {
    return 0;
  }
  pressure = (counts - 1638)/13107;
  return pressure;
}

void write_to_log (int aPress, int aTemp, int lPress, int lTemp) {
  DateTime now;
  digitalWrite(greenLEDpin, HIGH);                                      //Turn the green LED on
  uint32_t m = millis();                                                //Log millis since power-up
  logfile.print(m);                                                     
  logfile.print(", ");
  now = RTC.now();
  logfile.print(now.get());                                             //Log date and time in YY/MM/DD HH:MM:SS format
  logfile.print(", ");
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print(", ");
  logfile.print(aPress);                                                //Log the Ambient Pressure
  logfile.print(",");
  logfile.print(aTemp);                                                 //Log the Ambient Temperature
  logfile.print(",");
  logfile.print(lPress);                                                //Log the Line Pressure
  logfile.print(",");
  logfile.println(aTemp);                                               //Log the Line Temperature
  logTimer = millis();                                                    //Reset the log timer
  digitalWrite(greenLEDpin, LOW);                                       //...and turn the green LED on
}
And the list of errors I get now;

line_audit_case.cpp: In function 'void setup()':
line_audit_case:55: error: 'class File' has no member named 'writeError'
line_audit_case:55: error: 'class File' has no member named 'sync'
line_audit_case.cpp: In function 'void get_SCC_data(byte*, byte*)':
line_audit_case:106: error: 'class TwoWire' has no member named 'recieve'
line_audit_case:107: error: 'class TwoWire' has no member named 'recieve'
line_audit_case.cpp: In function 'void write_to_log(int, int, int, int)':
line_audit_case:137: error: 'class DateTime' has no member named 'get'

Thanks for any help,

-Ian

User avatar
luctussier
 
Posts: 5
Joined: Mon Oct 10, 2011 3:17 pm

RCTlib errors, really similar

Post by luctussier »

I had this problem too, but I don't understand really why.
RTClib.h:10: error: expected `)' before 't'
RTClib.h:11: error: expected `)' before 'year'
RTClib.h:14: error: 'uint16_t' does not name a type
RTClib.h:15: error: 'uint8_t' does not name a type
RTClib.h:16: error: 'uint8_t' does not name a type
RTClib.h:17: error: 'uint8_t' does not name a type
RTClib.h:18: error: 'uint8_t' does not name a type
RTClib.h:19: error: 'uint8_t' does not name a type
RTClib.h:20: error: 'uint8_t' does not name a type
RTClib.h:25: error: 'uint32_t' does not name a type
RTClib.h:28: error: 'uint8_t' does not name a type
RTClib.h:34: error: 'uint8_t' does not name a type
RTClib.h:36: error: 'uint8_t' does not name a type
This happens when I use the static method now() from the class without an instance.

Code: Select all

DateTime now = RTC_DS1307::now();
When I add the library inttiypes, the debung away, but I would like a solution that doesn't require me to manually add that library.

Code: Select all

#include <inttypes.h>
Any ideas or smart solutions?

User avatar
luctussier
 
Posts: 5
Joined: Mon Oct 10, 2011 3:17 pm

Re: Weird errors from RTClib.h

Post by luctussier »

pburgess also solved this with http://forums.adafruit.com/viewtopic.php?f=31&t=28583

Code: Select all

#include <Wire.h>
The library <Arduino.h>, also fixes the problem.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”