This is my first post here. I'm new to the Arduino world. I'm using a Rev3 UNO board. The project goal is to read analog data, log and time stamp it. I copied example programs and verified the hardware OpenLog and the DS1307 BOB both from sparkfun. So now I'm trying to Frankenpaste tht software together into a single sketch. The current problem the "gotoCommandMode()" which is a library command to put OpenLog into a command mode so that a file can be created and opened to receive the data. I get a "was not created in this scope" error. My feeble understanding of what little I've read says that "gotoCommandMode()" does not need to be in the main loop since it performs no calculation. In the the snippet of code immediately below my errors is the code that needs to be inserted. But whether I insert it in the main loop or not ,I get compile errors. I'm pretty sure it's a program structure thing as opposed to syntax., but I'm getting nowhere on my own. I guess now I have time to read the manual.
My errors
Logging_and_wth_ds1307_oct27c.ino: In function 'void setup()':
Logging_and_wth_ds1307_oct27c:62: error: 'gotoCommandMode' was not declared in this scope
Logging_and_wth_ds1307_oct27c.ino: In function 'void loop()':
Logging_and_wth_ds1307_oct27c:88: error: 'createFile' was not declared in this scope
Logging_and_wth_ds1307_oct27c:143: error: expected `}' at end of input
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the code that functions in another sketch but not this one.
randomSeed(analogRead(A0)); //Use the analog pins for a good seed value
int fileNumber = random(999); //Select a random file #, 0 to 999
char fileName[12]; //Max file name length is "12345678.123" (12 characters)
sprintf(fileName, "log%03d.txt", fileNumber);
gotoCommandMode(); //Puts OpenLog in command mode
createFile(fileName); //Creates a new file called log###.txt where ### is random
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Serial.print("Random file created: ");
Serial.println(fileName);
#include <SoftwareSerial.h>
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68 // This is the I2C address
// Arduino version compatibility Pre-Compiler Directives
#if defined(ARDUINO) && ARDUINO >= 100 // Arduino v1.0 and newer
#define I2C_WRITE Wire.write
#define I2C_READ Wire.read
#else // Arduino Prior to v1.0
#define I2C_WRITE Wire.send
#define I2C_READ Wire.receive
#endif
// Global Variables
int command = 0; // This is the command char, in ascii form, sent from the serial port
int i;
long previousMillis = 0; // will store last time Temp was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte test;
byte zero;
char *Day[] = {"","Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char *Mon[] = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
//*******************************Logger Vars*******************************************
int CH0 = A0;
int CH1 = A1;
int CH2 = A2;
int CH3 = A3;
float dat0 = 0;
float dat1 = 0;
float dat2 = 0;
float dat3 = 0;
int rxPin = 3;
int txPin = 2;
int x=0;
int resetOpenLog = 4;
int statLED = 13;
SoftwareSerial OpenLog(rxPin, txPin); //Soft RX on 3, Soft TX out on 2
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
void setup() {
Wire.begin();
//Serial.begin(57600);
zero=0x00;
pinMode(statLED, OUTPUT);
SoftwareSerial OpenLog(rxPin, txPin); //Soft RX on 3, Soft TX out on 2
Serial.begin(9600);
Serial.println("OpenLog online");
gotoCommandMode(); //Puts OpenLog in command mode : [THIS IS THE PROBLEM]
}
void loop(){
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
I2C_WRITE(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
second = bcdToDec(I2C_READ() & 0x7f);
minute = bcdToDec(I2C_READ());
hour = bcdToDec(I2C_READ() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(I2C_READ());
dayOfMonth = bcdToDec(I2C_READ());
month = bcdToDec(I2C_READ());
year = bcdToDec(I2C_READ());
randomSeed(analogRead(A0)); //Use the analog pins for a good seed value
int fileNumber = random(999); //Select a random file #, 0 to 999
char fileName[12]; //Max file name length is "12345678.123" (12 characters)
sprintf(fileName, "log%03d.txt", fileNumber);
createFile(fileName); //Creates a new file called log###.txt where ### is random
Serial.print("Random file created: ");
Serial.println(fileName);
//Write something to OpenLog
for(int x=0; x < 720; x++){ /* this loop reads the the 4 AI points and writes them to the
to the logger at 5 sec intervals*/
dat0 = analogRead(CH0);
dat1 = analogRead(CH1);
dat2 = analogRead(CH2);
dat3 = analogRead(CH3);
//Need to scale the values here prior to writing them to the OpenLogger
OpenLog.print("Data Set ");
OpenLog.println(x);
OpenLog.print("CH0 = ");
OpenLog.println(dat0);
OpenLog.print("CH1 = ");
OpenLog.println(dat1);
OpenLog.print("CH2 = ");
OpenLog.println(dat2);
OpenLog.print("CH3 = ");
OpenLog.println(dat3);
OpenLog.println();
OpenLog.println();
if (hour < 10)
Serial.print("0");
Serial.print(hour, DEC);
Serial.print(":");
if (minute < 10)
Serial.print("0");
Serial.print(minute, DEC);
Serial.print(":");
if (second < 10)
Serial.print("0");
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(Day[dayOfWeek]);
Serial.print(", ");
Serial.print(dayOfMonth, DEC);
Serial.print(" ");
Serial.print(Mon[month]);
Serial.print(" 20");
if (year < 10)
Serial.print("0");
Serial.println(year, DEC);
delay (2000);
}