Sketch troppo grande :\

Salve ragazzi ritorno qui per un problema serio...
Ho uno sketch di 340 righe di codice circa se non di meno.. con i 300!
fatto sta che appena compilo mi dice sketch troppo grande! :frowning:

Dimensione del file binario dello sketch: 32.622 bytes (su un massimo di 30.720 bytes)
processing.app.debug.RunnerException: Sketch troppo grande; consultate http://www.arduino.cc/en/Guide/Troubleshooting#size per consigli su come ridurlo.
	at processing.app.Sketch.size(Sketch.java:1658)
	at processing.app.Sketch.build(Sketch.java:1591)
	at processing.app.Sketch.exportApplet(Sketch.java:1613)
	at processing.app.Sketch.exportApplet(Sketch.java:1599)
	at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
	at java.lang.Thread.run(Thread.java:701)

Uso arduino Duemilanove, c'è qualche possibilità di caricarlo? :frowning:
Grazie

Se leggi ti dice chiaramente :

Dimensione del file binario dello sketch: 32.622 bytes (su un massimo di 30.720 bytes)

... è quindi ovvio che stai occupando troppa memoria, quindi ... NO, così non c'è possibilità.

Posta il codice e vediamo se si può ottimizzare qualche cosa !

Guglielmo

manca un # iniziale
era troppo grande e nememno nel forum me lo faceva caricare!

Confido in voi!!
EDIT: credo che

          if(readString.indexOf("F=22") > 0)

si possa ottimizzare

Ma credi che mettendo PROGMEM i bytes vengano messi chissà dove ? Semplicemente non vengono copiati in SRAM, ma comunque occupano la flash !!!

Ti rendi conto quanti vettori hai ??? :astonished: :astonished: :astonished:
Ti rendi conto che ciascun vettore contiene, se no sbaglio 200 int che sono 400 bytes ??? :astonished: :astonished: :astonished:

Moltiplica il numero di bytes di ogni singolo vettore x il numero dei vettori ... e capirai perché hai finito la memoria !!!

Guglielmo

I vettori li ho messi con progmem perché senno mi si bloccava il webserver e purtroppo mi servono che sono le codifiche del condizionatore.
Non c e altro modo per ottimizzare il codice? ?

Si, riscriverlo ... ]:smiley:

... ad esempio eliminado completamente l'uso degli oggetti di tipo String e le loro relative funzioni, imparando ad usare quello di tipo string (array of char) e le relative funzioni; implementando invece che un'infinità di IF un SWITCH/CASE e così via ...

E comunque ... hai KBytes e KBytes occupati in PROGMEM ... ho idea che dovrai rinunciare a qualche cosa ... o cambiare proprio logica ed usare per memorizzare tutti quegli array ... files su SD card ... :roll_eyes:

Guglielmo

