Skip to content

DigitalRead() duration in ms

jn edited this page May 21, 2014 · 1 revision

Home | Initial Setup


Purpose

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.

Status and Disclaimer

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.

Pre-requisites

You need:

Procedure

STEP 1: Connect to your Galileo Board using puTTY via LAN

STEP 2: Once in the Linux environment, set the date/time by executing date ddmmhhmmYY

  • example for May 20, 12:57pm: date 2005125714

This will make node.js run better.

STEP 3: Install galileo-io npm package

  • 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

STEP 3: Use WinSCP to create the web server in Galileo Board

  • 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

Home | Initial Setup