ArduinoでESP32

https://dl.espressif.com/dl/package_esp32_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json

TTGOでBME280を動かすには、下記のプログラムを使う。TTGOとBME280の接続は以下の通り。

(BME280)SCK-(TTGO)27
(BME280)SDO-(TTGO)G
(BME280)SDI-(TTGO)26
(BME280)GND-(TTGO)G
(BME280)VDD-(TTGO)3V

//BME280_ESP32
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
unsigned long delayTime;

void setup() {
    Serial.begin(115200);

    Wire.begin(26,27);
    bool status;
    // default settings
    status = bme.begin(0x76); //read I2C address 0x76
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }
    delayTime = 1000;
    Serial.println();
}

void loop() {
    printValues();
    delay(delayTime);
}

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

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

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

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

    Serial.println();
}

コメントを残す