Sparkfun MicroPressure SEN-16476 library breaks with Arduino Nano Every

Hello,

I've been using the Sparkfun Library for a pressure sensor with Arduino Micro and Nano with no problem. But I don't know why, with Arduino Nano Every the library breaks with following error.

Compiling sketch...
/Users/angel/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DAVR_NANO_4809_328MODE -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/deprecated -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/variants/nona4809 -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/libraries/Wire/src /Users/angel/Library/Caches/arduino/sketches/F61EF9A2AC2B5627C718CBAD8F6DF99F/sketch/SparkFun_MicroPressure.cpp -o /Users/angel/Library/Caches/arduino/sketches/F61EF9A2AC2B5627C718CBAD8F6DF99F/sketch/SparkFun_MicroPressure.cpp.o
/Users/angel/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega4809 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_NANO_EVERY -DARDUINO_ARCH_MEGAAVR -DAVR_NANO_4809_328MODE -DMILLIS_USE_TIMERB3 -DNO_EXTERNAL_I2C_PULLUP -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/api/deprecated -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/variants/nona4809 -I/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/libraries/Wire/src /Users/angel/Library/Caches/arduino/sketches/F61EF9A2AC2B5627C718CBAD8F6DF99F/sketch/desktop_kids_V02.ino.cpp -o /Users/angel/Library/Caches/arduino/sketches/F61EF9A2AC2B5627C718CBAD8F6DF99F/sketch/desktop_kids_V02.ino.cpp.o
In file included from /Users/angel/Library/Caches/arduino/sketches/F61EF9A2AC2B5627C718CBAD8F6DF99F/sketch/desktop_kids_V02.ino.cpp:1:0:
/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:101:12: error: expected identifier before numeric constant
 #define PA 0
            ^
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:22:3: note: in expansion of macro 'PA'
   PA,
   ^~
/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:101:12: error: expected '}' before numeric constant
 #define PA 0
            ^
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:22:3: note: in expansion of macro 'PA'
   PA,
   ^~
/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:101:12: error: expected unqualified-id before numeric constant
 #define PA 0
            ^
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:22:3: note: in expansion of macro 'PA'
   PA,
   ^~
In file included from /Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/desktop_kids_V02.ino:2:0:
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:28:1: error: expected declaration before '}' token
 };
 ^
In file included from /Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:2:0,
                 from /Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.cpp:10:
/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:101:12: error: expected identifier before numeric constant
 #define PA 0
            ^
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:22:3: note: in expansion of macro 'PA'
   PA,
   ^~
/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:101:12: error: expected '}' before numeric constant
 #define PA 0
            ^
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:22:3: note: in expansion of macro 'PA'
   PA,
   ^~
/Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/cores/arduino/Arduino.h:101:12: error: expected unqualified-id before numeric constant
 #define PA 0
            ^
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:22:3: note: in expansion of macro 'PA'
   PA,
   ^~
In file included from /Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.cpp:10:0:
/Users/angel/Downloads/SP/Tools/Desktop_Kids/desktop_kids_V02/SparkFun_MicroPressure.h:28:1: error: expected declaration before '}' token
 };
 ^
Using library Wire at version 1.0 in folder: /Users/angel/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.8/libraries/Wire 
exit status 1

Compilation error: expected declaration before '}' token

Do you know why am I getting this error? If I select Arduino Micro in the GUI the sketch compiles perfectly, but of course it cannot upload it to the board.

Here is the full sketch:

#include "SparkFun_MicroPressure.h"

int counter = 0;
unsigned long delayTime = 50;
int step = 1;
int sign = 1;
int pumpPort = 3;

int evArray[] = {9, 10, 11, 12};
int evId = 0;
int evAmount = sizeof(evArray)/sizeof(int);
float pressure = 0.0;


SparkFun_MicroPressure mpr; // Use default values with reset and EOC pins unused

