I am working with a sketch that I developed in IDE 0023 with the bread board bootloader. The sketch has worked very well for me in that environment. However, I decided it is time to move to IDE 1.0.1 and I have updated the libraries with Arduino.h. Also with help from the forum I got the bread board boot loader to work with IDE 1.0.1. The sketch compiles and starts to run but then hangs part way through. When I load an older version of my sketch in IDE 1.0.1 that does not include EEPROM Anything it runs fine, but when I introduce my latest version with EEPROM Anything it always hangs. Any suggestions on why it would run well on IDE 0023 but hang when using IDE 1.0.1 when using EEPROM Anything? I attached my sketch because I get errors about the size when I try to place it here.
1.0's internal libraries use, in general, a little more program space and SRAM. I suspect you're running out of that: You have 25 nearly identical strings that are 15 bytes long ("This is time ...") and 15 sets of 25 byte arrays. Those two combined are 750 bytes, which is getting close to half of the available SRAM.
First: Learn how to use arrays. Then you won't have to copy and paste stuff so much. If you don't want to,
Make all of those strings variables so they only have to be declared once. So instead of saying
Serial.println("type text now");
serialData(); //looks for serial data for a fixed period of time
Serial.println("going to sleep now");
say
const char* typetextnow = "type text now";
const char* goingtosleepnow = "going to sleep now";
Serial.println(typetextnow);
serialData();
Serial.println(goingtosleepnow);
That will save you literally hundreds of bytes.
Also, consider putting those strings in PROGMEM. That will save you another 20 to 50 bytes.
Serial.flush() has changed meaning in 1.0+. Unless you have a REALLY good reason for using it, in either pre-1.0 or post-1.0, you should not be using it.
int time1 = 5400;
int time2 = 6300;
int time3 = 0;
int time4 = 0;
int time5 = 0;
int time6 = 0;
int time7 = 0;
int time8 = 0;
int time9 = 0;
int time10 = 0;
int time11 = 0;
int time12 = 0;
int time13 = 0;
int time14 = 0;
int time15 = 0;
int time16 = 0;
int time17 = 0;
int time18 = 0;
int time19 = 0;
int time20 = 0;
int time21 = 0;
int time22 = 0;
int time23 = 0;
int time24 = 0;
int time25 = 0;
Arrays are so overrated...
for(int x = 1 ; x < 18 ; x++){
pinMode(x, INPUT);
digitalWrite(x, HIGH); //changed from low to high which was 400ua change
}
//delay(1000);
Serial.begin(9600);
You are setting pin 1 to be an input pin, then using Serial. Why?
You both make some great points and I will work on improving in all of these areas. Learning arrays is something I have been working on recently but my attempts to implement it here have not worked properly so far so I kept with what I know for purposes of this poster. I know that this is how it should be done and I am actively working on learning it though. My goal is to get everything working in IDE 1.0.1 first so I can practice some of the concepts you both mentioned.
I did try trimming my sketch down to 6 variables from 25 and removed many of the print statements. I know my sketch is still not very clean but this should have made a significant difference in SRAM and it still hangs in IDE 1.0.1. Is there a way to track SRAM usage and find out for sure if this is the problem?
I will remove Serial.flush(). I was using it because I turn on/off the device it is connected to frequently and when it tuns on it was sending some junk. It takes at least a few minutes before I get any serial data so I was just flushing it to get rid of any junk while it waits for valid data. I did not know the meaning changed in the new IDE so I will look that up as well.
I was setting the pins high to keep current consumption in sleep mode low since I use a battery. Clearly based on your comment I implemented this wrong so I will try to read up on this more.
I will have to read more about NULL termination because I thought I was. I look for a "#" and use that to mark the end of the transmission.
Is there a way to track SRAM usage and find out for sure if this is the problem?
Yes. Search the forum and playground for FreeMemory.
I was using it because I turn on/off the device it is connected to frequently and when it tuns on it was sending some junk. It takes at least a few minutes before I get any serial data so I was just flushing it to get rid of any junk while it waits for valid data.
How does dumping random amounts of unread data accomplish anything? You could be tossing good data without knowing it.
Clearly based on your comment I implemented this wrong so I will try to read up on this more.
Just with respect to pin 1. That pin is part of the serial port.
I will have to read more about NULL termination because I thought I was. I look for a "#" and use that to mark the end of the transmission.
After each character is added to the array, and the index incremented, add a '\0' at the location now pointed to be the index. The # is an end-of-packet marker, not a NULL terminator (the '\0' is a NULL terminator).