Friday, March 17, 2023

Dino weather station using Arduino

 Just copy the code:


#include <Wire.h>

#include <SPI.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BME280.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

/*#include <SPI.h>

#define BME_SCK 18

#define BME_MISO 19

#define BME_MOSI 23

#define BME_CS 5*/


#define SEALEVELPRESSURE_HPA (1013.25)


Adafruit_BME280 bme; // I2C

//Adafruit_BME280 bme(BME_CS); // hardware SPI

//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI


Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);

unsigned long delayTime;


void setup() {

  Serial.begin(9600);

  Serial.println(F("BME280 test"));

   

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)

   // init done

  display.display();

  delay(100);

  display.clearDisplay();

  display.display();

  display.setTextSize(1.2);

  display.setTextColor(WHITE);

  

  bool status;

  // default settings

  // (you can also pass in a Wire library object like &Wire2)

  status = bme.begin(0x76);  

  if (!status) {

    Serial.println("Could not find a valid BME280 sensor, check wiring!");

    while (1);

  }


  Serial.println("-- Default Test --");

  delayTime = 1000;


  Serial.println();

}



void loop() { 

  

  display.setCursor(0,0);

  display.clearDisplay();

  

  Serial.print("Temperature = "); Serial.print(bme.readTemperature()); Serial.println(" *C");

  display.print("Temperature: "); display.print(bme.readTemperature()); display.println(" *C");


  Serial.print("Pressure = "); Serial.print(bme.readPressure() / 100.0F); Serial.println(" hPa");

  display.print("Pressure: "); display.print(bme.readPressure() / 100.0F); display.println(" hPa");


  Serial.print("Humidity = "); Serial.print(bme.readHumidity()); Serial.println(" %");

  display.print("Humidity: "); display.print(bme.readHumidity()); display.println(" %");


  Serial.println();

  display.display();

  delay(1000);

}




No comments:

Post a Comment