Pages: [1] 2   Go Down
Author Topic: 30720 bytes maximum sketch size, if not enogh?  (Read 7554 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what if we need more space in large project?

i know loop helps but if we need more space?

Logged

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Main/ArduinoBoardMega

« Last Edit: May 17, 2010, 11:52:00 am by stephen_t » Logged


Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i know loop helps but if we need more space?

You youngsters thinking 30k is too small an area to work in; why, back in my day with 8-bit home computers it would be a luxury to have such an amount of memory!

/oldster rant mode off

 smiley

If you are at a point where you need more memory for code, and you have exhausted all possibilities for reducing the size of your code to fit (ever heard of a 4k intro?), then you either move to another micro-controller with a larger program memory (such as the Mega), or you use other approaches.

Perhaps before you finalize your design, look and see if it can be made distributed and parallelized - if it can, then you could possibly use multiple Arduinos (or ATMegas), communicating over SPI/I2C in a master/slave relationship, and break the code up among each.

For instance, say you were building an Arduino-based handheld game system - you could try to put everything into a single Arduino (sound, LCD control, button sensing - oh, and the game itself), but this wouldn't be the best method.

It would be better to have one Arduino be the dedicated "master" - which would probably also hold the game and the SPI/I2C interface to the other Arduino/ATMegas. These other devices, hanging off the SPI/I2C bus, would each control one aspect of the system. One could control the LCD (maybe a KS0108 display), one could read the buttons, and one could play music and sound effects. The master device would be responsible to coordinate and interface with all of this, but you would likely write a special library for that anyhow to abstract the details away from the actual game code.

A similar thing could be done with a robot; one master could coordinate other slave devices to act as motor controllers, sensor interfaces, or other tasks. Note that this strategy should always be given thought, and should be a possible tool in your toolbag - whether you are working with micro-controllers or networked mainframes.

 smiley
« Last Edit: May 17, 2010, 12:01:42 pm by keeper63@cox.net » Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Pluggy; what's that weird standalone brace for after the analogRead()?

 ;D
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A little something I was playing around with earlier, its the tail end of an if then structure........

Code:
/*
 
 Stephen's Blink and long term clock clock accuracy
 
 */

int ledPin =  13; // LED connected to digital pin 13
unsigned long time;
unsigned long secloop = 1000;
unsigned long fred;
unsigned long count = 0;
int ana;
boolean liteon = false;


// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);    
  Serial.begin(115200);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                    
{
  count = count + 1;
  time = millis();
  if (count >= 100){fred = count / 10 * 22;
  ana = analogRead(1);};
  if (time >= secloop){
    secloop = secloop + 500;
    //Serial.println(secloop/100,DEC);
    if (liteon){
      digitalWrite(ledPin, HIGH);
      Serial.print(count,DEC);
      Serial.print(" : ");
      Serial.print(ana,DEC);
      Serial.print(" : ");
      Serial.println(secloop/1000,DEC);
      count = 0;
      liteon = false;
    }
    else
    {
      digitalWrite(ledPin, LOW);
      liteon = true;
    };
  };
}

Looking again, it starts on the line above in the screenshot.   smiley-wink

Probably a superfluous semi-colon in there somewhere........
« Last Edit: May 17, 2010, 12:11:08 pm by stephen_t » Logged


0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 250
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

arduinoMega is great but i am using stand alone chip.
Logged

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Split it up into several modules and use more than one chip as suggested by cr0sh.

I have a large project that uses 2 328s and 2 168s communicating by serial.  
Logged


0
Offline Offline
Faraday Member
**
Karma: 23
Posts: 3470
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you need this size for program or for data? In case of data an eprom / SD card may do the trick.

Udo
Logged

Check out my experiments http://blog.blinkenlight.net

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

cr0sh, the open curly brace is in the line above.  I don't like this bracing style, myself, for exactly this reason.
Logged

Greenwood, Indiana
Offline Offline
God Member
*****
Karma: 0
Posts: 508
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd wondered about using an SDcard to hold code which can be swapped in and out. I have no idea about how to accomplish that.
Logged

If it was designed by man it can be repaired by man.

0
Offline Offline
Faraday Member
**
Karma: 23
Posts: 3470
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

An SD card would be good only for data. However, if you are running an interpreter, then code basically becomes data. Then of course the SD card can hold your code. If you do not mind to go for something like forth this can give you pretty good performance as well. However I see no way to put "Arduino code" into an SD card such that it can be executed with reasonable performance. Unless you course you go so far as to self flash the Arduino from the SD card. Something that is most probably very far stretched.

Udo
Logged

Check out my experiments http://blog.blinkenlight.net

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you have exhausted all possibilities for reducing the size of your code to fit

Sorry for bringing back a live such old topic, but while still developing code, I see the maximum size of my sketch closing in quickly. Even already came to issues where the sketch did not fit on a UNO anymore, fortunately the Duemilanove does still handle it.

But I do want to add more functionality and now seek ways to optimize my code. Anyone can guide me into some directions? There must be some general optimization guides or ... ?
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But I do want to add more functionality and now seek ways to optimize my code. Anyone can guide me into some directions? There must be some general optimization guides or ... ?

Hallo Erwin,

yes, there are general optimisation guides. They include pearls of wisdoms like reusing code, not including stuff you don't need, reducing string table sizes by tail end compression and many other things. But all those things work only, if your code suffers from the problem a measure is trying to alleviate. So before you go out and optimise away, you should try to understand what takes all the space in your code.

Korman
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 38
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Instead of arduino mega as some suggested, why not sanguino?
It has twice the memory of an 328 arduino, not to mention the number of analog and digital i/o and its in DIP smiley-grin
« Last Edit: November 30, 2010, 09:57:34 am by GregaG87 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can't we just replace the chip with other but only with more available memory?
Logged

Pages: [1] 2   Go Up
Jump to: