Components and supplies
Adafruit OLED 128x32 i2c
Adafruit BMP280
Arduino UNO
Project description
Code
Adafruit GFX library
bmp280_Serial_metric.ino
arduino
1/* This code is to use with Adafruit BMP280 (Metric) 2 * It measures both temperature and pressure and it displays them on the Serial monitor with the altitude 3 * It's a modified version of the Adafruit example code 4 * Refer to www.surtrtech.com or SurtrTech Youtube channel 5 */ 6 7#include <Adafruit_BMP280.h> 8 9Adafruit_BMP280 bmp; // I2C Interface 10 11void setup() { 12 Serial.begin(9600); 13 Serial.println(F("BMP280 test")); 14 15 if (!bmp.begin()) { 16 Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); 17 while (1); 18 } 19 20 /* Default settings from datasheet. */ 21 bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ 22 Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 23 Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 24 Adafruit_BMP280::FILTER_X16, /* Filtering. */ 25 Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ 26} 27 28void loop() { 29 Serial.print(F("Temperature = ")); 30 Serial.print(bmp.readTemperature()); 31 Serial.println(" *C"); 32 33 Serial.print(F("Pressure = ")); 34 Serial.print(bmp.readPressure()/100); //displaying the Pressure in hPa, you can change the unit 35 Serial.println(" hPa"); 36 37 Serial.print(F("Approx altitude = ")); 38 Serial.print(bmp.readAltitude(1019.66)); //The "1019.66" is the pressure(hPa) at sea level in day in your region 39 Serial.println(" m"); //If you don't know it, modify it until you get your current altitude 40 41 Serial.println(); 42 delay(2000); 43} 44
bmp280_OLED_US.ino
arduino
1/* This code is to use with Adafruit BMP280 and OLED screen (Imperial) 2 * It measures both temperature and pressure and it displays them on the OLED display with the altitude 3 * It's a modified version of the Adafruit example code 4 * Refer to www.surtrtech.com or SurtrTech Youtube channel 5 */ 6 7#include <Adafruit_GFX.h> //Libraries for the OLED and BMP280 8#include <Adafruit_SSD1306.h> 9#include <Adafruit_BMP280.h> 10 11#define SCREEN_WIDTH 128 // OLED display width, in pixels 12#define SCREEN_HEIGHT 32 // OLED display height, in pixels 13#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 14 15Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display) 16Adafruit_BMP280 bmp; 17 18void setup() { 19 bmp.begin(); //Start the bmp 20 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display 21 display.clearDisplay(); 22 display.display(); 23 display.setTextColor(WHITE); 24 display.setTextSize(1); 25 display.print("SurtrTech"); //Show the name, you can remove it or replace it 26 display.setCursor(32,12); 27 display.setTextSize(2); 28 display.println("BMP280"); 29 display.display(); 30 delay(2000); 31} 32 33void loop() { 34 35 display.clearDisplay(); 36 float T = bmp.readTemperature()*9/5 + 32; //Read temperature in C and conversion to F 37 float P = bmp.readPressure()/3386.39; //Read Pressure in Pa and conversion to inches of mercury 38 float A = bmp.readAltitude(1019.66)*3.28084; //Calculating the Altitude, the "1019.66" is the pressure in(hPa) at sea level at day in your region 39 //If you don't know it just modify it until you get the altitude of your place 40 41 display.setCursor(0,0); //Oled display, just playing with text size and cursor to get the display you want 42 display.setTextColor(WHITE); 43 display.setTextSize(2); 44 display.print("Temp"); 45 46 display.setCursor(0,18); 47 display.print(T,1); 48 display.setCursor(50,17); 49 display.setTextSize(1); 50 display.print("F"); 51 52 display.setTextSize(1); 53 display.setCursor(65,0); 54 display.print("Pres"); 55 display.setCursor(65,10); 56 display.print(P); 57 display.setCursor(100,10); 58 display.print("inHg"); 59 60 display.setCursor(65,25); 61 display.print("Alt"); 62 display.setCursor(90,25); 63 display.print(A,0); 64 display.setCursor(110,25); 65 display.print("ft"); 66 67 display.display(); 68 delay(2000); 69} 70
bmp280_Serial_Imperial.ino
arduino
1/* This code is to use with Adafruit BMP280 (Imperial) 2 * It measures both temperature and pressure and it displays them on the Serial monitor with the altitude 3 * It's a modified version of the Adafruit example code 4 * Refer to www.surtrtech.com or SurtrTech Youtube channel 5 */ 6 7#include <Adafruit_BMP280.h> 8 9Adafruit_BMP280 bmp; // I2C 10 11void setup() { 12 Serial.begin(9600); 13 Serial.println(F("BMP280 test")); 14 15 if (!bmp.begin()) { 16 Serial.println(F("Could not find a valid BMP280 sensor, check wiring!")); 17 while (1); 18 } 19 20 /* Default settings from datasheet. */ 21 bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ 22 Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 23 Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 24 Adafruit_BMP280::FILTER_X16, /* Filtering. */ 25 Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ 26} 27 28void loop() { 29 30 float f = bmp.readTemperature()*9/5 + 32 ; //Conversion from C to F 31 Serial.print(F("Temperature = ")); 32 Serial.print(f); 33 Serial.println(" *F"); 34 35 float P = bmp.readPressure()/3386.39; //displaying the Pressure in inches of mercury, you can change the unit 36 Serial.print(F("Pressure = ")); 37 Serial.print(P); 38 Serial.println(" inHg"); 39 40 float A = bmp.readAltitude(1019.66)*3.28084; //The "1019.66" is the pressure(hPa) at sea level in day in your region 41 Serial.print(F("Approx altitude = ")); //If you don't know it, modify it until you get your current altitude 42 Serial.print(A); 43 Serial.println(" ft"); 44 45 Serial.println(); 46 delay(2000); 47} 48
bmp280_OLED_m.ino
arduino
1/* This code is to use with Adafruit BMP280 and OLED screen (Metric) 2 * It measures both temperature and pressure and it displays them on the OLED display with the altitude 3 * It's a modified version of the Adafruit example code 4 * Refer to www.surtrtech.com or SurtrTech Youtube channel 5 */ 6 7#include <Adafruit_GFX.h> //Libraries for the OLED and BMP280 8#include <Adafruit_SSD1306.h> 9#include <Adafruit_BMP280.h> 10 11#define SCREEN_WIDTH 128 // OLED display width, in pixels 12#define SCREEN_HEIGHT 32 // OLED display height, in pixels 13#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) 14 15Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display) 16Adafruit_BMP280 bmp; 17 18void setup() { 19 bmp.begin(); //Start the bmp 20 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display 21 display.clearDisplay(); 22 display.display(); 23 display.setTextColor(WHITE); 24 display.setTextSize(1); 25 display.print("SurtrTech"); //Show the name, you can remove it or replace it 26 display.setCursor(32,12); 27 display.setTextSize(2); 28 display.println("BMP280"); 29 display.display(); 30 delay(2000); 31} 32 33void loop() { 34 35 display.clearDisplay(); 36 float T = bmp.readTemperature(); //Read temperature in C 37 float P = bmp.readPressure()/100; //Read Pressure in Pa and conversion to hPa 38 float A = bmp.readAltitude(1019.66); //Calculating the Altitude, the "1019.66" is the pressure in (hPa) at sea level at day in your region 39 //If you don't know it just modify it until you get the altitude of your place 40 41 display.setCursor(0,0); //Oled display, just playing with text size and cursor to get the display you want 42 display.setTextColor(WHITE); 43 display.setTextSize(2); 44 display.print("Temp"); 45 46 display.setCursor(0,18); 47 display.print(T,1); 48 display.setCursor(50,17); 49 display.setTextSize(1); 50 display.print("C"); 51 52 display.setTextSize(1); 53 display.setCursor(65,0); 54 display.print("Pres"); 55 display.setCursor(65,10); 56 display.print(P); 57 display.setCursor(110,10); 58 display.print("hPa"); 59 60 display.setCursor(65,25); 61 display.print("Alt"); 62 display.setCursor(90,25); 63 display.print(A,0); 64 display.setCursor(110,25); 65 display.print("m"); 66 67 display.display(); 68 delay(2000); 69} 70
BMP280_Adafruit_library
You may want to change things like in the tutorial
Adafruit SSD1306
BMP280_Adafruit_library
You may want to change things like in the tutorial
bmp280_Serial_metric.ino
arduino
1/* This code is to use with Adafruit BMP280 (Metric) 2 * It 3 measures both temperature and pressure and it displays them on the Serial monitor 4 with the altitude 5 * It's a modified version of the Adafruit example code 6 7 * Refer to www.surtrtech.com or SurtrTech Youtube channel 8 */ 9 10#include 11 <Adafruit_BMP280.h> 12 13Adafruit_BMP280 bmp; // I2C Interface 14 15void setup() 16 { 17 Serial.begin(9600); 18 Serial.println(F("BMP280 test")); 19 20 if 21 (!bmp.begin()) { 22 Serial.println(F("Could not find a valid BMP280 sensor, 23 check wiring!")); 24 while (1); 25 } 26 27 /* Default settings from datasheet. 28 */ 29 bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ 30 31 Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 32 33 Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 34 35 Adafruit_BMP280::FILTER_X16, /* Filtering. */ 36 Adafruit_BMP280::STANDBY_MS_500); 37 /* Standby time. */ 38} 39 40void loop() { 41 Serial.print(F("Temperature 42 = ")); 43 Serial.print(bmp.readTemperature()); 44 Serial.println(" *C"); 45 46 47 Serial.print(F("Pressure = ")); 48 Serial.print(bmp.readPressure()/100); 49 //displaying the Pressure in hPa, you can change the unit 50 Serial.println(" 51 hPa"); 52 53 Serial.print(F("Approx altitude = ")); 54 Serial.print(bmp.readAltitude(1019.66)); 55 //The "1019.66" is the pressure(hPa) at sea level in day in your region 56 Serial.println(" 57 m"); //If you don't know it, modify it until you get your current 58 altitude 59 60 Serial.println(); 61 delay(2000); 62} 63
bmp280_Serial_Imperial.ino
arduino
1/* This code is to use with Adafruit BMP280 (Imperial) 2 * It measures 3 both temperature and pressure and it displays them on the Serial monitor with the 4 altitude 5 * It's a modified version of the Adafruit example code 6 * Refer 7 to www.surtrtech.com or SurtrTech Youtube channel 8 */ 9 10#include <Adafruit_BMP280.h> 11 12Adafruit_BMP280 13 bmp; // I2C 14 15void setup() { 16 Serial.begin(9600); 17 Serial.println(F("BMP280 18 test")); 19 20 if (!bmp.begin()) { 21 Serial.println(F("Could not find 22 a valid BMP280 sensor, check wiring!")); 23 while (1); 24 } 25 26 /* Default 27 settings from datasheet. */ 28 bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* 29 Operating Mode. */ 30 Adafruit_BMP280::SAMPLING_X2, /* Temp. 31 oversampling */ 32 Adafruit_BMP280::SAMPLING_X16, /* Pressure 33 oversampling */ 34 Adafruit_BMP280::FILTER_X16, /* Filtering. 35 */ 36 Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */ 37} 38 39void 40 loop() { 41 42 float f = bmp.readTemperature()*9/5 + 32 ; //Conversion 43 from C to F 44 Serial.print(F("Temperature = ")); 45 Serial.print(f); 46 47 Serial.println(" *F"); 48 49 float P = bmp.readPressure()/3386.39; 50 //displaying the Pressure in inches of mercury, you can change the unit 51 Serial.print(F("Pressure 52 = ")); 53 Serial.print(P); 54 Serial.println(" inHg"); 55 56 float 57 A = bmp.readAltitude(1019.66)*3.28084; //The "1019.66" is the pressure(hPa) 58 at sea level in day in your region 59 Serial.print(F("Approx altitude = ")); 60 //If you don't know it, modify it until you get your current altitude 61 62 Serial.print(A); 63 Serial.println(" ft"); 64 65 Serial.println(); 66 67 delay(2000); 68} 69
Adafruit SSD1306
bmp280_OLED_US.ino
arduino
1/* This code is to use with Adafruit BMP280 and OLED screen (Imperial) 2 3 * It measures both temperature and pressure and it displays them on the OLED display 4 with the altitude 5 * It's a modified version of the Adafruit example code 6 7 * Refer to www.surtrtech.com or SurtrTech Youtube channel 8 */ 9 10#include 11 <Adafruit_GFX.h> //Libraries for the OLED and BMP280 12#include <Adafruit_SSD1306.h> 13#include 14 <Adafruit_BMP280.h> 15 16#define SCREEN_WIDTH 128 // OLED display width, in pixels 17#define 18 SCREEN_HEIGHT 32 // OLED display height, in pixels 19#define OLED_RESET -1 // 20 Reset pin # (or -1 if sharing Arduino reset pin) 21 22Adafruit_SSD1306 display(SCREEN_WIDTH, 23 SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display) 24Adafruit_BMP280 25 bmp; 26 27void setup() { 28 bmp.begin(); //Start 29 the bmp 30 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start 31 the OLED display 32 display.clearDisplay(); 33 display.display(); 34 display.setTextColor(WHITE); 35 36 display.setTextSize(1); 37 display.print("SurtrTech"); //Show the name, 38 you can remove it or replace it 39 display.setCursor(32,12); 40 display.setTextSize(2); 41 42 display.println("BMP280"); 43 display.display(); 44 delay(2000); 45} 46 47void 48 loop() { 49 50 display.clearDisplay(); 51 float T = bmp.readTemperature()*9/5 52 + 32; //Read temperature in C and conversion to F 53 float P = bmp.readPressure()/3386.39; 54 //Read Pressure in Pa and conversion to inches of mercury 55 float A 56 = bmp.readAltitude(1019.66)*3.28084; //Calculating the Altitude, the "1019.66" 57 is the pressure in(hPa) at sea level at day in your region 58 //If 59 you don't know it just modify it until you get the altitude of your place 60 61 62 display.setCursor(0,0); //Oled display, just playing with 63 text size and cursor to get the display you want 64 display.setTextColor(WHITE); 65 66 display.setTextSize(2); 67 display.print("Temp"); 68 69 display.setCursor(0,18); 70 71 display.print(T,1); 72 display.setCursor(50,17); 73 display.setTextSize(1); 74 75 display.print("F"); 76 77 display.setTextSize(1); 78 display.setCursor(65,0); 79 80 display.print("Pres"); 81 display.setCursor(65,10); 82 display.print(P); 83 84 display.setCursor(100,10); 85 display.print("inHg"); 86 87 display.setCursor(65,25); 88 89 display.print("Alt"); 90 display.setCursor(90,25); 91 display.print(A,0); 92 93 display.setCursor(110,25); 94 display.print("ft"); 95 96 display.display(); 97 98 delay(2000); 99} 100
Adafruit GFX library
bmp280_OLED_m.ino
arduino
1/* This code is to use with Adafruit BMP280 and OLED screen (Metric) 2 3 * It measures both temperature and pressure and it displays them on the OLED display 4 with the altitude 5 * It's a modified version of the Adafruit example code 6 7 * Refer to www.surtrtech.com or SurtrTech Youtube channel 8 */ 9 10#include 11 <Adafruit_GFX.h> //Libraries for the OLED and BMP280 12#include <Adafruit_SSD1306.h> 13#include 14 <Adafruit_BMP280.h> 15 16#define SCREEN_WIDTH 128 // OLED display width, in pixels 17#define 18 SCREEN_HEIGHT 32 // OLED display height, in pixels 19#define OLED_RESET -1 // 20 Reset pin # (or -1 if sharing Arduino reset pin) 21 22Adafruit_SSD1306 display(SCREEN_WIDTH, 23 SCREEN_HEIGHT, &Wire, OLED_RESET); //Declaring the display name (display) 24Adafruit_BMP280 25 bmp; 26 27void setup() { 28 bmp.begin(); //Start 29 the bmp 30 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start 31 the OLED display 32 display.clearDisplay(); 33 display.display(); 34 display.setTextColor(WHITE); 35 36 display.setTextSize(1); 37 display.print("SurtrTech"); //Show the name, 38 you can remove it or replace it 39 display.setCursor(32,12); 40 display.setTextSize(2); 41 42 display.println("BMP280"); 43 display.display(); 44 delay(2000); 45} 46 47void 48 loop() { 49 50 display.clearDisplay(); 51 float T = bmp.readTemperature(); 52 //Read temperature in C 53 float P = bmp.readPressure()/100; //Read 54 Pressure in Pa and conversion to hPa 55 float A = bmp.readAltitude(1019.66); 56 //Calculating the Altitude, the "1019.66" is the pressure in (hPa) at sea 57 level at day in your region 58 //If 59 you don't know it just modify it until you get the altitude of your place 60 61 62 display.setCursor(0,0); //Oled display, just playing with 63 text size and cursor to get the display you want 64 display.setTextColor(WHITE); 65 66 display.setTextSize(2); 67 display.print("Temp"); 68 69 display.setCursor(0,18); 70 71 display.print(T,1); 72 display.setCursor(50,17); 73 display.setTextSize(1); 74 75 display.print("C"); 76 77 display.setTextSize(1); 78 display.setCursor(65,0); 79 80 display.print("Pres"); 81 display.setCursor(65,10); 82 display.print(P); 83 84 display.setCursor(110,10); 85 display.print("hPa"); 86 87 display.setCursor(65,25); 88 89 display.print("Alt"); 90 display.setCursor(90,25); 91 display.print(A,0); 92 93 display.setCursor(110,25); 94 display.print("m"); 95 96 display.display(); 97 98 delay(2000); 99} 100
Downloadable files
BMP280+OLED
Both modules uses the i²c interface, SDA/SCL with A4 and A5, the BMP280 is powred by 5v meanwhile the OLED is using the 3.3v.
BMP280+OLED
Comments
Only logged in users can leave comments