Problem with a small amount of RAM



  • Am i doing something wrong?
    Are two sensors too much for Atmega328?
    library: today from git.

    #include <Adafruit_BMP085.h>
    #include "DHT.h"
    
    #define MY_TRANSPORT_WAIT_READY_MS 100
    //#define MY_DEBUG
    #define MY_DISABLED_SERIAL
    #define MY_SIGNING_SIMPLE_PASSWD "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    #define MY_RADIO_RFM69
    #define MY_RFM69_NEW_DRIVER
    #define MY_RFM69_MAX_POWER_LEVEL_DBM 13
    #define MY_NODE_ID 1
    #include <MySensors.h>
    
    MyMessage msgRSSIS(10, V_VAR1);
    MyMessage msgRSSIR(11, V_VAR1);
    MyMessage msgPowerd(12, V_VAR1);
    MyMessage msgPowerp(13, V_VAR1);
    MyMessage msgTempDHT(14, V_TEMP);
    MyMessage msgHumDHT(15, V_HUM);
    MyMessage msgTempBMP(16, V_TEMP);
    MyMessage msgPresBMP(17, V_PRESSURE);
    MyMessage msgPresSeaBMP(18, V_PRESSURE);
    
    Adafruit_BMP085 bmp;
    DHT dht(3, DHT22); //PIN, TYPE
    
    void setup()  
    { 
    }
    
    void presentation() 
    {
      sendSketchInfo("Zewnetrzny", "1.0");
      present(10, S_CUSTOM, "RSSI Sending",true);
      present(11, S_CUSTOM, "RSSI Receiving",true);
      present(12, S_CUSTOM, "Power dbm",true);
      present(13, S_CUSTOM, "Power Percent",true);
      present(14, S_TEMP, "DHT Temperature",true);
      present(15, S_HUM, "DHT Humidity",true);
      present(16, S_TEMP, "BMP Temperature",true);
      present(17, S_BARO, "BMP Pressure hPa",true);  
      present(18, S_BARO, "BMP Pressure Sea hPa",true);  
    }
    
    void loop()      
    {
      send(msgRSSIS.set(RFM69_getSendingRSSI(),1));
      wait(200); 
    
      send(msgRSSIR.set(RFM69_getReceivingRSSI(),1));
      wait(200); 
    
      send(msgPowerd.set(RFM69_getTxPowerLevel(),1));
      wait(200); 
    
      send(msgPowerp.set(RFM69_getTxPowerPercent(),1));
      wait(200); 
      
      dht.begin();
      send(msgTempDHT.set(dht.readTemperature(),1));
      wait(200); 
      send(msgHumDHT.set(dht.readHumidity(),1));
      wait(200); 
    
      bmp.begin();
      send(msgTempBMP.set(bmp.readTemperature(),1));
      wait(200);
      send(msgPresBMP.set(bmp.readPressure()/100,1));
      wait(200); 
      send(msgPresSeaBMP.set(bmp.readSealevelPressure(164)/100,1));
    
      wait(10000);   
    }
    
    void receive(const MyMessage &message) 
    {
    }
    
    

    Compilation result:

    Sketch uses 20196 bytes (65%) of program memory. The maximum is 30720 bytes.
    Global variables use 1694 bytes (82%) of dynamic memory, leaving 354 bytes for local variables. The maximum is 2048 bytes.
    Low level of available memory, stability problems may occur.
    

  • Hardware Contributor

    @melwinek your problem comes from the big number of texts.
    As you declare them, they are all saved in RAM. To avoid that you need to declare them with PROGMEM, or easier for simple use like yours, use the F() macro. Type F("something") instead of just "something".

    See here for more information :
    https://www.arduino.cc/en/Reference/PROGMEM



  • After some changes in MySensorsCore.cpp and MySensorsCore.h I used code:

      present(10, S_CUSTOM, F("RSSI Sending"),true);
      present(11, S_CUSTOM, F("RSSI Receiving"),true);
      present(12, S_CUSTOM, F("Power dbm"),true);
      present(13, S_CUSTOM, F("Power Percent"),true);
      present(14, S_TEMP, F("DHT Temperature"),true);
      present(15, S_HUM, F("DHT Humidity"),true);
      present(16, S_TEMP, F("BMP Temperature"),true);
      present(17, S_BARO, F("BMP Pressure hPa"),true);  
      present(18, S_BARO, F("BMP Pressure Sea hPa"),true); 
    

    Compilation result:
    1582 bytes (77%) of dynamic memory

    This is still too much.
    It seems to me that signing up consumes a lot of memory.
    Can it be improved?


  • Hardware Contributor

    @melwinek no idea about the signature but you could also try to reduce the number of messages you declare, I'm not sure about how much RAM a message uses but you can have one message for each type of data and set child id just before setting the value and sending.


  • Contest Winner

    @melwinek signing is memory optimized on the development branch. It cost some yes, but that is pretty much just how it is. It takes some ram to store digests and intermediate data for the calculations.


Log in to reply
 

Suggested Topics

12
Online

11.4k
Users

11.1k
Topics

112.7k
Posts