Example Code for Intel Joule-Digital Read
Last revision 2026/01/24
This article offers a step-by-step guide to using JS+MRAA for reading GPIO27 on Intel Joule, providing sample code and instructions for digital input setup.
Sample Code
JS+MRAA set GPIO27 as input, read and print its level every 1s.
var m = require('mraa'); //require mraa
console.log('MRAA Version: ' m.getVersion()); //write the mraa version to the console
var myDigitalPin = new m.Gpio(27); //setup digital read on onboard pin 4
myDigitalPin.dir(m.DIR_IN); //set the gpio direction to input
periodicActivity(); //call the periodicActivity function
function periodicActivity() //
{
var myDigitalValue = myDigitalPin.read(); //read the digital value of the pin
console.log('Gpio is ' myDigitalValue); //write the read value out to the console
setTimeout(periodicActivity,1000); //call the indicated function after 1 second (1000 milliseconds)
}
Result
Print MRAA version, output GPIO27 digital input 0/1 every 1s.
Was this article helpful?
