Data logger "Install"

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: Data logger "Install"

Post by bmco2n »

Hello, You can see the line numbers on the sketch, which are close to the error locations in the error report.
when I put a "{" in front of "if", then the error is now "un----id missing in front of "{", so "{" may not be what it's talking about.

Thanks again. 8)

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger "Install"

Post by adafruit_support_bill »

Several problems here:

#1 - the error is on line 52 now, not line 65.
#2 - the line numbers comments you added do not correspond to actual line numbers in the program. This may be due to pasting the raw code into your post. If you use the code button above the edit box, it will preserve your formatting and make it easier for us to cut & paste your code into the IDE for testing.
#3 - the 'if' on line 53 is outside of the scope of any function. In particular, it is after the closing curly brace for the loop() function.
#4 - everything after the line you have labeled as "//75" is also outside the scope of any function.
#5 - "senState" is not the same as "sensState"

bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: Data logger "Install"

Post by bmco2n »

Hi Teach,
Over the weekend I found a clue to "unqualified-id" which was expected by the compiler before "if". I removed the "{" that was in the line above it. It took care of that single error, but a bunch of new ones came up on the next compile.

A lot of errors appear regarding "undeclared in this scope" For example, "const int chipSelect = 10" appears aas a global in the SD>datalogger example before setup(). In my program void() wants it in its scope (between { and }. In other words, global declarations and setup() programs that work in the examples don't in new programs I try to write.

I guess i'm really lost and will refresh my memory on C from square one. Thanks for all your generous help. :D

bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: Data logger "Install"

Post by bmco2n »

Oops, your help comment wasn't there just before I posted mine. I'll give your suggestions a try before I return to kindergarten.
Again, many thanks. :D

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Data logger "Install"

Post by adafruit_support_bill »

The main problem is that your curly braces were not balanced. It is a lot easier to keep track of that if you indent consistently and align the opening ones with the closing ones. Also, keep an eye on the spelling/capitalization. Compilers have no forgiveness.

Below is your code formatted and corrected enough to compile. (The indenting is exaggerated for clarity)

Code: Select all

#include <SD.h>
#include <Wire.h>
#include "RTClib.h"          //15

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.      20

//global
RTC_DS1307 RTC;  // getting time started 1

void setup()      //25
{  

	const int chipSelect = 10; 

	//30
	Serial.begin(9600);
	Serial.print("Initializing SD card...");    //24
	// make sure that the default chip select pin is set to
	// output, even if you don't use it:
	//35

	//  see if the card is present and can be initialized:

	Serial.println("Card failed, or not present");
	// don't do anything more:       40
	return;  


	Serial.println("card initialized.");    //TYPE CONVERSION?

	if (! RTC.isrunning()) 
	{                                    // 45
		// following line sets the RTC to the date & time this sketch was compiled

		RTC.adjust(DateTime(__DATE__, __TIME__));    
	} 
	//50
}

void loop()
{
	const int chipSelect = 10;
	const int digitalPin = 2;
	pinMode(chipSelect, OUTPUT);    //55
	pinMode(digitalPin, INPUT);

	int lastsenState = 0;
	int senState = 0;    //Read sensor                      60

	senState = digitalRead(digitalPin);

	if (senState != lastsenState) 
	{                                        //65
		DateTime now = RTC.now();   

		Serial.print(now.hour(), DEC);
		Serial.print('  ');            
		Serial.print(now.minute(), DEC);    //70
		Serial.println('  ');
	}
	else 
	{ 
		(lastsenState = senState); 
	}  
	//75




	// 80 open the file. note that only one file can be open at a time,
	// so you have to close this one before opening another.

	{  
                               File dataFile = SD.open("datalog.txt", FILE_WRITE);

		// 85 if the file is available, write to it:
		if (dataFile) 
		{
			dataFile.println();
			dataFile.close();      
			// print to the serial port too: 
			Serial.println(digitalPin);           //90

		} // if the file isn't open, pop up an error:
		else 
		{
			Serial.println("error opening datalog.txt");    //80
			//95
		}
	}
}


bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: Data logger "Install"

Post by bmco2n »

Datalogger “install”
Greeetings ----- It seems I now have written code for the datalogger that will 1) tell the time when an event happens from digital pin 2 and 2) send the data to the SD card. I wrote the sketch one line at a time, making sure Serial.print worked with the time, because in pasting parts of an pervious sketch, the names of variables are retained; confusing when you used a different name in the one being written. I doubt if the sketch is good, as it takes 9 to ten minutes to compile and another 9 to upload. I notice that I’m uploading 16K bytes into a maximum of 32K, so my program is probably not efficient.
Just for FYI, my first Adafruit datalogger didn’t work. It was the soldering, of course and a questionable ONO, but checking the connections and voltages of all kinds of pins didn’t help, so I bought another Adafruit datalogger and soldered it very carefully. The LEDS wouldn’t light up (they are good) and the voltage for the green LED is 0.3 to 0.4 volts, less than the 0.6V they need. Both shields would tell the time with RTClib, but wouldn’t initialize the SD card using SD>datalogger in examples. One problem was that one of the ONOs was not good. The card reader informed me that the SD card from Adafruit was no good, so I formatted my camera SD card. One of the shields did work, if it was used on the right Arduino ONO (SMD R2). But that was temporary. This problem was solved by hooking a jumper between the 10K resistor (4V) to the SD card holder! It seems OK, because there’s only 0.5 milliamps going through the jumper and nothing was getting hot.
I’ll spare you all the data I measured---all resistances and voltages between all digital, analog, card holder pins and the DIP14 legs. D10, D11 D2 looked OK regarding voltages, I guess, but the rest, D13, D 12 and several others showed huge resistances and some negative voltages. I think a small short is draining power, judging from small voltages where there shouldn't be any (I think). Anyway, I got one of shields to talk to the SD card by using this jumper and everything seems to work, at least for now.
Many thinks for your concern and great work at the forum. Such a resource is invaluable to people like me. :D :roll:
Cheers,
Bruce

