i2c.h Wont compile without errors

Hi,

I have a sketch that works on an Uno but will not compile when trying to upload to an mrk wifi 1010. The problem seems to be with the i2c library I am using found here:

I am trying to connect a 262-BMP280 barometer:

Here is the sketch:

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

#include "i2c_BMP280.h"
BMP280 bmp280;

String EAR = "RIGHT";

void setup()
{
    Serial.begin(57600);
    
    bmp280.initialize();

    // 1-0-0    122Hz
    // 2-0-0    96Hz
    // 4-0-0    68Hz
    // 16-0-0   28Hz

    /*
    val > 15  VAL_CTRL_OSRS_P16
    val > 7   VAL_CTRL_OSRS_P08
    val > 3   VAL_CTRL_OSRS_P04
    val > 1   VAL_CTRL_OSRS_P02
    val > 0   VAL_CTRL_OSRS_P01
    */
    bmp280.setPressureOversampleRatio(1);               // Ultra-high resolution?

    /*
    val > 15  VAL_FILTER_16;
    val > 7   VAL_FILTER_08;
    val > 3   VAL_FILTER_04;
    val > 1   VAL_FILTER_02;
    */
    bmp280.setFilterRatio();                           // (disabled?) Infinite Impulse Response filter     

    /*
    ms > 3000 VAL_SB_4000;
    ms > 1500 VAL_SB_2000;
    ms > 750  VAL_SB_1000;
    ms > 350  VAL_SB_0500;
    ms > 180  VAL_SB_0250;
    ms > 90   VAL_SB_0125;
    ms > 31   VAL_SB_0062;
    */
    bmp280.setStandby();                               // ((fastest) Oversampling: 0.5

    // onetime-measure:
    bmp280.setEnabled(0);
    bmp280.triggerMeasurement();
}

void loop()
{
    bmp280.awaitMeasurement();

    float pascal;
    bmp280.getPressure(pascal);

    bmp280.triggerMeasurement();

    Serial.println(EAR + " " + pascal);
}

And here is the error message:

Arduino: 1.8.8 (Windows 10), Board: "Arduino MKR WiFi 1010"

In file included from sketch\i2c_BMP280.ino.cpp:1:0:

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h: In constructor 'WirePlus::WirePlus()':

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: error: no match for 'operator|=' (operand types are '_EPortType' and 'long unsigned int')

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:70:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 4);  // deactivate internal pull-ups for twi

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: note: candidate is:

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:70:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 4);  // deactivate internal pull-ups for twi

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: note: operator|=(_EPortType&, long unsigned int) <built-in>

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:70:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 4);  // deactivate internal pull-ups for twi

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: note:   no known conversion for argument 1 from '_EPortType' to '_EPortType&'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:70:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 4);  // deactivate internal pull-ups for twi

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: error: no match for 'operator|=' (operand types are '_EPortType' and 'long unsigned int')

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:71:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 5);  // as per note from atmega8 manual pg167

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: note: candidate is:

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:71:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 5);  // as per note from atmega8 manual pg167

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: note: operator|=(_EPortType&, long unsigned int) <built-in>

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:71:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 5);  // as per note from atmega8 manual pg167

     ^

C:\Users\cdjd4\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.20\cores\arduino/Arduino.h:116:37: note:   no known conversion for argument 1 from '_EPortType' to '_EPortType&'

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                     ^

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:71:5: note: in expansion of macro 'bitSet'

     bitSet(PORTC, 5);  // as per note from atmega8 manual pg167

     ^

In file included from C:\Users\cdjd4\Documents\Arduino\i2c_BMP280\i2c_BMP280.ino:5:0:

C:\Users\cdjd4\Documents\Arduino\libraries\I2C-Sensor-Lib_iLib\src/i2c.h:73:5: error: 'TWBR' was not declared in this scope

     TWBR = ((F_CPU / 400000L) - 16) / 2; 

     ^

exit status 1
Error compiling for board Arduino MKR WiFi 1010.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I must admit that c/c++ are not my main languages, I mostly work with c# and this is my first arduino project. I have spent the last week looking at this and could not find any answers which I think might be due to my lack of experience with the language. Any help or pointers would be most appreciated.

I do not have that sensor, but I took a brief look at your post and both headers.

In my opinion, the library can not be used with the MKR1010 because of the atmega-specific coding that is employed (which is reasonable for an atmega but not for the SAMD21 on the mkr1010).

While you could painstakingly try to fix things, it would be ill-advised.

Again, IMO, you would be much better off trying to use the BOSCH driver here: GitHub - boschsensortec/BMP280_driver: Bosch Sensortec BMP280 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community

The readme has examples for I2C initialization and reading etc...

Now, I don't have that sensor and have not tried that driver, but I am hoping this will help...let us know please.

Edited to add: I also notice that they have an Arduino library here with some instructions for use with samd boards that might be useful GitHub - boschsensortec/BSEC-Arduino-library: Arduino library for BSEC to simplify integration into compatible platforms. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community

DrGee:
I do not have that sensor, but I took a brief look at your post and both headers.

In my opinion, the library can not be used with the MKR1010 because of the atmega-specific coding that is employed (which is reasonable for an atmega but not for the SAMD21 on the mkr1010).

While you could painstakingly try to fix things, it would be ill-advised.

Again, IMO, you would be much better off trying to use the BOSCH driver here: GitHub - boschsensortec/BMP280_driver: Bosch Sensortec BMP280 sensor driver. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community

The readme has examples for I2C initialization and reading etc...

Now, I don't have that sensor and have not tried that driver, but I am hoping this will help...let us know please.

Edited to add: I also notice that they have an Arduino library here with some instructions for use with samd boards that might be useful GitHub - boschsensortec/BSEC-Arduino-library: Arduino library for BSEC to simplify integration into compatible platforms. To report issues, go to https://community.bosch-sensortec.com/t5/Bosch-Sensortec-Community/ct-p/bst_community

Thank you so much for getting back to me with some options and I apologize for the delay. I was genuinely losing my mind trying to get the library working. I will look at both suggestions and get back to let you know if I have found some success or not.

Cdjd44:
Thank you so much for getting back to me with some options and I apologize for the delay. I was genuinely losing my mind trying to get the library working. I will look at both suggestions and get back to let you know if I have found some success or not.

Hallo,

After my purchase of the MKRWIFI1010 the same problem occurred. The options for a solution mentioned earlier seemed pretty tough to do.

Looking into the possible solutions the special library called BMx280MI in the list shown by the library tool of the Arduino IDE was found.

The info on the lib is at
https://bitbucket.org/christandlg/bmx280mi/overview

Does not use i2c.h and i2c_bmp280.h but Wire.h and BMx280MI.h.

The example in that repositry worked for me. Have a look at
https://bitbucket.org/christandlg/bmx280mi/src/b1ed6eea7a5071f56cd590d06e783109a211be5b/examples/BMx280_I2C/?at=master

and the corresponding sketch
https://bitbucket.org/christandlg/bmx280mi/src/b1ed6eea7a5071f56cd590d06e783109a211be5b/examples/BMx280_I2C/BMx280_I2C.ino?at=master&fileviewer=file-view-default

Maybe it works for you as well. Combining with WIFININA and MQTT was OK.