Hello,
I recorded the sensor data of the BME280 and an RTC module and saved it to a file on an SD card. Now I want to transfer this file to a PC via Bluetooth or WLAN. Can someone help me how to do this? That's my code so far.
I use an Arduino Nano 33 IoT, Adafruit BME 280, DS1307 (Elegoo), HW-704 (Micro-SD-Shield), 16GB SD-Card
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <DS3231.h>
#include "RTClib.h"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
unsigned long delayTime;
bool start = true;
File myFile;
String Temperature, Pressure, Altitude, Humidity, Messung;
String Date;
RTC_DS1307 rtc;
//Adafruit BME 280
Adafruit_BME280 bme; // I2C
// Real Time Clock
DS3231 clock;
RTCDateTime dt;
void setup() {
Serial.begin(57600);
//*RTC Initialisierung*
if (! rtc.begin())
{
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}
if (! rtc.isrunning())
{
Serial.println("RTC is NOT running, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
clock.begin();
//Send sketch compiling time to Arduino
clock.setDateTime(__DATE__,__TIME__);
//*BME280 Initialisierung*
if (! bme.begin(0x77, &Wire))
{
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
bme.setSampling(Adafruit_BME280::MODE_NORMAL,
Adafruit_BME280::SAMPLING_X8, // temperature
Adafruit_BME280::SAMPLING_X16, // pressure
Adafruit_BME280::SAMPLING_X1, // humidity
Adafruit_BME280::FILTER_X8,
Adafruit_BME280::STANDBY_MS_0_5 );
//*SD card Initialisierung*
while (!Serial)
{
Serial.print("Initializing SD card...");
if (!SD.begin(10))
{
Serial.println("initialisation failed!");
while(1);
}
Serial.println("inistalisation done");
}
myFile = SD.open("Messung.txt", FILE_WRITE);
if (myFile)
{
myFile.println("Date | Time | Temperature (°C) | Pressure (hPa) | Humidity (%) \r\n");
myFile.close();
}
else
{
Serial.println("error opening Messung.txt");
}
delayTime = 5000;
}
void loop()
{
if (start == true)
{
delay(1000);
Serial.print("Date | Time | Temperature | Pressure | Humidity");
start = false;
}
// Only needed in forced mode! In normal mode, you can remove the next line.
bme.takeForcedMeasurement(); // has no effect in normal mode
printRTC();
printBME280();
delay(delayTime);
}
void printRTC()
{
DateTime time = rtc.now();
Serial.print (String("DateTime::TIMESTAMP_DATE:\t")+ time.timestamp(DateTime::TIMESTAMP_DATE));
Serial.print(String("DateTime::TIMESTAMP_TIME:\t")+ time.timestamp(DateTime::TIMESTAMP_TIME));
Serial.println("\n");
Serial.println("Beginne zu speichern");
myFile = SD.open("Messung.txt", FILE_WRITE);
if(myFile)
{
myFile.print(time.timestamp(DateTime::TIMESTAMP_DATE));
myFile.print(" | ");
myFile.print(time.timestamp(DateTime::TIMESTAMP_TIME));
myFile.print(" | ");
myFile.close();
Serial.println("gespeichert");
}
else
{
Serial.println("error opening Messung.txt nach RTC");
}
}
void printBME280()
{
String Temperature = String(bme.readTemperature(), 2);
String Pressure = String(bme.readPressure() / 100.0F,2);
String Humidity = String(bme.readHumidity(),2);
Messung = Temperature + " | " + Pressure + " | " + Humidity;
Serial.println("Save Sensordata");
Serial.println(Messung);
myFile = SD.open("Messung.txt", FILE_WRITE);
if(myFile)
{
Serial.println("Writing to Messung.txt...");
myFile.print(Messung);
myFile.print("\n");
myFile.close();
Serial.println("done");
}
else
{
Serial.println("error opening Messung.txt nach Sensor");
}
}