• Being a hard core Arduino user, I decided to switch to the Espruino.
    I put together a DS18B20 data logger. After a few days, I noticed
    on the I2C LCD, that memory usage was increasing from 646 to 651.
    Any help is appreciated to track down this memory leak. (See code below)

    BTW ... I am very impressed with the amount of program code needed for this project. It would of taken thousands of lines of code for the Arduino.

    /*
    DS18B20 Data Logger
    Rev. 1.0b
    6/26/14
    Espruino: v 1.3: firmware: v 65 WEB-IDE: v 45
    Windows 8.1 / Chrome
    Hardware: I2C 4x20 LCD, DS18B20, I2C RTC DS3231
    Bugs: Memory usage 646 but after a few days increases to 651 ???
    
    Program description:
    Uses 1-wire DS18B20 for the temperature sensor.
    The DS18B20 temperature is logged along with time/date to SD and LCD.
    1-wire and 1 I2C bus is used.
    
    Program credits:
    SD data logger code snippet was used from an unknown Espruino forum member.
    
    Note: 3.3k pull-ups for I2C LCD/RTC.
    */
    
    function onInit(){
    var ow = new OneWire(A1);
    var sensor = require("DS18B20").connect(ow);
    sensor.setRes(12); 
    digitalWrite([LED1,LED2,LED3],0b100);
    var lcd = require("HD44780").connectI2C(I2C1);
    I2C1.setup({scl:B8,sda:B9});
    lcd.clear(); 
    setTimeout("digitalWrite([LED1,LED2,LED3­],0b010);", 1000);
    setTimeout("digitalWrite([LED1,LED2,LED3­],0b001);", 2000);
    setTimeout("digitalWrite([LED1,LED2,LED3­],0);", 3000);
    // Delay start-up for diagnostics (above) and for LCD clear
    I2C1.setup({scl:B8, sda:B9});
    var rtc = require("DS3231").connect(I2C1);
    }
    
    var fs = require('fs');
    var testName    = "TEST152L.LOG";
    var testDetails = "Data Logging DS18B20 to SD";
    var logInterval = 5000;
    var logEntry    = 0;
    
    var ow = new OneWire(A1);
    var sensor = require("DS18B20").connect(ow);
    
    I2C1.setup({scl:B8,sda:B9});
    var rtc = require("DS3231").connect(I2C1);
    
    /* Set Dow Time/date - comment out lines out below after first use!
    Usage:
    rtc.setDow("day of the week") Monday,Tuesday ...
    rtc.setDate(date,month,year);1-31,1-12,0­-99
    rtc.setTime(hours,minutes); Military Time 
    Set time exactly on minute roll-over (+ 1  min)
    */
    
    //rtc.setDow("Thursday");
    //rtc.setDate(26,6,14);
    //rtc.setTime(19,25); 
    
    I2C1.setup({scl:B8, sda:B9});
    var lcd = require("HD44780").connectI2C(I2C1);
    lcd.clear();
    
    
    // Initialise log file here with header information
    console.log(testDetails);
    fs.appendFileSync(testName, testDetails);
    
    // Function to log some data every so often
    setInterval(function(){
        // Indicate each time function is executed 
        digitalPulse(LED1, 1, 100);
    // Log some data.
        logEntry++;
     var logString = logEntry + " " + (sensor.getTemp(true)* 1.8 + 32 + " F. ") +
        (rtc.readDateTime()) + " "  + "\r\n";
    
        //console.log(logString); <---- do not leave in without USB (will halt)
        //console.log(process.memory().usage); <--- do not leave in without USB (will halt)
        fs.appendFileSync(testName, logString);
        lcd.setCursor(0,0);
        lcd.print("DS18B20 Logging ..."); 
        lcd.setCursor(0,1);
        // lcd needs a string ????
        lcd.print("TempF: " + new String(sensor.getTemp(true)*1.8 + 32));
        lcd.setCursor(0,2);
        lcd.print(rtc.readDateTime());
        lcd.setCursor(0,3);
        lcd.print(new String(process.memory().usage));
        
    }, logInterval);
    
    
About

Avatar for user7114 @user7114 started