Error when compiling: expected unqualified-id before numeric constant

I am trying to adapt a MS5837 pressure sensor to work with the Particle Electron. I am just trying to get the library’s test code to work but I am running into this error when I try to compile. This code compiles and works just fine on Arduino but doesn’t seem to work with Particle. The code I am trying to run along with the .h and .cpp can be found on github via:

Link to code

The full error message with its context in the raw output - or at least a filename and line number - would be helpful.
If you used Web IDE providing a project snapshot via the SHARE THIS REVISION button in the IDE would avoid the necessity to piece together some test project in order to see your actual problem.

But some things I have noticed in that library. It uses variables like D1 and D2 but these are already used as macros to define the pin names on the Particle devices. So that’s most likely the problem you are seeing.

Thank you for your help! I renamed the variables in the library from D1 and D2 to R1 and R2 respectively. I am now getting a different series of errors.

I know that Wire is a library inherent to Arduino. Do I need to add the Wire.h folder along with other dependencies from my Arduino install to my project directory? Or does particle offer an alternative?

On Particle devices there is no Wire.h file. But via #include <Particle.h> you can include all HW features the devices have on board.

If you are targeting a system version >= 0.6.3 you can #include <Arduino.h> (before any other include) which will provide you with extensive compatibility macros that make porting Arduino libraries much easier.

I have modified the library to #include <Particle.h> as well as added #include <Particle.h> to my .ino code. The code compiles without any issues but I am unable to use the sensor via serial as I get

  while (!sensor.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");

so the sensor is not initializing properly. I currently have the SDA connected to D0 and SCL connected to D1. I have also tried wiring SDA and SCL to pins C4 and C5 but it is still not working. I believe that by changing the variable names in the library from D1 and D2 to E1 and E2 has prevented initializing the sensor. Is there any way to keep the variables the original names from the library (D1 and D2) but prevent them from interfering as macros to define the pin names on the Particle?

You shouldn’t try to “reclaim” these as variable names, but if you changed all the instances of D1/D2 in the library it shouldn’t matter how they are called.

A way you may be able to do it might be by changing the library internal references from D1/D2 to
But I’d still consider it bad style.

When having troubles with I2C devices it’s also advisable to chech whether it can be found on the bus at all

1 Like

Hello, I’m having the same problem, did you find a solution?