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)
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.
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
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
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)
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.