Scope and Compiler Problems

Hi, I am trying to use a BMP280 library and seem to keep having scope problems
which elude me to figure out why (I am a bit of a newbee). I know C reassonably well,
but not ++.

Attached is lib and my .ino

I would be grateful if anyone can take a look at this and give me some direction.

One last question. Is there a doc on the Arduino IDE that explains scoping and the
placement of includes and directives at beginning of file versus in setup() or loop() ?
BMP280 Test.zip (28.7 KB)

let me google "arduino scope" for you... first hit is

don't put your #include in setup... start your .ino with them
declare your bmp instance also globally

Your global variables can also be initialized when you declare them, no need to do that in the setup like you can do

byte status = 0;
float temperature = 0;
..

(and by default they are initialized to 0 so you don't even need to do it)

don't do begin() twice

I have a basic understanding of scope, should have made that clear,
and thought that if a var or object is declared in setup(0 that becomes
global, which there is no mention of in Arduino ref manual. In fact it
implies if its in setup() then its local by wording in the link you gave.

Regards, Dana.

if you declare a variable in a function, it's local to that function.

so your code probably should be

#include <Wire.h>
#include <ESP8266.h>
#include "BMP280_DEV.h"
BMP280_DEV bmp280(6, 7);

void setup() {
  Serial.begin(9600);
  bmp280.begin();
  bmp280.setTimeStandby(TIME_STANDBY_1000MS);
  bmp280.startNormalConversion();
}


void loop() {
  float  temperature;
  float  pressure;
  float  altitude;

  if (bmp280.getMeasurements(temperature, pressure, altitude) > 0) {
    Serial.println(temperature, DEC);
  }
}

Let me google why there is a set() function in Arduino, unlike the
main() I am used to in C.

Thanks for the help, I still need, if possible, someone to look at
other errors I have in sketch.

Regards, Dana.

because the IDE generates the main for you which will call setup() and then repetitively loop() once the board as been properly configured. Since configuring the board is not for beginners, that's why they hide the main() but it's open source, so you can see it here for an AVR for example

did you try the code I posted?
you are referring to a local library (BMP280_DEV-master) that's probably not where it should be installed but I added double quotes so that the include would look in the local directory but it might not be enough for it work. Install the library in the right place

you also probably don't need #include <ESP8266.h>

So here are the errors. So I added the ESP8266WiFi.h because looks like another lib
was calling it, still lost in the forest :slight_smile:

I am trying to post the errors, and 500G of crap seems to appear in this window.

So old school -

Regards, Dana.

let's start by small steps:

where did you get BMP280_DEV ?

this one ? GitHub - MartinL1/BMP280_DEV: An Arduino compatible, non-blocking, I2C/SPI library for the Bosch BMP280 barometer.

github

I did try your code3, erros posted from that. The BMP280 is installed as
a zipo lib by IDE in correct folder.

Regards, Dana.

come on... my crystal ball is still in the dishwasher...

provide links and helpful input... do your part

1 Like

OK - this library can be installed directly from the Library manager.
open the library manager, search for BMP280_DEV and pick the library and click install.
it will put the library in the right place and right format for your PC/Mac

Thats what I have been using, already did that yesterday.

why do you have it in the directory you shared ?

I should have just given you the URL....my error.

OK no worries

if you compile this (one of their example) - does this work?

/////////////////////////////////////////////////////////////////////////////////
// BMP280_DEV - I2C Communications, Default Configuration, Normal Conversion
/////////////////////////////////////////////////////////////////////////////////

#include <BMP280_DEV.h>                           // Include the BMP280_DEV.h library

float temperature, pressure, altitude;            // Create the temperature, pressure and altitude variables
BMP280_DEV bmp280;                                // Instantiate (create) a BMP280_DEV object and set-up for I2C operation (address 0x77)

void setup() 
{
  Serial.begin(115200);                           // Initialise the serial port
  bmp280.begin();                                 // Default initialisation, place the BMP280 into SLEEP_MODE 
  //bmp280.setPresOversampling(OVERSAMPLING_X4);    // Set the pressure oversampling to X4
  //bmp280.setTempOversampling(OVERSAMPLING_X1);    // Set the temperature oversampling to X1
  //bmp280.setIIRFilter(IIR_FILTER_4);              // Set the IIR filter to setting 4
  bmp280.setTimeStandby(TIME_STANDBY_2000MS);     // Set the standby time to 2 seconds
  bmp280.startNormalConversion();                 // Start BMP280 continuous conversion in NORMAL_MODE  
}

void loop() 
{
  if (bmp280.getMeasurements(temperature, pressure, altitude))    // Check if the measurement is complete
  {
    Serial.print(temperature);                    // Display the results    
    Serial.print(F("*C   "));
    Serial.print(pressure);    
    Serial.print(F("hPa   "));
    Serial.print(altitude);
    Serial.println(F("m"));  
  }
}

(it compiles fine on my machine once the library is installed)

Yes

Thanks. Now I will go fig why the USBUART functionality, the monitor, is not working
but I am sure I can at least put my big boy pants on for that. I think I just have to wire
up I2C correctly for that.

Thanks for the help.

Regards, Dana.