Hey guys, im new to arduino.
Just started my very first project, its an automated grow chamber, or at least will be.
Anyway, here i am learning to write some basic stuff, mostly i got off the internet and just tailored to my needs. But, theres one big problem!
I ran out of flash space. :~
I need some help with editing the libraries to fit my needs only and nothing more, if i'll want to add anything back i want to just "uncomment" it and let it be. I hope im clear enough.
I attached the sketch since its too long.
This is the most of it, i will add some more stuff later, but my problem is space right now, space that is occupied by gibrish code that i cant understand in those libraries.
Based on the code you see what can be trimmed off?
Thank you.
Given how close you are to the limit, you can get under 32K just by making your serial prints less verbose. They're also costing you RAM, but in this case, use of the F macro makes things (slightly) worse as there's a small increase in program size.
As Paul said, functions you don't use are already omitted (at least mostly; there are ways to write classes that won't omit default virtual functions, regardless of whether they're referenced explicitly, I think.)
You're probably using more RAM than you have, too. A lot of those Print strings should be put in flash with the F("string") format. (this does NOT take more room than having them in RAM, because the code needs a copy in flash that gets copied to RAM at startup, anyway.)
Here's a list of your biggest pieces of code; these would be the places to attack first. Most of it seems to be in the SD code, which ... does a lot of stuff. But you could check if it has an option for using static buffers instead of malloc/realloc; it would save quite a lot of space to be able to get rid of those...
(from "avr-nm -nSC --size-sort *.elf")
location size function name
00000078 00000100 t dscrc_table
0000694c 0000010e T HardwareSerial::begin(unsigned long)
000060d6 0000010e T malloc
00001c28 00000124 T Sd2Card::readData(unsigned long, unsigned int, unsigned int, unsigned char*)
000003d2 00000128 T setup
00003a60 0000012c T OneWire::search(unsigned char*)
00004896 0000012c T DNSClient::getHostByName(char const*, IPAddress&)
000061e4 00000130 T free
000031ec 00000138 T SdVolume::fatPut(unsigned long, unsigned long)
00001f6e 00000152 T SdFile::seekSet(unsigned long)
00004730 00000166 T DNSClient::BuildRequest(char const*)
00003c18 0000016e T DallasTemperature::calculateTemperature(unsigned char*, unsigned char*)
00001d6c 00000180 T Sd2Card::init(unsigned char, unsigned char)
000021a6 00000196 T SdFile::truncate(unsigned long)
00006314 000001b4 T realloc
00002c20 0000020e T SdFile::open(SdFile*, char const*, unsigned char)
0000359a 0000021e T SdVolume::allocContiguous(unsigned long, unsigned long*)
0000233c 0000022a T SdFile::read(void*, unsigned int)
00001422 0000023a T SDClass::getParentDir(char const*, int*)
0000165c 0000024a T SDClass::open(char const*, unsigned char)
00002f62 0000028a T SdVolume::init(Sd2Card*, unsigned char)
0000445c 000002d4 T DNSClient::ProcessResponse(unsigned int, IPAddress&)
00000e92 000002f2 T DHT22::readData()
000027c6 00000370 T SdFile::write(void const*, unsigned int)
000004fa 00000936 T loop
Thanks alot, im trying this right now, and im having some issues.
Just how exactly am i supposed to write the Sensor value part (DHT22AHum for example), into the HTML using the F macro?
Tried it like a regular F and it didnt work. Now the server doesnt work at all.
Heres what i came up with:
in the mean time i'll keep on Fing those Print()'s
westfw:
As Paul said, functions you don't use are already omitted (at least mostly; there are ways to write classes that won't omit default virtual functions, regardless of whether they're referenced explicitly, I think.)
You're probably using more RAM than you have, too. A lot of those Print strings should be put in flash with the F("string") format. (this does NOT take more room than having them in RAM, because the code needs a copy in flash that gets copied to RAM at startup, anyway.)
Here's a list of your biggest pieces of code; these would be the places to attack first. Most of it seems to be in the SD code, which ... does a lot of stuff. But you could check if it has an option for using static buffers instead of malloc/realloc; it would save quite a lot of space to be able to get rid of those...
I didnt understand half of what you just said. Again, im just a noob never ever before dealt with programming or C or Processing or Arduino IDE, so all of this is very new to me.
I would appreciate very much any short explanation to what does this memory table mean. Oh, and why does the SD takes so much memory if i only use it to write a simple .csv file?
Thank you everyone for your helpful replies!
Yep, well handling an entire file system takes code. It's pretty good if it fits into 15 kB. You may be "writing a simple file" but it has to know how to talk to the SD card, handle directories, files, dates, errors, etc.
Tried it like a regular F and it didnt work. Now the server doesnt work at all.
You only use the F macro on string literals, not variable data. Can you be more specific about what "doesn't work" means?
Ok, the problem was i was missing some blank line, its all good now.
Anyway, after quite some time tinkering with it, i decided the SD library is just way too big for me. So i wont be using it anymore.
So basically, now i activated the UDP NTP, and it shows time correctly and it doesnt interfere with the server's work, so thats good.
Now, this is the part where im really gonna need some help.
Now i wanna make the arduino into the Controller that it really is and start working on the automation of my grow box.
Basically all im gonna need to do is tell the arduino that in 06:00 it should light up the box, and at 00:00 it should turn it off, for example. I already have a 8 Relay module. Physically, i know how to connect everything. Its the software part that baffles me.
I still have 4 digital pins available and 3 more analogs, should be enough.
Any idea where to start guys?
Have you ever used a commercial sprinkler timer or similar? They tend to suck, having a set of functions dating back to when microcontorllers had 128 bytes of RAM that was volatile, but they are a model that can be used.
Create a data structure called an "event." An event has a start time, an action, a target, maybe a duration (you could have separate "off" events instead), and probably some flags that indicate whether the event has triggered or not. Put all your events in an array or list. In loop, scan through the events looking for any whose time has come, and perform the necessary action.
westfw:
Have you ever used a commercial sprinkler timer or similar? They tend to suck, having a set of functions dating back to when microcontorllers had 128 bytes of RAM that was volatile, but they are a model that can be used.
Create a data structure called an "event." An event has a start time, an action, a target, maybe a duration (you could have separate "off" events instead), and probably some flags that indicate whether the event has triggered or not. Put all your events in an array or list. In loop, scan through the events looking for any whose time has come, and perform the necessary action.
Thank you sir! You are a F#$%ing genius!
That was the 'thing' i was looking for! you just nailed it man.
Before i start, i have a couple Q's.
How can i make the Event log, that will hold all the 'events' in it? You mentioned an array or list, please give me an example how to write such said array or list. Based on the parameters or values that i want to read and write. Which i will specify once i have done all my tests with different types of soils in different moisture levels. Which will be read by the Soil Hygrometers i have. Which have 10 bits of resolution, so 1023-0, which i remapped to ascend once it feels moisture, just for my own comfort of "understanding the numbers".
I will have Floats. Both the DHT22's and the DS18B20's in stainless steel casings (all water proof with heat shrinking and everything!), show Float values. Thats my 2nd Q.
2. How can i incorporate reading all the sensors in the loop and by predetermined 'maxAllowed' and 'minAllowed' values, i can program the arduino to activate or deactivate different components?
For say: If hygrometer1Value shows 200 it means the soil is dry enough to water, or better yet, when the hygro1Value hits 200 the arduino starts counting 60 min. to watering. Using the UDP NTP! and if any one knows this time protocol (which works great by now!), how can i incorporate time+date, i want to get a date stamp too. For example: 21/01/2014 19:12:43.
Any help with that is much appreciated!
Im still learning a lot so please excuse my low set of skills and stupid questions, its my first time ever programming ANYTHING, so bear with me good arduino folks
Thank you!