void setup() {
  Serial.begin(115200);
  pinMode(pumpPort, OUTPUT);
  for(int evId = 0; evId < evAmount; evId++ ){
    pinMode(evArray[evId],OUTPUT);
  }

  if(!mpr.begin())
  {
    Serial.println("Cannot connect to MicroPressure sensor.");
    while(1);
  }

}

void loop() {
  counter = counter + (sign*step);

  if (counter > 255){
    counter = 255 - (2*step);
    sign = sign * -1;
  }
  if (counter <=0){
    counter = step;
    sign = sign * -1;
  }
  pressure = mpr.readPressure(BAR)-1;
  Serial.print("Counter= ");
  Serial.print(counter);
  Serial.print(", Pressure=");
  Serial.println(pressure);
  pumpOn(counter);
  delay(delayTime);

  if (counter >= (255-step)){
    for( evId = 0; evId < evAmount; evId++){
      Serial.print("EV: ");
      Serial.println(evArray[evId]);
      ev_On(evArray[evId]);
      delay(500);
    }
    for( evId = 0; evId < evAmount; evId++){
      ev_Off(evArray[evId]);
      delay(500);
    }
  }
}


void pumpOn(int pwm){
  analogWrite(pumpPort, pwm);
}

void ev_On(int evPort){
  digitalWrite(evPort, HIGH);
}

void ev_Off(int evPort){
  digitalWrite(evPort, LOW);
}

Sparkfun.cpp code

/*

  This is a library for the Qwiic MicroPressure Sensor, which can read from 0 to 25 PSI.

  By: Alex Wende

  Date: July 2020 

  License: This code is public domain but you buy me a beer if you use this and 

  we meet someday (Beerware license).

  Feel like supporting our work? Buy a board from SparkFun!

 */

#include "SparkFun_MicroPressure.h"




/* Constructor and sets default values.

   - (Optional) eoc_pin, End of Conversion indicator. Default: -1 (skip)

   - (Optional) rst_pin, Reset pin for MPR sensor. Default: -1 (skip)

   - minimumPSI, minimum range value of the sensor (in PSI). Default: 0

   - maximumPSI, maximum range value of the sensor (in pSI). Default: 25

*/

SparkFun_MicroPressure::SparkFun_MicroPressure(int8_t eoc_pin, int8_t rst_pin, uint8_t minimumPSI, uint8_t maximumPSI)

{

  _eoc = eoc_pin;

  _rst = rst_pin;

  _minPsi = minimumPSI;

  _maxPsi = maximumPSI;

}




/* Initialize hardware

  - deviceAddress, I2C address of the sensor. Default: 0x18

  - wirePort, sets the I2C bus used for communication. Default: Wire

  - Returns 0/1: 0: sensor not found, 1: sensor connected

*/

bool SparkFun_MicroPressure::begin(uint8_t deviceAddress, TwoWire &wirePort)

{

  _address = deviceAddress;

  _i2cPort = &wirePort;

if(_eoc != -1)

{

pinMode(_eoc, INPUT);

}

if(_rst != -1)

{

pinMode(_rst, OUTPUT);

digitalWrite(_rst,LOW);

delay(5);

digitalWrite(_rst,HIGH);

delay(5);

}




_i2cPort->beginTransmission(_address);




uint8_t error = _i2cPort->endTransmission();




if(error == 0) return true;

else           return false;

}




/* Read the status byte of the sensor

  - Returns status byte

*/

uint8_t SparkFun_MicroPressure::readStatus(void)

{

_i2cPort->requestFrom(_address,1);

return _i2cPort->read();

}




/* Read the Pressure Sensor Reading

 - (optional) Pressure_Units, can return various pressure units. Default: PSI

   Pressure Units available:

     - PSI: Pounds per Square Inch

   - PA: Pascals

   - KPA: Kilopascals

   - TORR

   - INHG: Inch of Mercury

   - ATM: Atmospheres

   - BAR

*/

