-
Notifications
You must be signed in to change notification settings - Fork 2
DigitalRead() duration in ms
This document explains the procedure to execute digitalRead() function within a node.js environment and measure the duration of the call. This is useful to determine fit of some sensors.
This WIKI page is a living document that may be changed at any moment without prior notice.
All procedures and instructions shared in this GIT Hub Account are given to you "as-is" without any implicit or explicit warranty of success.
To the extent permitted by law, I accept no liability or responsibility for any damage or loss you may get into while following this procedure.
As of the time this post was written, I am affiliated to Intel Corporation as a regular employee based in Costa Rica, working as an Applications Developer.
All content in this page is provided voluntarily and personally independently of Intel.
You need:
- Perform the Boot from SD Card procedure (Optional)
- Perform the Connecting through LAN procedure
- You can use Connecting through LAN procedure
- example for May 20, 12:57pm:
date 2005125714
This will make node.js run better.
- Using the puTTY terminal, create a folder to store your server code. i.e.: /home/root/readTime
cd /home/root
mkdir readTime
- Access the folder you just created
cd /home/root/readTime
- Install galileo-io npm package
npm install galileo-io
- Run WinSCP and connect to the Galileo Board via Ethernet
- Look for the folder you just created. I.e.: /home/root/readTime
- Create a new file named 'time_reader.js' with the following code inside:
var Galileo = require("galileo-io");
var board = new Galileo();
var pinToRead = 3;
board.on("ready", function boardReadyEvent() {
console.log("Board Ready Function Reached!");
this.pinMode(pinToRead, this.MODES.INPUT);
var initialTime = new Date().getTime();
var endTime = new Date().getTime();
var minimalDiff = endTime - initialTime;
var readOpTime;
var valueRead;
console.log({ini: initialTime, end: endTime, diff: minimalDiff});
initialTime = new Date().getTime();
board.digitalRead(pinToRead, function readHandler(data){
readOpTime = (new Date().getTime()) - initialTime;
console.log("digitalRead() lasted: " + readOpTime + "ms");
console.log("value we got was: " + data);
initialTime = new Date().getTime();
});
console.log("End of BoardReady event");
});
- run the file in node.js by executing
node time_reader.js
- You'll see the constant execution of the read operation with the duration assessment. In my case, most of the readings take 1-2 milliseconds (same as in an ARDUINO sketch) but some readings took ~16ms!
- Use [CTRL] + [C] to stop execution