No such file or directory

Back in 2018, this sketch worked. I disconnected the device and put it in the closet. Now trying to use it again forget how all this works. But right off the bat I get this error message when trying to verify the skech.

In file included from C:\Users\User\Documents\Arduino\light-and-temp-logger_2_min\light-and-temp-logger_2_min.ino:4:0:
c:\Users\User\Documents\Arduino\libraries\RTClib\src/RTClib.h:25:10: fatal error: Adafruit_I2CDevice.h: No such file or directory
 #include <Adafruit_I2CDevice.h>
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: exit status 1

I've got to relearn how this sketch works, but can't get past the compilation. Figure I should put the sketch in here.

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

// A simple data logger for the Arduino analog pins
// this sketch from Adafruit Data Logging Sheild tutorial


// how many milliseconds between grabbing data and logging it. 1000 ms is once a second

#define LOG_INTERVAL  10000 // mills between entries (reduce to take more/faster data) 10 seconds

// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to 
// the last 10 reads if power is lost but it uses less power and is much faster!
//#define SYNC_INTERVAL 120000 // mills between calls to flush() - to write data to the card   2 minutes
//#define SYNC_INTERVAL LOG_INTERVAL // mills between calls to flush() - to write data to the card   same as Log Interval
const int SYNC_INTERVAL=LOG_INTERVAL;
uint32_t syncTime = 0; // time of last sync()

#define ECHO_TO_SERIAL   1 // echo data to serial port
//#define ECHO_TO_SERIAL   0 // don't echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3

// The analog pins that connect to the sensors
#define photocellPin 0           // analog 0
#define tempPin 1                // analog 1
#define BANDGAPREF 14            // special indicator that we want to measure the bandgap

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!
#define bandgap_voltage 1.1      // this is not super guaranteed but its not -too- off

RTC_PCF8523 RTC; // define the Real Time Clock object

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();

    
  // use debugging LEDs
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
    
#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE); 
      break;  // leave the loop!
    }
  }
  
  if (! logfile) {
    error("couldnt create file");
  }
  
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
  

  logfile.println("millis,stamp,datetime,light,temp,vcc");    
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,light,temp,vcc");
#endif //ECHO_TO_SERIAL
 
  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}

void loop(void)
{
  DateTime now;

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
  
  digitalWrite(greenLEDpin, HIGH);
   
  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");    
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");  
#endif

  // fetch the time
  now = RTC.now();
  // log time
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  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('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(", ");
  Serial.print('"');
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print('"');
#endif //ECHO_TO_SERIAL

  analogRead(photocellPin);
  delay(10); 
  int photocellReading = analogRead(photocellPin);  
  
  analogRead(tempPin); 
  delay(10);
  int tempReading = analogRead(tempPin);    
  
  // converting that reading to voltage, for 3.3v arduino use 3.3, for 5.0, use 5.0
  float voltage = tempReading * aref_voltage / 1024;  
  float temperatureC = (voltage - 0.5) * 100 ;
  float temperatureF = (temperatureC * 9 / 5) + 32;
  
  logfile.print(", ");    
  logfile.print(photocellReading);
  logfile.print(", ");    
  logfile.print(temperatureF);
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(photocellReading);
  Serial.print(", ");    
  Serial.print(temperatureF);
#endif //ECHO_TO_SERIAL

  // Log the estimated 'VCC' voltage by measuring the internal 1.1v ref
  analogRead(BANDGAPREF); 
  delay(10);
  int refReading = analogRead(BANDGAPREF); 
  float supplyvoltage = (bandgap_voltage * 1024) / refReading; 
  
  logfile.print(", ");
  logfile.print(supplyvoltage);
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(supplyvoltage);
#endif // ECHO_TO_SERIAL

  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  digitalWrite(greenLEDpin, LOW);
  
    // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
  
  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(redLEDpin, HIGH);
  //delay(5000);
  logfile.flush();
  digitalWrite(redLEDpin, LOW);
  
}

Do you have the Adafruit_I2CDevice library installed ?

Well gosh @UKHeliBob,

I should have checked that since it was noted in the error message. I don't see it in my RTClib/src directory.

Install? Does that mean just downloading it into that same directory?

thanks,

hal

Try the library manager first.

@sterretje

I searched Library manager and don't find it.

I downloaded Adafruit_I2CDevice.h but don't know what to do with it. I tried to follow directions in "Installing a Library on Windows" but they didn't exactly match what I was seeing.

Finally.

Googling the Adafruit_I2CDevice library kept popping up Adafruit_BusIO. So I used the library manger to install that. And bingo, it worked!

To my surprise, within the Adafruit_BusIO folder in libraries, there were numerous .h files and examples. Among those files was the Adafruit_I2CDevice.h file @UKHeliBob said I should install.

Thanks all. Now on to relearning how this data logging shield works.

hal

Because you may encounter this in future for libraries that are not available in Library Manager, you can install the downloaded zip using Sketch → Libraries → Add .ZIP Library and selecting the downloaded ZIP.

A link would have been useful :wink:

Thanks @sterretje,

The confusion for me was that I couldn't find the Adafruit_I2CDevice.h item in the library. and couldn't find any zip files (per instructions) elsewhere. I found it on Github, but not as a zip file. That didn't work. Finally found it embedded in an Adafruit BusIO library. Using the library manager install, it loaded device.h and several other files as well.

FWIW - here's the directions on this and the following page I was attempting to follow. But not finding the zip file, totally baffled me. Installing a library

oh- and now I see that I needed not only the .h file but also related files like .cpp and an examples folder.

thanks again,

hal

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.