float SparkFun_MicroPressure::readPressure(Pressure_Units units)

{

_i2cPort->beginTransmission(_address);

_i2cPort->write((uint8_t)0xAA);

_i2cPort->write((uint8_t)0x00);

_i2cPort->write((uint8_t)0x00);

_i2cPort->endTransmission();

  // Wait for new pressure reading available

if(_eoc != -1) // Use GPIO pin if defined

{

while(!digitalRead(_eoc))

{

delay(1);

}

}

else // Check status byte if GPIO is not defined

{

uint8_t status = readStatus();

while((status&BUSY_FLAG) && (status!=0xFF))

{

delay(1);

      status = readStatus();

}

}

_i2cPort->requestFrom(_address,4);

uint8_t status = _i2cPort->read();

  //check memory integrity and math saturation bits

if((status & INTEGRITY_FLAG) || (status & MATH_SAT_FLAG))

{

return NAN;

}

  //read 24-bit pressure

uint32_t reading = 0;

for(uint8_t i=0;i<3;i++)

{

    reading |= _i2cPort->read();

if(i != 2) reading = reading<<8;

}




  //convert from 24-bit to float psi value

float pressure;

  pressure = (reading - OUTPUT_MIN) * (_maxPsi - _minPsi);

  pressure = (pressure / (OUTPUT_MAX - OUTPUT_MIN)) + _minPsi;




if(units == PSI)       return pressure; //PSI

else if(units == PA)   return pressure*6894.7573; //Pa (Pascal)

else if(units == KPA)  return pressure*6.89476;   //kPa (kilopascal)

else if(units == TORR) return pressure*51.7149;   //torr (mmHg)

else if(units == INHG) return pressure*2.03602;   //inHg (inch of mercury)

else if(units == ATM)  return pressure*0.06805;   //atm (atmosphere)

else if(units == BAR)  return pressure*0.06895;   //bar

else                   return pressure; //PSI

}

Sparkfun .h code

#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <Wire.h>

#define DEFAULT_ADDRESS 0x18
#define MAXIMUM_PSI     25
#define MINIMUM_PSI     0

#define BUSY_FLAG       0x20
#define INTEGRITY_FLAG  0x04
#define MATH_SAT_FLAG   0x01

#define OUTPUT_MAX 0xE66666
#define OUTPUT_MIN 0x19999A

enum Pressure_Units {
  PSI,
  PA,
  KPA,
  TORR,
  INHG,
  ATM,
  BAR
};

class SparkFun_MicroPressure
{
  public:
    SparkFun_MicroPressure(int8_t eoc_pin=-1, int8_t rst_pin=-1, uint8_t minimumPSI=MINIMUM_PSI, uint8_t maximumPSI=MAXIMUM_PSI);
    bool begin(uint8_t deviceAddress = DEFAULT_ADDRESS, TwoWire &wirePort = Wire);
    uint8_t readStatus(void);
    float readPressure(Pressure_Units units=PSI);
    
  private:
    int8_t _address;
	int8_t _eoc, _rst;
	
    uint8_t _minPsi, _maxPsi;
    
    TwoWire *_i2cPort;
};

You started a topic in the Uncategorised category of the forum when its description explicitly tells you not to

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

I've used the code tag. I see the error message properly identified as code in the post.

sorry I apollogise. I couldn't see a library category. I didn't unserstand what category was.

You used code tags when you posted the error message, for which I thank you, but you have not posted your sketch

okh ok. I've done it now.

buf ok Managed to solve it.

It seems that Arduino.h library for Nano Every Boards defines PA as 0 which is converted when instantiating the Enum.

The solution was to cahange PA by PASCAL in the Sparkfun's .h ENUM variable.

Good to hear, please report it to Sparkfun too !

yes I opened the issue at git library from sparkfun and told them the solution i've made. eventhough it seems there is incompatibility with arduino nano every, i did not manage to get values other than NAN.