I try to get data from 2 Temp.sensors to a data logger.
To do, i took a running sketch of the 2 sensors ond copied the data part into it and modified it in several parts.
I checked several times and experiented with several "{ "and "} " ,s but kept this error message coming up.
Could you help me pls.
As it shows, i am a newby , it surprices me that a datafile is "opend" all the time.
"File dataFile = SD.open("datalog.txt", FILE_WRITE);" within the loop and not i the setup part.
Is this usual ?
// Logger - Version: 1.0.3
#include <Logger.h>
#include <SimpleDHT.h>
#include <SPI.h>
#include <SD.h>
// VCC: 5V or 3V
// GND: GND
// SENSOR 1 is in Digital Data pin: 7
// SENSOR 2 is in Digital Data pin: 8
const int chipSelect = 4;
int dataPinSensor1 = 7;
int dataPinSensor2 = 8;
SimpleDHT22 dht22;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
Serial.print("Initializing 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);
}
Serial.println("card initialized.");
void loop() {
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// Reading data from sensor 1...
Serial.println("=================================");
// Reading data from sensor 1...
Serial.println("Getting data from sensor 1...");
// read without samples.
byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;
if ((err = dht22.read(dataPinSensor1, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Communication error with Sensor 1, err="); Serial.println(err);delay(1000);
return;
}
// converting Celsius to Fahrenheit
byte f = temperature * 1.8 + 32;
Serial.print("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print( " ");
// Serial.print((int)f); Serial.print(" *F, ");
Serial.print((int)humidity); Serial.println(" H humidity");
//
// to datafile
dataFile.println("sen1");
dataFile.println(",");
dataFile.println((int)temperature);
dataFile.println(",");
dataFile.Println((int)humidity); Serial.println(" H humidity");
dataFile.println(",");
// Reading data from sensor 2...
// ============================
Serial.println("Getting data from sensor 2...");
byte temperature2 = 0;
byte humidity2 = 0;
if ((err = dht22.read(dataPinSensor2, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("Communication error with Sensor 2, err="); Serial.println(err);delay(1000);
return;
}
// converting Celsius to Fahrenheit
byte fb = temperature2 * 1.8 + 32;
Serial.print("Sample OK: ");
Serial.print((int)temperature); Serial.print(" *C, ");
Serial.print(" ");
// Serial.print((int)fb); Serial.print(" *F, ");
Serial.print((int)humidity); Serial.println(" H humidity");
Serial.println(" ");
// to datafile
dataFile.println("sen2");
dataFile.println(",");
dataFile.println((int)temperature);
dataFile.println(",");
dataFile.Println((int)humidity); Serial.println(" H humidity");
dataFile.println(",");
// DHT11 sampling rate is 1HZ.
delay(8500);
}
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/486397493/build -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -libraries /tmp/486397493/pinned -libraries /tmp/486397493/custom -fqbn arduino:avr:uno -build-cache /tmp -logger humantags -verbose=false /tmp/486397493/2DHT22_Runningand_datalog
Multiple libraries were found for "Logger.h"
Used: /tmp/486397493/pinned/logger-1-0-3
Not used: /home/admin/builder/opt/libraries/latest/logger-1-0-3
/tmp/486397493/2DHT22_Runningand_datalog/2DHT22_Runningand_datalog.ino: In function 'void setup()':
/tmp/486397493/2DHT22_Runningand_datalog/2DHT22_Runningand_datalog.ino:36:13: error: a function-definition is not allowed here before '{' token
/tmp/486397493/2DHT22_Runningand_datalog/2DHT22_Runningand_datalog.ino:109:1: error: expected '}' at end of input
/tmp/486397493/2DHT22_Runningand_datalog/2DHT22_Runningand_datalog.ino:109:1: error: expected '}' at end of input
exit status 1