Out of dynamic memory!!!

Hello to everyone and happy new year,i have a question about a project of home automation.
One of the things i want to control is 4 air co devices via ir.I 'm working with nrf24 with 10 nodes in the house,everything works perfect but i have an issue on ir codes airco units.The problem is if put all the codes from ir remote the arduino is running with limit ram memory.Here is the code of an node at living room.
i would be appreciate any kind of help to reduce memory problems.

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <DHT.h>;
#include <IRLibSendBase.h> //We need the base code
#include <IRLib_HashRaw.h> //Only use raw sender

//off
#define RAW_DATA_LEN 140
uint16_t rawDataOff[RAW_DATA_LEN] = {
8934, 4542, 658, 550, 650, 554, 662, 1646,
602, 606, 662, 542, 658, 1650, 662, 546,
658, 546, 658, 550, 598, 606, 658, 1650,
654, 550, 654, 550, 666, 542, 662, 542,
666, 546, 658, 546, 658, 550, 662, 542,
598, 606, 606, 602, 654, 1654, 602, 602,
602, 610, 658, 546, 598, 606, 602, 606,
662, 542, 662, 1646, 662, 546, 662, 1646,
602, 606, 658, 546, 602, 1706, 598, 610,
598, 20030, 598, 1710, 658, 546, 602, 1706,
662, 542, 662, 546, 654, 550, 662, 542,
658, 550, 662, 546, 666, 538, 602, 606,
602, 602, 658, 550, 602, 602, 662, 1642,
662, 542, 662, 546, 662, 542, 658, 550,
662, 546, 658, 546, 662, 546, 658, 546,
654, 550, 662, 546, 598, 606, 602, 606,
658, 546, 602, 602, 606, 1702, 658, 1650,
654, 550, 662, 1000
};

//--------------------------Heat-------------------------------
//on thermansi 20
#define RAW_DATA_LEN 140
uint16_t rawDataOn20[RAW_DATA_LEN] = {
9022, 4482, 662, 542, 662, 546, 658, 1650,
658, 1646, 666, 542, 662, 1646, 662, 542,
662, 542, 662, 550, 658, 546, 662, 1646,
662, 542, 662, 546, 658, 550, 658, 542,
662, 546, 662, 546, 658, 546, 658, 546,
662, 546, 662, 542, 662, 1646, 662, 1646,
658, 550, 650, 550, 662, 546, 658, 550,
658, 546, 658, 1650, 658, 546, 658, 1650,
662, 546, 658, 550, 594, 1710, 658, 546,
662, 19970, 658, 1646, 658, 550, 662, 1642,
662, 546, 654, 554, 658, 546, 658, 550,
654, 550, 662, 546, 654, 550, 658, 550,
658, 546, 658, 550, 658, 546, 654, 1654,
658, 546, 662, 546, 658, 546, 662, 542,
598, 610, 662, 546, 658, 546, 662, 546,
658, 546, 658, 550, 658, 546, 654, 550,
666, 542, 658, 550, 658, 1646, 662, 1646,
658, 1650, 658, 1000
};

//on thermansi 21
#define RAW_DATA_LEN 140
uint16_t rawDataOn21[RAW_DATA_LEN] = {
8942, 4534, 602, 610, 598, 602, 602, 1706,
602, 1706, 598, 610, 598, 1706, 602, 606,
598, 606, 602, 1710, 598, 606, 602, 1706,
602, 602, 602, 606, 602, 602, 602, 606,
598, 606, 602, 606, 598, 610, 598, 606,
602, 606, 598, 606, 598, 1710, 598, 1710,
598, 606, 602, 602, 602, 606, 598, 602,
606, 606, 598, 1710, 602, 606, 598, 1710,
598, 606, 598, 606, 602, 1706, 602, 606,
598, 20030, 602, 1710, 598, 606, 602, 1706,
598, 606, 598, 610, 598, 606, 602, 602,
662, 546, 602, 606, 598, 606, 602, 606,
598, 610, 598, 602, 662, 546, 598, 1706,
602, 606, 598, 606, 602, 606, 602, 602,
602, 606, 598, 606, 602, 606, 654, 550,
658, 550, 658, 546, 602, 606, 602, 606,
602, 602, 602, 1706, 598, 1706, 602, 1710,
598, 1706, 602, 1000
};

