Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
When I compile a code, this is the error I get:

In file included from MS561101BA_altitude.pde:31:
C:\Program Files (x86)\Arduino\libraries\MS561101BA/MS561101BA.h:82: error: expected unqualified-id before numeric constant

The code I am trying to compile is:


C++
#include <wire.h>
//#include <debugutils.h>
#include <ms561101ba.h>   // <-------------------------------------------Line 31


#define MOVAVG_SIZE 32

MS561101BA baro = MS561101BA();

float movavg_buff[MOVAVG_SIZE];
int movavg_i=0;

const float sea_press = 1013.25;
float press, temperature;

void setup() {
  Wire.begin();
  Serial.begin(115200);
  delay(1000);

  // Suppose that the CSB pin is connected to GND.
  // You'll have to check this on your breakout schematics
  baro.init(MS561101BA_ADDR_CSB_LOW); 
  delay(100);
  
  // populate movavg_buff before starting loop
  for(int i=0; i<movavg_size;>    movavg_buff[i] = baro.getPressure(MS561101BA_OSR_4096);
  }
}

void loop() {
  Serial.print(" temp: ");
  temperature = baro.getTemperature(MS561101BA_OSR_4096);
  Serial.print(temperature);
  Serial.print(" degC pres: ");
  
  press = baro.getPressure(MS561101BA_OSR_4096);
  pushAvg(press);
  press = getAvg(movavg_buff, MOVAVG_SIZE);
  Serial.print(press);
  Serial.print(" mbar altitude: ");
  Serial.print(getAltitude(press, temperature));
  Serial.println(" m");
}

float getAltitude(float press, float temp) {
  //return (1.0f - pow(press/101325.0f, 0.190295f)) * 4433000.0f;
  return ((pow((sea_press / press), 1/5.257) - 1.0) * (temp + 273.15)) / 0.0065;
}

void pushAvg(float val) {
  movavg_buff[movavg_i] = val;
  movavg_i = (movavg_i + 1) % MOVAVG_SIZE;
}

float getAvg(float * buff, int size) {
  float sum = 0.0;
  for(int i=0; i<size;>    sum += buff[i];
  }
  return sum / size;
}

Code of MS561101BA.h is:


C++
#ifndef MS561101BA_h
#define MS561101BA_h

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

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

//#define DEBUG_V
//#define DEBUG
//#include <debugutils.h>

// addresses of the device
#define MS561101BA_ADDR_CSB_HIGH  0x76   //CBR=1 0x76 I2C address when CSB is connected to HIGH (VCC)
#define MS561101BA_ADDR_CSB_LOW   0x77   //CBR=0 0x77 I2C address when CSB is connected to LOW (GND)

// registers of the device
#define MS561101BA_D1 0x40
#define MS561101BA_D2 0x50
#define MS561101BA_RESET 0x1E

// D1 and D2 result size (bytes)
#define MS561101BA_D1D2_SIZE 3

// OSR (Over Sampling Ratio) constants
#define MS561101BA_OSR_256 0x00
#define MS561101BA_OSR_512 0x02
#define MS561101BA_OSR_1024 0x04
#define MS561101BA_OSR_2048 0x06
#define MS561101BA_OSR_4096 0x08

#define MS561101BA_PROM_BASE_ADDR 0xA2 // by adding ints from 0 to 6 we can read all the prom configuration values. 
// C1 will be at 0xA2 and all the subsequent are multiples of 2
#define MS561101BA_PROM_REG_COUNT 6 // number of registers in the PROM
#define MS561101BA_PROM_REG_SIZE 2 // size in bytes of a prom registry.



class MS561101BA {
  public:
    MS561101BA();
    void init(uint8_t addr);
    float getPressure(uint8_t OSR);
    float getTemperature(uint8_t OSR);
    int32_t getDeltaTemp(uint8_t OSR);
    uint32_t rawPressure(uint8_t OSR);
    uint32_t rawTemperature(uint8_t OSR);
    int readPROM();
    void reset();
    uint32_t lastPresConv, lastTempConv;
  private:
    void startConversion(uint8_t command);
    uint32_t getConversion(uint8_t command);
    uint8_t _addr;
    uint16_t _C[MS561101BA_PROM_REG_COUNT];  //  <--------------------Line 82
    uint32_t pressCache, tempCache;
};

#endif // MS561101BA_h


Any help would be apprecited in eliminating this error. :)
Posted
Updated 23-Jun-14 8:41am
v4
Comments
Andreas Gieriet 8-Jun-14 17:06pm    
The code was broken while pasted. Please check if the pasted code matches your original code.
Press the [Improve question] link at the bottom of your question: Place each code segment into <pre lang="c++"> ... </pre>.
Cheers
Andi
Peter_in_2780 9-Jun-14 2:37am    
Is the symbol MS561101BA_PROM_REG_COUNT defined anywhere before this line?
Member 10871816 9-Jun-14 3:05am    
Yes, it is defined in the header file MS561101BA.h as:
#define MS561101BA_PROM_REG_COUNT 6 // number of registers in the PROM
Andreas Gieriet 9-Jun-14 8:42am    
You seem not being interesed in help - why don't you update your code as advised? It constains broken code that won't at all compile, therefore, I don't trust your code line numbers.

E.g. this code is broken:

for(int i=0; i<movavg_size;> movavg_buff[i] = baro.getPressure(MS561101BA_OSR_4096);
}


Run your compiler with the option to only pre-process and check the respective error location.

Andi

PS: Is this the first, last, only error message? Any other messages?
Vedat Ozan Oner 23-Jun-14 14:58pm    
Can you test it with Arduino.h? I don't get any error with your code. ( having paste errors corrected & function declarations mocked)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900