Wire was not declared

Hi,
I’m trying to port the I2C-Library from Francisco Malpartida to spark core but I fail at the very first line,…

I2CIO.cpp: In member function 'int I2CIO::begin(uint8_t)':
I2CIO.cpp:65:4: error: 'Wire' was not declared in this scope
Wire.begin ( );

I hope you can give me a hint how I can proceed. I included some code snippets, hope they are enough to identify the issue.

Main Application:

#define SPARK_CORE 2
#include "LiquidCrystal_I2C.h" /* which includes application.h and I2CIO.h */
void setup()
{
  Wire.begin(); // join i2c bus
}
void loop()
{
}

I2CIO.cpp:

#include "application.h"
#include "I2CIO.h"
I2CIO::I2CIO ( )
{
   _i2cAddr     = 0x0;
   _dirMask     = 0xFF;    // mark all as INPUTs
   _shadow      = 0x0;     // no values set
   _initialised = false;
}
int I2CIO::begin (  uint8_t i2cAddr )
{
   _i2cAddr = i2cAddr;
   Wire.begin ( );
   _initialised = Wire.requestFrom ( _i2cAddr, (uint8_t)1 );
   _shadow = Wire.receive ();
   return ( _initialised );
}

Kind regards

@joky, I found the library on bitbucket and I will do a port to see if I can get it to compile. Stay tuned. :slight_smile:

1 Like

@joky, there were several conditional compiles to add/change to make the code compile. Also, you have:

#define SPARK_CORE 2

The compiler now defines “SPARK” with a value of 1 so you can do conditional compiles with it. I posted the ported code with the HelloWorld_I2C demo on my repo here. Let me know it if works :smile:

Hi,
thank you! I (you) got it working!

Can you submit the code to the spark library (or should I do?)

kind regards

1 Like

@joky, I will publish the library today. :smiley:

2 Likes