Skip to content

Commit a34eb03

Browse files
committed
bmp280 examples
1 parent 5d64964 commit a34eb03

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
WProgram.h - Legacy Main include file for the Arduino SDK
3+
Copyright (c) 2025 Phil Schatzmann. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
#pragma once
20+
// This is for compatibility with older Arduino libraries that still include WProgram.h
21+
// It is recommended to use Arduino.h instead of WProgram.h in new code
22+
#include "Arduino.h"

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ add_subdirectory("i2c")
55
add_subdirectory("spi")
66
add_subdirectory("serial2")
77
add_subdirectory("using-arduino-library")
8+
# BME280 Sensor Examples
9+
arduino_library(SparkFunBME280 "https://github.com/sparkfun/SparkFun_BME280_Arduino_Library" )
10+
add_subdirectory("bme280-i2c")
11+
add_subdirectory("bme280-spi")
812

913
if(USE_HTTPS)
1014
add_subdirectory("wifi-secure")

examples/bme280-i2c/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
arduino_sketch(bme280-i2c bme280-i2c.ino LIBRARIES SparkFunBME280)

examples/bme280-i2c/bme280-i2c.ino

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Example sketch for the BME280 combined humidity and pressure sensor
2+
// Using I2C communication with the SparkFun BME280 Arduino Library
3+
4+
#include <Arduino.h>
5+
#include <Wire.h>
6+
#include "SparkFunBME280.h"
7+
8+
BME280 mySensor;
9+
10+
void setup() {
11+
Serial.begin(115200);
12+
Serial.println("Reading basic values from BME280");
13+
// Begin communication over I2C
14+
Wire.begin();
15+
if (mySensor.beginI2C() == false) {
16+
Serial.println("The sensor did not respond. Please check wiring.");
17+
while (1); // Freeze
18+
}
19+
}
20+
21+
void loop() {
22+
Serial.print("Humidity: ");
23+
Serial.print(mySensor.readFloatHumidity(), 0);
24+
Serial.print(" Pressure: ");
25+
Serial.print(mySensor.readFloatPressure(), 0);
26+
Serial.print(" Alt: ");
27+
Serial.print(mySensor.readFloatAltitudeMeters(), 1);
28+
Serial.print(" Temp: ");
29+
Serial.println(mySensor.readTempC(), 2);
30+
31+
delay(1000);
32+
}

examples/bme280-spi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
arduino_sketch(bme280-spi bme280-spi.ino LIBRARIES SparkFunBME280)

examples/bme280-spi/bme280-spi.ino

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Example sketch for the BME280 combined humidity and pressure sensor
2+
// Using SPI communication with the SparkFun BME280 Arduino Library
3+
4+
#include <Arduino.h>
5+
#include <SPI.h>
6+
#include "SparkFunBME280.h"
7+
8+
const int csPin = 13; // Chip select pin for SPI
9+
BME280 mySensor;
10+
11+
void setup() {
12+
Serial.begin(9600);
13+
Serial.println("Reading basic values from BME280");
14+
// Begin communication over SPI. Use pin 10 as CS.
15+
if (mySensor.beginSPI(csPin) == false) {
16+
Serial.println("The sensor did not respond. Please check wiring.");
17+
while (1); // Freeze
18+
}
19+
}
20+
21+
void loop() {
22+
Serial.print("Humidity: ");
23+
Serial.print(mySensor.readFloatHumidity(), 0);
24+
Serial.print(" Pressure: ");
25+
Serial.print(mySensor.readFloatPressure(), 0);
26+
Serial.print(" Alt: ");
27+
Serial.print(mySensor.readFloatAltitudeMeters(), 1);
28+
Serial.print(" Temp: ");
29+
Serial.println(mySensor.readTempC(), 2);
30+
31+
delay(1000);
32+
}

0 commit comments

Comments
 (0)