Mannaggia...
opterei sulla sd ma e fattibile leggere gli array da file e inviarli con un IR?
altre soluzioni?
Grazie
EDIT:

          if(readString.indexOf("L=2") > 0) {

come la metto sullo switch case che è una stringa?
dovrebbe venire una cosa del genere
switch(readString.indexOf){
case "L=2": //ecc..ecc
ma da errore
Potete farmi un esempio di come rimuovere quell'if ed usare switch case?
a quanto pare switch accetta solo numeri... percè se metto la a lo interpreta come 97.
Grazie

Scusate il doppio post, ho trovato un Sdcard da 256mb.
Vorrei copiarci tutti gli array così da liberare spazio su arduino e ogni volta leggerli da sd card e inviarli con iRlib.

/*
  SD card file dump
 
 This example shows how to read a file from the SD card using the
 SD library and send it over the serial port.
    
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4
 
 created  22 December 2010
 by Limor Fried
 modified 9 Apr 2012
 by Tom Igoe
 
 This example code is in the public domain.
     
 */

#include <SD.h>

// 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.
const int chipSelect = 4;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // 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("C30");

  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
}

void loop()
{
}

riesco a vedere sulla seriale il contenuto dell'array C30, ma come faccio a prendere quella stringa e salvarlo su array?
io sulla seriale vedo:

Initializing SD card...card initialized.
4492,4432,596,1600,592,508,592,1608...ecc...ecc...

come faccio a copiare questo valore su un unsigned int C30[] ??? temporanea in arduino? in modo che dopo aver inviato il buffer con con irlib svuoto esso...
Grazie

Ciao Roxdragon,
ho dato un'occhiata al tuo sketch ma mi sono soffermato soltanto sulla gestione del PROGMEM.
Ho notato che quello che metti in memoria pure essendo array lunghissimi sono composti sostanzialmente da pochi numeri ripetuti innumerevoli volte.
Quindi ho provato ad alleggerire l'uso della memoria flash:

prog_uint16_t P500 [] PROGMEM = {500 };
prog_uint16_t P504 [] PROGMEM = {504 };
prog_uint16_t P508 [] PROGMEM = {508 };
prog_uint16_t P512 [] PROGMEM = {512 };
prog_uint16_t P584 [] PROGMEM = {584 };
prog_uint16_t P588 [] PROGMEM = {588 };
prog_uint16_t P592 [] PROGMEM = {592 };
prog_uint16_t P596 [] PROGMEM = {596 };
prog_uint16_t P600 [] PROGMEM = {600 };
prog_uint16_t P1000[] PROGMEM = {1000};
prog_uint16_t P1596[] PROGMEM = {1596};
prog_uint16_t P1600[] PROGMEM = {1600};
prog_uint16_t P1604[] PROGMEM = {1604};
prog_uint16_t P1608[] PROGMEM = {1608};
prog_uint16_t P1612[] PROGMEM = {1612};
prog_uint16_t P4424[] PROGMEM = {4424};
prog_uint16_t P4428[] PROGMEM = {4428};
prog_uint16_t P4432[] PROGMEM = {4432};
prog_uint16_t P4436[] PROGMEM = {4436};
prog_uint16_t P4488[] PROGMEM = {4488};
prog_uint16_t P4492[] PROGMEM = {4492};
prog_uint16_t P4496[] PROGMEM = {4496};
prog_uint16_t P4500[] PROGMEM = {4500};
prog_uint16_t P4512[] PROGMEM = {4512};
prog_uint16_t P4516[] PROGMEM = {4516};
prog_uint16_t P4520[] PROGMEM = {4520};
prog_uint16_t P4524[] PROGMEM = {4524};
prog_uint16_t P5260[] PROGMEM = {5260};
prog_uint16_t P5264[] PROGMEM = {5264};
prog_uint16_t P5268[] PROGMEM = {5268};
prog_uint16_t P5272[] PROGMEM = {5272};

//ARIA CALDA                                                                                                                             
PROGMEM const uint16_t *C30[] = {P4492,P4432,P596,P1600,P592,P508,P592,P1608,P588,P1608,P596,P504,P588,P508,P596,P1604,P592,P504,P596,P504,P596,P1604,P592,P504,P600,P500,P592,P1604,P600,P1600,P596,P504,P596,P1600,P596,P504,P596,P504,P588,P1608,P596,P1600,P596,P1604,P588,P1608,P600,P1600,P592,P1604,P592,P1604,P600,P1600,P592,P508,P596,P500,P592,P508,P596,P504,P596,P504,P588,P508,P596,P1604,P588,P508,P596,P1604,P588,P1608,P600,P1600,P592,P1604,P592,P508,P592,P508,P596,P500,P592,P1608,P596,P500,P592,P508,P596,P504,P596,P504,P588,P1608,P596,P1604,P592,P5268,P4520,P4424,P592,P1608,P596,P504,P588,P1608,P596,P1604,P592,P504,P600,P500,P592,P1608,P596,P500,P592,P508,P592,P1604,P592,P508,P596,P504,P596,P1600,P596,P1604,P588,P508,P596,P1604,P592,P504,P596,P504,P600,P1600,P592,P1604,P592,P1604,P600,P1600,P596,P1600,P592,P1608,P588,P1608,P596,P1604,P592,P504,P596,P504,P600,P500,P592,P508,P592,P504,P600,P500,P592,P1604,P592,P508,P592,P1604,P592,P1608,P596,P1600,P592,P1608,P588,P508,P596,P504,P596,P504,P588,P1608,P596,P504,P600,P500,P592,P504,P596,P504,P588,P1612,P592,P1604,P592,P1000}; 
PROGMEM const uint16_t *C29[] = {P4488,P4436,P592,P1604,P592,P508,P592,P1604,P592,P1608,P596,P504,P588,P512,P592,P1604,P588,P512,P592,P504,P600,P1600,P592,P508,P596,P500,P592,P1608,P596,P1600,P596,P504,P596,P1600,P596,P504,P596,P504,P592,P1604,P600,P1600,P592,P1604,P592,P1608,P596,P1600,P596,P1604,P592,P1604,P588,P1612,P596,P500,P592,P508,P592,P508,P596,P500,P592,P508,P592,P508,P596,P1600,P596,P504,P596,P1604,P592,P504,P596,P1604,P592,P1604,P592,P508,P592,P508,P596,P500,P592,P1608,P596,P504,P588,P1608,P600,P500,P592,P508,P592,P1604,P592,P1604,P600,P5264,P4516,P4432,P596,P1600,P592,P508,P596,P1600,P596,P1604,P588,P512,P592,P504,P600,P1600,P592,P508,P596,P500,P592,P1608,P596,P504,P588,P508,P596,P1604,P588,P1608,P596,P504,P592,P1604,P600,P500,P592,P508,P592,P1604,P592,P1608,P596,P1600,P596,P1604,P592,P1604,P588,P1612,P596,P1600,P592,P1608,P588,P508,P592,P508,P596,P504,P588,P508,P596,P504,P596,P504,P588,P1608,P600,P500,P592,P1608,P596,P500,P592,P1608,P596,P1600,P596,P504,P600,P500,P588,P508,P596,P1604,P592,P508,P592,P1604,P592,P508,P596,P500,P600,P1600,P596,P1600,P592,P1000}; 
PROGMEM const uint16_t *C28[] = {P4496,P4424,P592,P1608,P596,P504,P592,P1604,P600,P1600,P592,P504,P600,P500,P592,P1608,P596,P500,P592,P508,P596,P1604,P588,P508,P596,P504,P600,P1600,P592,P1604,P592,P508,P592,P1604,P592,P508,P596,P504,P596,P1600,P596,P1604,P592,P1604,P600,P1600,P592,P1604,P592,P1604,P600,P1600,P596,P1600,P596,P504,P596,P504,P600,P500,P592,P504,P596,P504,P600,P500,P592,P1604,P600,P500,P592,P508,P596,P504,P596,P1600,P596,P1604,P588,P508,P596,P504,P600,P500,P592,P1604,P600,P1600,P596,P1600,P592,P508,P596,P504,P588,P1608,P596,P1604,P592,P5268,P4520,P4428,P600,P1596,P596,P504,P600,P1600,P596,P1600,P592,P508,P596,P504,P596,P1600,P596,P504,P600,P500,P592,P1604,P588,P512,P592,P508,P592,P1604,P592,P1604,P592,P508,P592,P1608,P588,P508,P596,P504,P596,P1604,P592,P1604,P588,P1612,P596,P1600,P592,P1608,P588,P1608,P596,P1604,P592,P1604,P588,P512,P592,P504,P600,P500,P588,P512,P592,P508,P596,P500,P600,P1600,P596,P504,P596,P500,P592,P508,P596,P1604,P592,P1604,P588,P512,P592,P508,P592,P504,P600,P1600,P596,P1600,P592,P1608,P588,P508,P592,P508,P596,P1604,P592,P1604,P588,P1000}; 

// Ho dovuto eliminare gli altri C e F perché sono troppi caratteri da inserire qui...  ma puoi capire da te come aggiungerli.
                                                                                                                                                                                                                                                            //OFF                                                                                                                                                                                                                                                
PROGMEM const uint16_t *OFF[] = {P4492,P4432,P592,P1608,P588,P508,P596,P1604,P588,P1608,P596,P504,P588,P512,P592,P1604,P600,P500,P592,P508,P596,P1600,P592,P508,P596,P504,P596,P1600,P596,P1604,P588,P512,P592,P1604,P592,P508,P592,P1604,P592,P1608,P596,P1600,P596,P1604,P588,P508,P596,P1604,P588,P1608,P596,P1604,P592,P508,P592,P508,P596,P500,P592,P508,P596,P1600,P592,P508,P596,P504,P596,P1600,P596,P1604,P592,P1604,P600,P500,P592,P508,P592,P508,P596,P500,P592,P508,P592,P508,P596,P504,P588,P508,P596,P1604,P588,P1608,P596,P1604,P592,P1608,P596,P1600,P596,P5264,P4524,P4424,P592,P1608,P596,P504,P588,P1608,P596,P1604,P592,P504,P596,P504,P600,P1600,P592,P508,P596,P500,P592,P1608,P596,P500,P592,P508,P596,P1604,P588,P1608,P596,P504,P588,P1608,P600,P500,P592,P1608,P596,P1600,P592,P1608,P588,P1608,P596,P504,P588,P1608,P596,P1604,P592,P1608,P596,P500,P592,P508,P596,P504,P596,P500,P592,P1608,P596,P504,P588,P508,P596,P1604,P592,P1604,P600,P1600,P592,P508,P596,P500,P592,P508,P592,P508,P596,P504,P588,P508,P596,P504,P596,P504,P588,P1608,P596,P1604,P592,P1604,P592,P1608,P596,P1600,P592,P1000}; 

static const uint16_t **IR[] PROGMEM = {C30, C29, C28, OFF};

Per il resto dello sketch.... non ce la posso fare!!! :sleeping: