Hallo,
ich bin komplett neu bei Arduino und wäre für Hilfe sehr dankbar!
Für ein Schulprojekt möchte ich einen Datalogger für einen Stratosphährenflug mit einem Ballon bauen. Ich bin dabei im Internet auf diese Anleitung gestoßen. Ich habe mir also folgende Hardware:
- Adafruit Feather M0 Adalogger
- AM2302 Sensor
- Adafruit BME280 Sensor
- Adafruit Ultimate GPS FeatherWing
besorgt und auf einem Breadboard zusammengesteckt. Dann habe ich in der Arduino IDE Software die zur Verfügung gestellte Sketch Datei und beschriebenen Libraries geladen. Leider klappte es mit der Übertragung nicht auf Anhieb. Zunächst wurde die "dht.h" Datei nicht gefunden. nach dem installieren der dht_Sensor library, was nicht in der Anleitung stand wird diese nun gefunden aber es ist ein komplexer neuer Fehler aufgetreten bei dem ich dringend eure Hilfe benötige!
Hier der Code:
/*
SD card datalogger
Feather M0 Datalogger Mainmodule
BME280 Sensor / I2C
GPS Modul Featherwing /RS232
DHT22 Sensor /1Pin
*/
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "BME280_I2C.h" // we use the I2C version
#include <Adafruit_GPS.h>
#include <DHT.h>
#define DHT22_PIN 5 // 1Pin on Pin5
#define GPSSerial Serial1 // Definition of GPS Serial
#define GPSECHO false
// Create the BME280 object
BME280_I2C bme; // I2C using default 0x77
// or BME280_I2C bme(0x76); // I2C using address 0x76
Adafruit_GPS GPS(&GPSSerial); // Definition of Structure GPS
dht DHT; // Definition of Structure DHT
struct
{
uint32_t total;
uint32_t ok;
uint32_t crc_error;
uint32_t time_out;
uint32_t connect;
uint32_t ack_l;
uint32_t ack_h;
uint32_t unknown;
} stat = { 0,0,0,0,0,0,0,0};
File dataFile; // The file we write to ( write mode is always append!!
const int chipSelect = 4; // SD Card select
// ************ Definition of log mode ***********************
int max_no_of_files = 100; // Max File number
int max_no_of_logs = 120; // Logs per file
int log_int_sec = 5; // Log Interval in seconds
int new_file_flag = 0; // flag for begin of new file
int gps_dat_flag = 0; // flag for new dat (GPS)
//************ some internal counters **********************
int no_of_files = 0;
int no_of_logs = 0;
int no_of_secs = 0;
int chk_DHT; // gets the DHT value
//************* used to measure log interval (not absolut exact but no cumulated fault)
unsigned long current_millis = 0;
unsigned long next_sec_millis;
char filename[14]; // filename max. 8 Chars!
//************* used to build up the log String **************
String dataString;
String gpsString;
String dhtString;
void setup()
{
// Open serial communications and wait for port to open:
pinMode(13, OUTPUT); // red and green LED
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(13, LOW);
strcpy(filename, "data_00.txt"); // default filename
init_GPS_string(); // Fills first GPS string after start with zeros
Serial.begin(115200);
//************ GPS Initializing *********************************
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
delay(3000); // wait three seconds to miss no serial output
print_header(); // Version and Log Setting
//**************** Check for BME 280 *************************
if (!bme.begin()) {
Serial.println("Could not find BME280");
while (1){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(4500);
}
}
else{
Serial.println("BME280 present!");
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
}
bme.setTempCal(-1);
//****************** Check for DHT22 **********************
chk_DHT = DHT.read22(DHT22_PIN);
if (chk_DHT == DHTLIB_OK || chk_DHT == DHTLIB_ERROR_CHECKSUM){
Serial.println("DHT22 present!");
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
}
else{
Serial.println("Could not find DHT22");
while (1){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(3500);
}
}
//***************** Check for SD Card *****************
Serial.println("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(SS, OUTPUT);
check_SD_card();
//**************** Check for Datafile ******************
check_DataFile();
}
void loop()
{
prepare_Data(); // Setup Datastring Lognumber
//************ Read BME280 and add values to Log ***************
bme.readSensor();
// read three sensors and append to the string:
dataString += String("BP ");
dataString += String(bme.getPressure_MB());
dataString += String("0,BH ");
dataString += String(bme.getHumidity());
dataString += String("0,BT ");
dataString += String(bme.getTemperature_C());
dataString += String("0,");
//************ Read DHT22 and add values to Log ***************
read_DHT();
dataString += dhtString;
//************ Add prepared GPS string to log *****************
//************ First string after prog start is always zero ***
//************ GPS is read out at end of each measuring cycle**
dataString += gpsString;
check_max_log(); // Check if end of file or end of log is reached
write_SD_string();
digitalWrite(8, LOW);
digitalWrite(13, LOW);
// read GPS till log interval finished
read_GPS();
next_sec_millis += 1000*log_int_sec;
}
void print_header()
{
Serial.println("Datalogger V1.37");
Serial.print("Log Interval: ");
Serial.println(String(log_int_sec));
Serial.print("No. of logs per file: ");
Serial.println(String(max_no_of_logs));
Serial.print("Max No. of files: ");
Serial.println(String(max_no_of_files));
Serial.println(" ");
}
void check_SD_card()
{
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more
while (1){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(2500);
}
}
Serial.println("card initialized.");
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(1500);
}
void check_DataFile(){
// Open up the file we're going to log to!
//dataFile = SD.open(filename,FILE_WRITE);
dataFile = SD.open(filename,FILE_WRITE);
if (! dataFile) {
Serial.print("error opening ");
Serial.println(filename);
// Wait forever since we cant write data
while (1){
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(1500);
}
}
else{
Serial.print("opening...");
Serial.println(filename);
new_file_flag = 1;
next_sec_millis = millis();
next_sec_millis += 1000*log_int_sec;
}
}
void prepare_Data()
{
// string for assembling the data to log:
//String dataString = "";
dataString = String("LS ");
if (no_of_secs < 10){
dataString += "0000";
}
else{
if (no_of_secs < 100){
dataString += "000";
}
else{
if (no_of_secs < 1000){
dataString += "00";
}
else{
if (no_of_secs < 10000){
dataString += "0";
}
}
}
}
dataString += String(no_of_secs);
dataString += ",";
}
void check_max_log()
{
if (no_of_logs == max_no_of_logs){
Serial.print("closing: ");
Serial.println(filename);
dataFile.close();
no_of_logs = 0;
no_of_files += 1;
if (no_of_files < max_no_of_files){
new_file_flag = 1;
strcpy(filename, "data_00.txt");
filename[5] = '0' + no_of_files/10;
filename[6] = '0' + no_of_files%10;
dataFile = SD.open(filename,FILE_WRITE);
if (! dataFile) {
Serial.print("error opening: ");
Serial.println(filename);
// Wait forever since we cant write data
while (1) ;
}
else{
Serial.print("opening: ");
Serial.println(filename);
}
}
else{
Serial.print("Log finished! ");
while (1){
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(500);
digitalWrite(8, HIGH);
delay(500);
digitalWrite(8, LOW);
delay(5000);
}
}
}
}
void write_SD_string()
{
if (no_of_logs < max_no_of_logs){
dataFile.println(dataString);
// print to the serial port too:
Serial.println(dataString);
if(new_file_flag == 0){
digitalWrite(8, HIGH); // turn the green LED on (HIGH is the voltage level)
delay(250);
digitalWrite(8, LOW);
}
else{
digitalWrite(13, HIGH);
digitalWrite(8, HIGH);
delay(250);
digitalWrite(13, LOW);
digitalWrite(8, LOW);
new_file_flag = 0;
}
no_of_logs++;
no_of_secs += log_int_sec;
}
}
void read_GPS()
{
while (current_millis < next_sec_millis){
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
gps_dat_flag = 0;
}
current_millis = millis();
}
gpsString = String("GT ");
gpsString += String(GPS.hour, DEC);
gpsString += String(":");
gpsString += String(GPS.minute, DEC);
gpsString += String(":");
gpsString += String(GPS.seconds, DEC);
gpsString += String(",");
gpsString += String("GD ");
gpsString += String(GPS.day, DEC);
gpsString += String("/");
gpsString += String(GPS.month, DEC);
gpsString += String(",");
gpsString += String("GF ");
gpsString += String((int)GPS.fix);
gpsString += String("/");
gpsString += String((int)GPS.fixquality);
gpsString += String(",");
gpsString += String("GS ");
gpsString += String((int)GPS.satellites);
gpsString += String(",");
gpsString += String("GL ");
gpsString += String(GPS.longitude, 3);
gpsString += String(",");
gpsString += String("GB ");
gpsString += String(GPS.latitude, 3);
gpsString += String(",");
gpsString += String("GH ");
gpsString += String(GPS.altitude);
gpsString += String("00");
//Serial.println(gpsString);
}
void init_GPS_string(){
gpsString = String("GT ");
gpsString += String("00");
gpsString += String(":");
gpsString += String("00");
gpsString += String(":");
gpsString += String("00");
gpsString += String(",");
gpsString += String("GD ");
gpsString += String("0");
gpsString += String("/");
gpsString += String("0");
gpsString += String(",");
gpsString += String("GF ");
gpsString += String("0");
gpsString += String("/");
gpsString += String("0");
gpsString += String(",");
gpsString += String("GS ");
gpsString += String("0");
gpsString += String(",");
gpsString += String("GL ");
gpsString += String("0000.000");
gpsString += String(",");
gpsString += String("GB ");
gpsString += String("0000.000");
gpsString += String(",");
gpsString += String("GH ");
gpsString += String("000.000");
}
void read_DHT()
{
// READ DATA
chk_DHT = DHT.read22(DHT22_PIN);
if (chk_DHT == DHTLIB_OK){
dhtString = String("DH ");
dhtString += String(DHT.humidity, 1);
dhtString += String("00,");
dhtString += String("DT ");
dhtString += String(DHT.temperature, 1);
dhtString += String("00,");
}
else{
dhtString = String("DH ");
dhtString += String("--.-");
dhtString += String("--,");
dhtString += String("DT ");
dhtString += String("--.-");
dhtString += String("--,");
}
}
Hier die Fehlermeldung:
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:24:1: error: 'dht' does not name a type
24 | dht DHT; // Definition of Structure DHT
| ^~~
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino: In function 'void setup()':
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:117:16: error: expected primary-expression before '.' token
117 | chk_DHT = DHT.read22(DHT22_PIN);
| ^
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:118:20: error: 'DHTLIB_OK' was not declared in this scope
118 | if (chk_DHT == DHTLIB_OK || chk_DHT == DHTLIB_ERROR_CHECKSUM){
| ^~~~~~~~~
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:118:44: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
118 | if (chk_DHT == DHTLIB_OK || chk_DHT == DHTLIB_ERROR_CHECKSUM){
| ^~~~~~~~~~~~~~~~~~~~~
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino: In function 'void read_DHT()':
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:447:18: error: expected primary-expression before '.' token
447 | chk_DHT = DHT.read22(DHT22_PIN);
| ^
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:449:20: error: 'DHTLIB_OK' was not declared in this scope
449 | if (chk_DHT == DHTLIB_OK){
| ^~~~~~~~~
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:451:26: error: expected primary-expression before '(' token
451 | dhtString += String(DHT.humidity, 1);
| ^
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:451:30: error: expected primary-expression before '.' token
451 | dhtString += String(DHT.humidity, 1);
| ^
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:454:26: error: expected primary-expression before '(' token
454 | dhtString += String(DHT.temperature, 1);
| ^
C:\Arduino\Projekte\Datalogger_37\Datalogger_37.ino:454:30: error: expected primary-expression before '.' token
454 | dhtString += String(DHT.temperature, 1);
| ^
Mehrere Bibliotheken wurden für "DHT.h" gefunden
Benutzt: C:\Arduino\libraries\DHT_sensor_library
Nicht benutzt: C:\Users\IJR\AppData\Local\Arduino15\libraries\DHT_sensor_library
Mehrere Bibliotheken wurden für "SD.h" gefunden
Benutzt: C:\Arduino\libraries\SD
Nicht benutzt: C:\Users\IJR\AppData\Local\Arduino15\libraries\SD
Nicht benutzt: C:\Users\IJR\AppData\Local\Arduino15\libraries\SD-master
exit status 1
Compilation error: 'dht' does not name a type
Ich freue mich von Euch zu hören!
Ilian