//on thermansi 22
#define RAW_DATA_LEN 140
uint16_t rawDataOn22[RAW_DATA_LEN] = {
8994, 4482, 658, 546, 662, 546, 602, 1702,
602, 1706, 658, 546, 662, 1642, 666, 542,
598, 610, 662, 542, 658, 1650, 598, 1710,
598, 606, 662, 546, 662, 542, 666, 538,
602, 606, 658, 550, 658, 546, 602, 606,
654, 550, 658, 550, 654, 1654, 658, 1650,
658, 546, 658, 546, 606, 606, 654, 550,
662, 542, 662, 1646, 602, 606, 662, 1642,
666, 542, 658, 550, 658, 1646, 662, 546,
662, 19970, 662, 1650, 594, 610, 662, 1642,
662, 546, 598, 606, 662, 546, 658, 546,
602, 606, 598, 606, 602, 602, 658, 554,
662, 542, 654, 550, 658, 550, 598, 1706,
654, 554, 658, 546, 666, 542, 662, 542,
658, 550, 658, 546, 662, 546, 654, 550,
662, 546, 662, 542, 658, 550, 658, 546,
602, 606, 662, 542, 662, 546, 658, 546,
662, 546, 662, 1000
};

//on thermansi 23
#define RAW_DATA_LEN 140
uint16_t rawDataOn23[RAW_DATA_LEN] = {
8990, 4482, 598, 606, 598, 610, 598, 1710,
662, 1646, 598, 606, 662, 1646, 602, 606,
598, 610, 658, 1650, 654, 1650, 598, 1714,
594, 610, 658, 542, 602, 606, 662, 546,
662, 546, 598, 606, 598, 610, 658, 546,
598, 610, 654, 550, 602, 1710, 598, 1710,
598, 606, 658, 546, 654, 554, 598, 606,
654, 554, 658, 1650, 662, 522, 622, 1706,
598, 606, 658, 546, 654, 1654, 662, 546,
658, 19978, 658, 1646, 662, 546, 662, 1642,
662, 542, 662, 542, 666, 542, 666, 542,
662, 542, 658, 554, 658, 546, 658, 546,
662, 542, 662, 546, 662, 542, 598, 1714,
658, 546, 662, 546, 654, 550, 662, 546,
662, 542, 662, 542, 662, 546, 662, 542,
662, 546, 662, 546, 658, 546, 662, 542,
662, 546, 658, 1646, 662, 546, 662, 542,
662, 546, 658, 1000
};

IRsendRaw mySender;
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor

RF24 radio(10, 9); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t master00 = 00;
const uint16_t node03 = 03;

const int relay1 = 4;
const int relay2 = 5;
const int relay3 = 6;
const int relay4 = 7;
const int relay5 = 8;
const int relay6 = 14;
const int relay7 = 15;
const int relay8 = 16;

char AcSaloni;
int PAPCstate;
int lastPAPCstate; // the previous reading from the input pin

struct package
{
float tempSaloni;
float humSaloni;
};
typedef struct package Package;
Package data;
/////------------------------------------------

void setup() {
SPI.begin();
Serial.begin(9600);
dht.begin();
radio.begin();
network.begin(95, 03); //(channel, node address)
radio.setDataRate(RF24_1MBPS);
radio.setPALevel(RF24_PA_MAX);

pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);

digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8, HIGH);

}

