#include <Arduino.h>
#include <SPI.h>
/*
GND -> GND
3.3 -> 3.3
CS -> 5
MOSI -> 23
MISO -> 19
SCK -> 18
*/
#include "sd_read_write.h"
#include "SD_MMC.h"
#define SD_MMC_CMD 15 //Please do not modify it.
#define SD_MMC_CLK 14 //Please do not modify it.
#define SD_MMC_D0 2 //Please do not modify it.
#include "SparkFunBME280.h"
BME280 mySensor;
float valArry[4];
void setup()
{
Serial.begin(115200);
Serial.println("Example showing alternate I2C addresses");
//BME280 setup
if (mySensor.beginSPI(5) == false) //Begin communication over SPI. Use pin 10 as CS.
{
Serial.println("The sensor did not respond. Please check wiring.");
//while(1); //Freeze
}else{
Serial.println("BME280 connected.");
}
mySensor.setReferencePressure(101200); //Adjust the sea level pressure used for altitude calculations
//sdcard setup
SD_MMC.setPins(SD_MMC_CLK, SD_MMC_CMD, SD_MMC_D0);
if (!SD_MMC.begin("/sdcard", true, true, SDMMC_FREQ_DEFAULT, 5)) {
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD_MMC.cardType();
if(cardType == CARD_NONE){
Serial.println("No SD_MMC card attached");
return;
}
Serial.print("SD_MMC Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024);
Serial.printf("SD_MMC Card Size: %lluMB\n", cardSize);
if(!SD_MMC.exists("/envData.txt")){
String s = String("Day,Hour,Min,Temp,Humidity,Pressure,Discomfort_index\n");
writeFile(SD_MMC, "/envData.txt", s.c_str());
}
readFile(SD_MMC, "/envData.txt");
}
void loop()
{
unsigned long currentTime = millis(); // 現在の時間をミリ秒で取得
// ミリ秒を秒、分、時間、日に変換
int seconds = currentTime / 1000;
int minutes = seconds / 60;
int hours = minutes / 60;
int days = hours / 24;
// 余りを計算して、秒、分、時間を表示
minutes = minutes % 60;
hours = hours % 24;
valArry[0] = mySensor.readTempC();
valArry[1] = mySensor.readFloatHumidity();
valArry[2] = mySensor.readFloatPressure()/100;
//Discomfort index
valArry[3] = (((0.81*valArry[0] + 0.01*valArry[1]*(0.99*valArry[0]-14.3))+46.3));
String s = String(days) + ",";
s = s + String(hours) + ",";
s = s + String(minutes) + ",";
s = s + String(valArry[0]) + ",";
s = s + String(valArry[1]) + ",";
s = s + String(valArry[2]) + ",";
s = s + String(valArry[3]) + "\n";
Serial.print(s.c_str());
appendFile(SD_MMC, "/envData.txt", s.c_str());
delay(600000);
}
コメント
コメントを投稿