a function definition not allowed before "{ "
i try data 2 temp.sensors data logger.
to do, took running sketch of 2 sensors ond copied data part , modified in several parts.
i checked several times , experiented several "{ "and "} " ,s kept error message coming up.
could me pls.
as shows, newby , surprices me datafile "opend" time.
"file datafile = sd.open("datalog.txt", file_write);" within loop , not setup part.
is usual ?
./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 found "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: function-definition not allowed here before '{' token
/tmp/486397493/2dht22_runningand_datalog/2dht22_runningand_datalog.ino:109:1: error: expected '}' @ end of input
/tmp/486397493/2dht22_runningand_datalog/2dht22_runningand_datalog.ino:109:1: error: expected '}' @ end of input
exit status 1
to do, took running sketch of 2 sensors ond copied data part , modified in several parts.
i checked several times , experiented several "{ "and "} " ,s kept error message coming up.
could me pls.
as shows, newby , surprices me datafile "opend" time.
"file datafile = sd.open("datalog.txt", file_write);" within loop , not setup part.
is usual ?
code: [select]
// 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 in digital data pin: 7
// sensor 2 in digital data pin: 8
const int chipselect = 4;
int datapinsensor1 = 7;
int datapinsensor2 = 8;
simpledht22 dht22;
void setup() {
// open serial communications , wait port open:
serial.begin(9600);
while (!serial) {
; // wait serial port connect. needed native usb port only
serial.print("initializing sd card...");
// see if card present , can initialized:
if (!sd.begin(chipselect)) {
serial.println("card failed, or not present");
// don't more:
while (1);
}
serial.println("card initialized.");
void loop() {
file datafile = sd.open("datalog.txt", file_write);
// reading data sensor 1...
serial.println("=================================");
// reading data sensor 1...
serial.println("getting data 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 sensor 1, err="); serial.println(err);delay(1000);
return;
}
// converting celsius 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");
//
// datafile
datafile.println("sen1");
datafile.println(",");
datafile.println((int)temperature);
datafile.println(",");
datafile.println((int)humidity); serial.println(" h humidity");
datafile.println(",");
// reading data sensor 2...
// ============================
serial.println("getting data sensor 2...");
byte temperature2 = 0;
byte humidity2 = 0;
if ((err = dht22.read(datapinsensor2, &temperature, &humidity, null)) != simpledhterrsuccess) {
serial.print("communication error sensor 2, err="); serial.println(err);delay(1000);
return;
}
// converting celsius 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(" ");
// 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 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 found "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: function-definition not allowed here before '{' token
/tmp/486397493/2dht22_runningand_datalog/2dht22_runningand_datalog.ino:109:1: error: expected '}' @ end of input
/tmp/486397493/2dht22_runningand_datalog/2dht22_runningand_datalog.ino:109:1: error: expected '}' @ end of input
exit status 1
where setup() function end ?
Arduino Forum > Using Arduino > Programming Questions > a function definition not allowed before "{ "
arduino
Comments
Post a Comment