void loop() {

network.update();

// ===== Receiving =====
while ( network.available() ) { //Is there any incoming data
RF24NetworkHeader header;
network.read(header, &AcSaloni, sizeof(AcSaloni)); //Read the incoming data
if (header.from_node == 00) {
if (AcSaloni == 2) {
mySender.send(AcSaloni, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
}
else if (AcSaloni == 3) {
mySender.send(rawDataOn20, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
}
else if (AcSaloni == 4) {
mySender.send(rawDataOn21, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
}
else if (AcSaloni == 5) {
mySender.send(rawDataOn22, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
}
else if (AcSaloni == 6) {
mySender.send(rawDataOn23, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
}

}
}

delay(10);

//data.tempSaloni = dht.readTemperature();
//data.humSaloni = dht.readHumidity();

//RF24NetworkHeader header(master00); // (Address where the data is going)
//bool ok = network.write(header, &data, sizeof(data)); // Send the data

//Serial.println(data.tempSaloni);
//Serial.println(data.humSaloni);
}

ever hear of PROGMEM ?

sherzaad:
ever hear of PROGMEM ?
i have read it,if you have time can you give me an example in the code above?

did you follow the link??

the example there should be clear enough for you to tweak YOUR code accordingly.

Please follow the advice on posting code given in posting code

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <DHT.h>;
#include <IRLibSendBase.h>    //We need the base code
#include <IRLib_HashRaw.h>    //Only use raw sender

#include <pgmspace.h>

//off
#define RAW_DATA_LEN 140
uint16_t rawDataOff[RAW_DATA_LEN] = {
  8934, 4542, 658, 550, 650, 554, 662, 1646,
  602, 606, 662, 542, 658, 1650, 662, 546,
  658, 546, 658, 550, 598, 606, 658, 1650,
  654, 550, 654, 550, 666, 542, 662, 542,
  666, 546, 658, 546, 658, 550, 662, 542,
  598, 606, 606, 602, 654, 1654, 602, 602,
  602, 610, 658, 546, 598, 606, 602, 606,
  662, 542, 662, 1646, 662, 546, 662, 1646,
  602, 606, 658, 546, 602, 1706, 598, 610,
  598, 20030, 598, 1710, 658, 546, 602, 1706,
  662, 542, 662, 546, 654, 550, 662, 542,
  658, 550, 662, 546, 666, 538, 602, 606,
  602, 602, 658, 550, 602, 602, 662, 1642,
  662, 542, 662, 546, 662, 542, 658, 550,
  662, 546, 658, 546, 662, 546, 658, 546,
  654, 550, 662, 546, 598, 606, 602, 606,
  658, 546, 602, 602, 606, 1702, 658, 1650,
  654, 550, 662, 1000
};

//--------------------------Heat-------------------------------
//on thermansi 20
#define RAW_DATA_LEN 140
uint16_t rawDataOn20[RAW_DATA_LEN] = {
  9022, 4482, 662, 542, 662, 546, 658, 1650,
  658, 1646, 666, 542, 662, 1646, 662, 542,
  662, 542, 662, 550, 658, 546, 662, 1646,
  662, 542, 662, 546, 658, 550, 658, 542,
  662, 546, 662, 546, 658, 546, 658, 546,
  662, 546, 662, 542, 662, 1646, 662, 1646,
  658, 550, 650, 550, 662, 546, 658, 550,
  658, 546, 658, 1650, 658, 546, 658, 1650,
  662, 546, 658, 550, 594, 1710, 658, 546,
  662, 19970, 658, 1646, 658, 550, 662, 1642,
  662, 546, 654, 554, 658, 546, 658, 550,
  654, 550, 662, 546, 654, 550, 658, 550,
  658, 546, 658, 550, 658, 546, 654, 1654,
  658, 546, 662, 546, 658, 546, 662, 542,
  598, 610, 662, 546, 658, 546, 662, 546,
  658, 546, 658, 550, 658, 546, 654, 550,
  666, 542, 658, 550, 658, 1646, 662, 1646,
  658, 1650, 658, 1000
};

//on thermansi 21
#define RAW_DATA_LEN 140
uint16_t rawDataOn21[RAW_DATA_LEN] = {
  8942, 4534, 602, 610, 598, 602, 602, 1706,
  602, 1706, 598, 610, 598, 1706, 602, 606,
  598, 606, 602, 1710, 598, 606, 602, 1706,
  602, 602, 602, 606, 602, 602, 602, 606,
  598, 606, 602, 606, 598, 610, 598, 606,
  602, 606, 598, 606, 598, 1710, 598, 1710,
  598, 606, 602, 602, 602, 606, 598, 602,
  606, 606, 598, 1710, 602, 606, 598, 1710,
  598, 606, 598, 606, 602, 1706, 602, 606,
  598, 20030, 602, 1710, 598, 606, 602, 1706,
  598, 606, 598, 610, 598, 606, 602, 602,
  662, 546, 602, 606, 598, 606, 602, 606,
  598, 610, 598, 602, 662, 546, 598, 1706,
  602, 606, 598, 606, 602, 606, 602, 602,
  602, 606, 598, 606, 602, 606, 654, 550,
  658, 550, 658, 546, 602, 606, 602, 606,
  602, 602, 602, 1706, 598, 1706, 602, 1710,
  598, 1706, 602, 1000
};

//on thermansi 22
#define RAW_DATA_LEN 140
uint16_t rawDataOn22[RAW_DATA_LEN] = {
  8994, 4482, 658, 546, 662, 546, 602, 1702,
  602, 1706, 658, 546, 662, 1642, 666, 542,
  598, 610, 662, 542, 658, 1650, 598, 1710,
  598, 606, 662, 546, 662, 542, 666, 538,
  602, 606, 658, 550, 658, 546, 602, 606,
  654, 550, 658, 550, 654, 1654, 658, 1650,
  658, 546, 658, 546, 606, 606, 654, 550,
  662, 542, 662, 1646, 602, 606, 662, 1642,
  666, 542, 658, 550, 658, 1646, 662, 546,
  662, 19970, 662, 1650, 594, 610, 662, 1642,
  662, 546, 598, 606, 662, 546, 658, 546,
  602, 606, 598, 606, 602, 602, 658, 554,
  662, 542, 654, 550, 658, 550, 598, 1706,
  654, 554, 658, 546, 666, 542, 662, 542,
  658, 550, 658, 546, 662, 546, 654, 550,
  662, 546, 662, 542, 658, 550, 658, 546,
  602, 606, 662, 542, 662, 546, 658, 546,
  662, 546, 662, 1000
};

//on thermansi 23
#define RAW_DATA_LEN 140
uint16_t rawDataOn23[RAW_DATA_LEN] = {
  8990, 4482, 598, 606, 598, 610, 598, 1710,
  662, 1646, 598, 606, 662, 1646, 602, 606,
  598, 610, 658, 1650, 654, 1650, 598, 1714,
  594, 610, 658, 542, 602, 606, 662, 546,
  662, 546, 598, 606, 598, 610, 658, 546,
  598, 610, 654, 550, 602, 1710, 598, 1710,
  598, 606, 658, 546, 654, 554, 598, 606,
  654, 554, 658, 1650, 662, 522, 622, 1706,
  598, 606, 658, 546, 654, 1654, 662, 546,
  658, 19978, 658, 1646, 662, 546, 662, 1642,
  662, 542, 662, 542, 666, 542, 666, 542,
  662, 542, 658, 554, 658, 546, 658, 546,
  662, 542, 662, 546, 662, 542, 598, 1714,
  658, 546, 662, 546, 654, 550, 662, 546,
  662, 542, 662, 542, 662, 546, 662, 542,
  662, 546, 662, 546, 658, 546, 662, 542,
  662, 546, 658, 1646, 662, 546, 662, 542,
  662, 546, 658, 1000
};


IRsendRaw mySender;
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor

RF24 radio(10, 9);               // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint16_t master00 = 00;
const uint16_t node03 = 03;

const int relay1 =  4;
const int relay2 =  5;
const int relay3 =  6;
const int relay4 =  7;
const int relay5 =  8;
const int relay6 =  14;
const int relay7 =  15;
const int relay8 =  16;

char AcSaloni;
int PAPCstate;
int lastPAPCstate; // the previous reading from the input pin

struct package
{
  float tempSaloni;
  float humSaloni;
};
typedef struct package Package;
Package data;
/////------------------------------------------





void setup() {
  SPI.begin();
  Serial.begin(9600);
  dht.begin();
  radio.begin();
  network.begin(95, 03);  //(channel, node address)
  radio.setDataRate(RF24_1MBPS);
  radio.setPALevel(RF24_PA_MAX);

  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(relay5, OUTPUT);
  pinMode(relay6, OUTPUT);
  pinMode(relay7, OUTPUT);
  pinMode(relay8, OUTPUT);

  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
  digitalWrite(relay5, HIGH);
  digitalWrite(relay6, HIGH);
  digitalWrite(relay7, HIGH);
  digitalWrite(relay8, HIGH);

}

void loop() {


  network.update();

  // ===== Receiving =====
  while ( network.available() ) {      //Is there any incoming data
    RF24NetworkHeader header;
    network.read(header, &AcSaloni, sizeof(AcSaloni));  //Read the incoming data
    if (header.from_node == 00) {
      if (AcSaloni == 2) {
        mySender.send(rawDataOff, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
      }
      else if (AcSaloni == 3) {
        mySender.send(rawDataOn20, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
      }
      else if (AcSaloni == 4) {
        mySender.send(rawDataOn21, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
      }
      else if (AcSaloni == 5) {
        mySender.send(rawDataOn22, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
      }
      else if (AcSaloni == 6) {
        mySender.send(rawDataOn23, RAW_DATA_LEN, 36); //Pass the buffer,length, optionally frequency
      }

    }
  }


  delay(10);



  //data.tempSaloni = dht.readTemperature();
  //data.humSaloni = dht.readHumidity();

  //RF24NetworkHeader header(master00);    // (Address where the data is going)
  //bool ok = network.write(header, &data, sizeof(data)); // Send the data

  //Serial.println(data.tempSaloni);
  //Serial.println(data.humSaloni);
}

Thank you

You can see how much easer it is to read and copy when posted using code tags

UKHeliBob:
Thank you

You can see how much easer it is to read and copy when posted using code tags

Thanks too,first time posting :wink: i hope to find a solution..!

First of all, you are (re)declaring the define "RAW_DATA_LEN" multiple times - this is a bad habbit you should get rid of ASAP. Second of all, your arrays are 280 bytes in size and have a lot of duplicated values in them - which is unnecessary. You could declare the different values in one array, and indicies to that array in all the other arrays.

#define VALUES_LENGTH 5
uint16_t VALUES[VALUES_LENGTH] = { 1234, 4325, 7694, 5328, 534 };

#define RAW_DATA_LENGTH 20
uint8_t RAW_DATA_INDICIES[RAW_DATA_LENGTH] = { 0, 1, 2, 3, 4, 3, 2, 1, 0, 2, 3, 1, 4, 2, 4, 1, 3, 2, 1, 0 };

for (int i = 0; i < RAW_DATA_LENGTH; i++) Serial.println(VALUES[ RAW_DATA_INDICIES[i] ]);

The example above uses (25 + 20) = 30 bytes of memory. Had the RAW_DATA array been declared as you do, it would had consumed (202) = 40 bytes. That is 10 bytes less and because you have multiple arrays, that will save a lot of memory.

Apparently you did not understand my suggestion. Seems like you want a copy-paste sollution, go to gigs and collabs and pay someone to do your work..!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.