Okay so im just about finished with the coding finally! but I have one final problem. Im getting this error:
Arduino_SD_card_Verify.ino:127:4: error: 'id' does not name a type
Arduino_SD_card_Verify.ino:129:9: error: expected constructor, destructor, or type conversion before '(' token
Arduino_SD_card_Verify.ino: In function 'void loop()':
Arduino_SD_card_Verify.ino:132:6: error: redefinition of 'void loop()'
Arduino_SD_card_Verify.ino:105:8: error: 'void loop()' previously defined here
Error compiling.
I removed the void loop() found directly above
"String dataString =String(id) + ", " + String(V_pin);"
But when I tried to begin my data-logging nothing would show up due to this missing code. Im not sure how to fix this error, any guidance would be greatly appreciated!!
Here is the code;
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <SD.h>
#include <SPI.h>
// I2C library
#include <Wire.h>
//SPI settings
// MOSI, MISO, SCLK Set by default
int CS_pin = 4;
int pow_pin = 10;
//analog pins for Voltage readings
int V_pin = 0;
#define I2C_ADDR 0x27 // Define I2C Address where the SainSmart LCD is
#define BACKLIGHT_PIN 6
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// initialize the library with the numbers of the interface pins
int sensePin = 0;
int timer;
long id = 1;
//check voltage level
int Volt_level =analogRead(V_pin);
float refresh_rate = 0.0;
void setup()
{
analogReference(DEFAULT);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
timer=0;
Serial.begin(9600);
Serial.println("Initializing Card");
//CS Pin is an output
pinMode(CS_pin, OUTPUT);
//Card will draw power from pin 8, so set it high
pinMode(pow_pin, OUTPUT);
digitalWrite(pow_pin, HIGH);
if(!SD.begin(CS_pin)) //begin sd card process
{
Serial.println("Card Failed");
return; //ends program (terminate)
Serial.println("Card Ready");
}
//Read the Configuration info. (COMMANDS.txt)
File commandFile = SD.open("COMMANDS.txt");
if(commandFile)
{
Serial.println("Reading Command File");
float decade = pow(10, (commandFile.available() - 1));
while(commandFile.available())
{
float Volt = (commandFile.read() - '0');
refresh_rate = Volt*decade+refresh_rate;
decade = decade/10;
}
Serial.print("Refresh Rate = ");
Serial.print(refresh_rate);
Serial.println("ms");
}
else
{
Serial.println("Could not read command file.");
return;
}
//Write Log File Header
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.println(", , , ,"); // Just a leading blank line, incase there was previous data
String header = "ID, Voltage";
logFile.println(header);
logFile.close();
Serial.println(header);
}
else
{
Serial.println("Couldnt access file");
}
}
void loop ()
{
//Create Data string for storing to SD card
//Utilizing CSV Format for Execl spreadsheet
String dataString =String(id) + ", " + String(V_pin);
//Open a file to write to
//Only one file can be open at a time
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.println(dataString);
logFile.close();
Serial.println(dataString);
}
else
{
Serial.println("Couldnt open log file");
}
}
//Increment ID number
id++;
delay(refresh_rate);
void loop()
{
delay(refresh_rate);
// Print message to the LCD
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Voltage Reading:");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print((analogRead(sensePin))/238.0);
lcd.print("V");
delay(1000);
lcd.setCursor(0,2);
lcd.print("Time Elapsed:");
lcd.setCursor(0,3);
lcd.print(timer);
lcd.print(" Seconds");
timer=timer+1;
}