Hello all,
I'm new to all this, but I think I've got a fairly decent understanding of how to code an Arduino. The basic terminology and functions etc., although arithmetic was never one of my stronger characteristics but I manage. Arduino Playground - HomePage has been like a bible to me lately.
Now I'm digging into the SdFat library. I have a SeeedStudio SD Shield V3 but I'm having a lot of trouble trying to code it. As of now, its seems like they went with "Here is there examples, GOOD LUCK SUCKERS! They don't help me understand the terminology at all. I haven't found any good resources online. cout? bout? ofstream? AHHHH! XD What is this << :: >>? XD sdlog, end1 Where are you getting all this from!? XD
Thank you,
(EVENT LOG SAMPLE)
void logEvent(const char *msg) {
// create dir if needed
sd.mkdir("LOGS/2011/JAN");
// create or open a file for append
3. ofstream sdlog("LOGS/2011/JAN/LOGFILE.TXT", ios::out | ios::app);
(MY INTERPRETATION)
Now were just making up voids().
sd. is the object, mkdir = make directory (Linux :D). Not too bad here.
Is that French? / WHAT? / ("directory") / what / what is :: / out must append the file / |=or / app isn't an integer or announced anywhere else in the code so... sure?.
/*
* Append a line to a file - demo of pathnames and streams
*/
#include <SdFat.h>
// SD chip select pin
const uint8_t chipSelect = SS;
// file system object
SdFat sd;
// define a serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
/*
* Append a line to LOGFILE.TXT
*/
void logEvent(const char *msg) {
// create dir if needed
sd.mkdir("LOGS/2011/JAN");
// create or open a file for append
ofstream sdlog("LOGS/2011/JAN/LOGFILE.TXT", ios::out | ios::app);
// append a line to the file
sdlog << msg << endl;
// check for errors
if (!sdlog) sd.errorHalt("append failed");
// file will be closed when sdlog goes out of scope
}
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
// pstr stores strings in flash to save RAM
cout << pstr("Type any character to start\n");
while (Serial.read() < 0) {}
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
// append a line to the logfile
logEvent("Another line for the logfile");
cout << "Done - check /LOGS/2011/JAN/LOGFILE.TXT on the SD" << endl;
}
//------------------------------------------------------------------------------
void loop() {}
dritchie0042:
// create or open a file for append
3. ofstream sdlog("LOGS/2011/JAN/LOGFILE.TXT", ios::out | ios::app);
...
3. Is that French? / WHAT? / ("directory") / what / what is :: / out must append the file / |=or / app isn't an integer or announced anywhere else in the code so... sure?.
When I said "I searched online, but found nothing", perhaps that wasn't put in to the right context.
Sure you can the definitions for anything you wish on the web. Whats the point though when you can't understand it. The amount of work going term through term in that manner isn't very efficient.
For example:
"C++98C++11
In terms of static initialization order, cout is guaranteed to be properly constructed and initialized no later than the first time an object of type ios_base::Init is constructed."
Is that how you guys learned C++? Many,many hours upon headaches? lol We all have to start somewhere, I'm surprised there isn't a more user friendly version or method for learning an SD Shield.
No. I bought a book, which seems to be something you are trying to avoid doing.
Google is great for looking up what a function does, but the trick is to know what to look up. You seem to be trying yo look up what the arguments to the function mean, without looking up what the function does.
Not surprisingly, if you look up ofstream, you'll find that it creates an output stream, and from there you'll find what the constructor does (that is what is being called there), and from there what the arguments are/mean.
Of course, looking up ofstream in the index of the book you didn't buy would give you a lot more background on ofstream, fstream, streams, etc.
Get the BOOKS AND USE THEM instead of asking others to think for you... and GET OFF THE PITY POT...
I'm a 67 year old retired electronics engineer learning C++ for the first time...
And enjoying the challenge immensely. You??
nickn4:
EDIT: my brother told me to edit my post. and i had to tell you it weren't many many hours..
he said i had to tell you it were many many months!
Yep, I didn't learn C++ in a few hours. It look a lot longer.
My advice is to start with simple examples and build on those.