Hello I have managed to get both the Adafruit Datalogging shield walk-through and this individual code working http://www.learn.parallax.com/reed-switch-arduino-demo separately, but trying to combine the two together I get these errors. I think I have it all arranged correctly but any help would be greatly appreciated. Board Arduino Uno and Adafruit Datalogger shield.
Errors:
Temp_and_Reed_Switch_data_logging_shield.ino:55:1: error: 'Serial' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:58:8: error: expected constructor, destructor, or type conversion before '(' token
Temp_and_Reed_Switch_data_logging_shield.ino:61:1: error: expected unqualified-id before 'if'
Temp_and_Reed_Switch_data_logging_shield.ino:66:1: error: 'Serial' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:70:1: error: expected unqualified-id before 'for'
Temp_and_Reed_Switch_data_logging_shield.ino:70:21: error: 'i' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:70:30: error: 'i' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:80:1: error: expected unqualified-id before 'if'
Temp_and_Reed_Switch_data_logging_shield.ino:84:1: error: 'Serial' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:85:1: error: 'Serial' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:87:1: error: 'Wire' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:88:1: error: expected unqualified-id before 'if'
Temp_and_Reed_Switch_data_logging_shield.ino:95:1: error: 'logfile' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:97:1: error: 'serial' does not name a type
Temp_and_Reed_Switch_data_logging_shield.ino:98:1: error: expected unqualified-id before 'if'
Temp_and_Reed_Switch_data_logging_shield.ino:104:8: error: expected constructor, destructor, or type conversion before '(' token
Temp_and_Reed_Switch_data_logging_shield.ino:105:8: error: expected constructor, destructor, or type conversion before '(' token
Temp_and_Reed_Switch_data_logging_shield.ino:107:8: error: expected constructor, destructor, or type conversion before '(' token
Temp_and_Reed_Switch_data_logging_shield.ino:108:13: error: expected constructor, destructor, or type conversion before '(' token
Temp_and_Reed_Switch_data_logging_shield.ino:114:1: error: expected declaration before '}' token
Multiple libraries were found for "SD.h"
Used: C:\Users\Andrew\Documents\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
'Serial' does not name a type
Program:
// SD card datalogger
// SD card attached to SPI bus as follows:
// MOSI - pin 11
// MISO - pin 12
// CLK - pin 13
// CS - pin 10
#include "SD.h"
#include <Wire.h>
#include "RTClib.h"
#include <SPI.h>
#define LOG_INTERVAL 1000 // mills between entries
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
// the digital pins that connect to the LEDs
#define redLEDpin 4
#define greenLEDpin 5
// The analog pins that connect to the sensors
#define tempPin 1 // analog 1
RTC_DS1307 RTC; // define the Real Time Clock object
const int chipSelect = 10;
const int switchPin = 2; // // Reed switch to digital pin 2
// the logging file
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
// red LED indicates error
digitalWrite(redLEDpin, HIGH);
while (1);
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.println();
//If we set WAIT_TO_START to anything but 0, the Arduino will wait until the user types something in.
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
}
// initialize the SD card
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(10, OUTPUT);
// 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:
return;
}
Serial.println("card initialized.");
// create a new file on SD Card called Logger number
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i / 10 + '0';
filename[7] = i % 10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
}
Serial.print("Logging to: ");
Serial.println(filename);
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("millis,time,temp,reedswitch");
#if ECHO_TO_SERIAL // attempt to write out the header to the file
serial.println("millis,time,temp,reedswitch");
if (logfile.writeError || !logfile.sync()) {
error("write header");
#endif //ECHO_TO_SERIAL
}
pinMode(redLEDpin, OUTPUT);
pinMode(greenLEDpin, OUTPUT);
pinMode(switchPin, INPUT); // switchPin is an input
digitalWrite(switchPin, HIGH); // Activate internal pullup resistor
long lastDebounce1 = 0;
long debounceDelay = 500; // Ignore bounces under 1/2 second
// If you want to set the aref to something other than 5v
//analogReference(EXTERNAL);
}
void loop(void)
{
DateTime now;
// delay for the amount of time we want between readings
delay((LOG_INTERVAL - 1) - (millis() % LOG_INTERVAL));
digitalWrite(greenLEDpin, HIGH);
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
#if ECHO_TO_SERIAL
Serial.print(m); // milliseconds since start
Serial.print(", ");
#endif
// fetch the time
now = RTC.now();
// log time
logfile.print(now.get()); // seconds since 2000
logfile.print(", ");
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
#if ECHO_TO_SERIAL
Serial.print(now.get()); // seconds since 2000
Serial.print(", ");
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
#endif //ECHO_TO_SERIAL
delay(10);
int tempReading = analogRead(tempPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = tempReading * 5.0 / 1024;
float temperatureC = (voltage - 0.5) * 100 ;
logfile.print(", ");
logfile.println(temperatureC);
logfile.print(", ");
logfile.print(reedswitch);
#if ECHO_TO_SERIAL
Serial.print(", ");
Serial.println(temperatureC);
Serial.print(", ");
Serial.print(reedswitch);
#endif //ECHO_TO_SERIAL
digitalWrite(greenLEDpin, LOW);
}