• Equipment: Espruino board, USB cable, WebIDE and SD card.
    This program makes use of three objects saved in local modules in a WebIDE project.
    The first object “CalObj” makes use of a file “Mycalibrations.cal” located on the SD card in the Espruino board.

    {"calibrations":[
    {"name":"Inlet","units":"psig","pin":"A0­","slope":100.13897386464,"Intercept":-0­.03419722673},
    {"name":"Outlet","units":"psig","pin":"A­1","slope":50,"Intercept":-25},
    {"name":"Motor","units":"Amps","pin":"A2­","slope":1,"Intercept":0},
    {"name":"Supply","units":"Volts","pin":"­A3","slope":1,"Intercept":0},
    {"name":"Flow","units":"Liters/minute","­pin":"A4","slope":1,"Intercept":0}
    ]}
    

    The following link lays out the object used to calibrate the analog inputs into engineering units. It was used to create the file “Mycalibrations.cal” on the SD card.
    http://forum.espruino.com/conversations/­¬286215/

    The second object “TimeObj.js” is used for its stopwatch function and ability to format date and time from a pattern stored in an array. See the following link.
    http://forum.espruino.com/conversations/­286424/

    The third object “LogObj.js” uses the previous two object modules and a “.cfg” file stored on the SD card. This program uses three different “.cfg” files an produces three different “.csv” files. The program used to create the “.cfg” files is “saveLogCfgXX1.js”
    One of the “.cfg” files looks like this:

    {"Fname":"xx1.csv",
    "Interval":1000,
    "items":[
    {"header":"N","cmd":"count"},
    {"header":"Date","cmd":"DATE","Args":["M­","-","D","-","Y"]},
    {"header":"Time","cmd":"TIME","Args":["H­",":","M",":","S"]},
    {"header":"A0","cmd":"SAR","Args":["A0",­2]},
    {"header":"A1","cmd":"SAR","Args":["A1",­2]},
    {"header":"A2","cmd":"AR","Args":["A2",2­]},
    {"header":"Board Temp C","cmd":"BTC","Args":[2]},
    {"header":"Board Temp F","cmd":"BTF","Args":[2]}
    ],
    "count":0,
    "N":10
    }
    
    

    The “Fname” is the name of the csv file to create.
    The “Interval” is the milliseconds between each data sample.
    The “Items” array contains records that set up the data to log to the csv file.
    The “Header” is the text at the top of a column in the csv file.
    The “cmd” can be “count”,“DATE”,“TIME”, “SAR”,”AR”,”BTC” or “BTF”
    Date and time commands use the information in the “Args” to format the data.
    AR is analog read without calibrations applied.
    SAR is a calibrated analog reading. For SAR the header information comes from the calibration file.
    For AR and SAR Args[0] is the pin name, and Args[1] is used in a toFixed(Args[1]) to format the data.
    The BTC and BTF are the board temperature in F or C units.
    Count is used to count and N is the number of samples to take

    Programs to load into Project:
    LogCSV6a.js, saveLogCfgXX1.js

    Modules to load into Modules:
    TimeObj.js, LogObj.js and CalObj.js
    Files on SD card in the Espruino:
    Mycalibrations.cal, Mylog1.cfg, Mylog2.dfg, and Mylog3.cfg
    Files created on the SD card by this program:
    Xx1.csv, xx2.csv, and xx3.csv.

    LogCSV6a.js listing:

    function ReadObjectFile(fname){
     return JSON.parse(require("fs").readFileSync(fn­ame));
    }//end ReadObjectFile
    
    
    
    function TestIt(){
     var T= new (require("TimeObj"))();
     T.updateTime();
    //start the stopwatch
     T.SWstart();
    // output day of the week
     console.log(T.getDay());
    
     Cal=new (require("CalObj"))(ReadObjectFile("Myca­librations.cal")); 
     Log=new (require("LogObj"))(ReadObjectFile("Mylo­g1.cfg"),Cal,T);
     Log1=new (require("LogObj"))(ReadObjectFile("Mylo­g2.cfg"),Cal,T);
     Log2=new (require("LogObj"))(ReadObjectFile("Mylo­g3.cfg"),Cal,T);
    
    //Changes to the onjects can be masde
    // Log1.A.Interval=3000;
    // Log1.A.Fname="xx1.csv";
    
    //start the logging 
     Log.doHeaders();
     Log.start();
    
     Log1.doHeaders();
     Log1.start();
    
     Log2.doHeaders();
     Log2.start();
    // output the elapsed time  
     console.log(T.SWstop().toFixed(3)," ms");
    }//end TestIt
    
    setBusyIndicator(LED1);
    TestIt();
    
    

    and the console output:

    >echo(0);
    Fri
    1680.916  ms
    =undefined
    xx1.csv Finished
    11005.221  ms
    xx2.csv Finished
    21572.389  ms
    xx3.csv Finished
    3202
    
    

    14 Attachments

About