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.
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:
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(fname));
}//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("Mycalibrations.cal"));
Log=new (require("LogObj"))(ReadObjectFile("Mylog1.cfg"),Cal,T);
Log1=new (require("LogObj"))(ReadObjectFile("Mylog2.cfg"),Cal,T);
Log2=new (require("LogObj"))(ReadObjectFile("Mylog3.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
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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.
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:
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:
and the console output:
14 Attachments