bmco2n
 
Posts: 76
Joined: Thu Apr 14, 2011 4:34 pm

Re: Data logger "Install"

Post by bmco2n »

Datalogger “install”Success----Additional finds.
Greeetings ----- It seems I now have written code for the datalogger that will 1) tell the time when an event happens from digital pin 2 and 2) send the data to the SD card. I wrote the sketch one line at a time, making sure Serial.print worked with the time, because in pasting parts of an pervious sketch, the names of variables are retained; confusing when you used a different name in the one being written. I doubt if the sketch is good, as it takes 9 to ten minutes to compile and another 9 to upload. I notice that I’m uploading 16K bytes into a maximum of 32K, so my program is probably not efficient.
Just for FYI, my first Adafruit datalogger didn’t work. It was the soldering, of course and also, a questionable ONO, but checking the connections and voltages of all kinds of pins didn’t help, so I bought another Adafruit datalogger and soldered it very carefully. The LEDS wouldn’t light up (they are good) and the voltage for the green LED is 0.3 to 0.4 volts, less than the 0.6V they need. Both shields would tell the time with RTClib, but wouldn’t initialize the SD card using SD>datalogger in examples. One problem was that one of the ONOs was not good and the card reader informed me that the SD card from Adafruit was no good, so I formatted my camera SD card. At this point, one of the shields did work, if it was used on the right Arduino ONO (SMD R2). But that was temporary.
-----This problem was solved by hooking a jumper between the 10K resistor (~4V) to the SD card holder! TALK ABOUT LUCK! ONLY 0.5 MILLIAMPS THROUGH THE JUMPER ----CAUTIONARY TALE --- BEFORE TRYING TO DETERMINE IF A JUMPER WILL MAKE IT WORK, TEST THE AMPS ACROSS THE POINTS, FIRST.
I’ll spare you all the data I measured---all resistances and voltages between all digital, analog, card holder pins and the DIP14 legs. D10, D11 D2 looked OK regarding voltages, I guess, but the rest, D13, D 12 and several others showed huge resistances and some negative voltages. Anyway, I got one of shields to talk to the SD card by using this jumper and everything seems to work, at least for now.
Many thinks for your work at the forum. LadyAda is a boon to retired scientists! The bad SD card is OK, I’ll just order another from Adafruit + anything else I can do to keep you in business.
Cheers,
Bruce

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”