Problem addin Wire.h to a library.

Hello everybody. I am making a where I'll have basic functions to read and write through I2C.

Then if I include the library Wire I get this error.

/I2C.h:4: fatal error: Wire.h: No such file or directory

The library look like that

I2C.H

#ifndef I2C_H_
#define I2C_H_

#include "Arduino.h"
#include <Wire.h>

#define ADDRESS         0x21                       // Define address of OV7670
#define REGISTERS       0x91                       // Define # of Registesr on OV7076


class I2CClass {

  public:
        I2CClass();
        void init();
        void write(uint8_t slave_address, uint8_t data);
        void read_bank();
  private:
        uint8_t initialized;
};

extern I2CClass I2C;
#endif

I2C.CCP

#include "I2C.h"

I2CClass::I2CClass(){
  initialized = false;                         
}

void I2CClass::init(){
  if (!initialized) {
     Wire.begin();             
     initialized = true;
  }
}

void I2CClass::write(uint8_t slave_address, uint8_t data){
  delay(5); 
  Wire.beginTransmission(ADDRESS);           // Start transmission to device
  Wire.write(slave_address);                 // Send register address
  Wire.write(data);                          // Send value to write
  Wire.endTransmission();                    // End transmission 
  delay(5);                      
}

void I2CClass::read_bank(){
  int count = 0;
  byte tmp;
  
  while(count<REGISTERS)
  {
     byte highByte=0;
     Serial.print("\n Registro num: ");
     Serial.println(count,HEX);
     Wire.beginTransmission(ADDRESS);          //Start communication with cmps03
     Wire.write(count);                        //Send the register we wish to read
     Wire.endTransmission();
     Wire.requestFrom(ADDRESS, 1);             //Request high byte
     while(Wire.available() < 1);              //While there is a byte to receive
     highByte = Wire.read();                   //Read the byte as an integer
     Serial.println(highByte,HEX);
     delay(25);
     count++;
  }        
}

I2CClass I2C;

How can I solve it? If have tried to copy wire.h and wire.ccp to the scketh folder but them also ask for twy.h and more libraries..

Thanks in advance

I think the problem is how Arduino IDE collect all code (.h and .cpp/.c source) from library folder and your sketch folder.
It scan your sketch and not your I2C library.
I think if you write the include #include <Wire.h> as first line in your sketch and remove it from i2c.h now compile.

nid69ita:
I think the problem is how Arduino IDE collect all code (.h and .cpp/.c source) from library folder and your sketch folder.
It scan your sketch and not your I2C library.
I think if you write the include #include <Wire.h> as first line in your sketch and remove it from i2c.h now compile.

You'll still need it in your i2c library, or it won't know what the wire functions are.

By adding it to your sketch you are telling the IDE to include that file's location in the list of places to look for files during compilation. Without that being added, when it comes to compiling your library (which is done separately to compiling the sketch) it won't know where to find the Wire.h file.

@Majenko you know if this problem is resolved with 1.5.5 ? In new version of IDE now it scan all code ?

nid69ita:
@Majenko you know if this problem is resolved with 1.5.5 ? In new version of IDE now it scan all code ?

I don't know about 1.5.5, but it's certainly fixed in UECIDE cus I fixed it myself :stuck_out_tongue:

majenko:

nid69ita:
@Majenko you know if this problem is resolved with 1.5.5 ? In new version of IDE now it scan all code ?

I don't know about 1.5.5, but it's certainly fixed in UECIDE cus I fixed it myself :stuck_out_tongue:

Yes, I know it, good work !!! :smiley: