We need to load the à la mods "comm" library first before we begin working on the app. To get the à la mods "comm" library and install it run the following commands from the home directory. This will retrieve the compressed library file, extract all the files into its directory structure and then using "npm" install all the NodeJS dependency modules.

> wget http://www.alamods.com/software/alamods.tgz > tar -xzvf alamods-comm.tgz > cd ./alamods/comm > npm install

Another method of getting the à la mods "comm" library is via the "software" section within the resources page of the website.

One more general thing to do before we get into the actual application. We need to setup the file structure for NodeJS development. When running "npm init" you can use the defaults to most of the questions.

> cd ~ > mkdir isoiom17427 > cd ./isoiom17427 > npm init

Once that is complete we can develop an app that runs on the Raspberry Pi to control the I/O and LED of the ISOIOM17427 module. If you're developing this directly on the Raspberry Pi you can use "nano" or your favorite editor.

> sudo nano isoiom17427-control-registers.js

Add the following code:

let Comm = require("../alamods/comm/alamods-comm.js"); // instantiate the Comm object let comm = new Comm('M'); // state machine variable to toggle the LED let ledState = "on"; // setup the à la mods stacking address // be sure the solder jumpers on the module are all removed if // you're using address 0 as setup here. const MODULE_ADDR = 0; // this gets the model number of the module // internal register 0x80 contains the model number - this is // two byte number (0 - 65535) that corresponds to the last // 5 digits of the general module name (i.e. ISOIOM17427 // model number would be 17427); let model = comm.moduleRegRead(MODULE_ADDR, 0x80); console.log(model); // turn the LED on solid to magenta // internal address 0x90 is the register that controls the // status LED on most à la mods smart modules. // bit 15 - determines register control // - 0 = default mode where module controls LED automatically // - 1 = register (0x90) control of LED // bit 2 = Blue LED // bit 1 = Green LED // bit 0 = Red LED comm.moduleRegWrite(MODULE_ADDR, 0x90, 0x8005); // this timer function will run periodically and execute the state machine // (switch statement) to toggle the LED. setInterval (function() { // use a "switch" statement to toggle the LED on and off switch(ledState) { case "on": // turn the LED off comm.moduleRegWrite(MODULE_ADDR, 0x90, 0x8000); // release the relays // register 0x10 is the relay control register comm.moduleRegWrite(MODULE_ADDR, 0x10, 0x0000); // read the inputs // register 0x00 is the inputs status register inputs = comm.moduleRegRead(MODULE_ADDR, 0x00); // write the status of the GPIO digital inputs to the console in hex format console.log(inputs.toString(16)); break; case "off": // turn the LED on to magenta comm.moduleRegWrite(MODULE_ADDR, 0x90, 0x8005); // energize the relays (all) // register 0x10 is the relay control register comm.moduleRegWrite(MODULE_ADDR, 0x10, 0x00ff); ledState = "on"; break; default: ledState = "on"; break; } }, 1000);

When the app file is completed save it and run the following command:

> sudo node isoiom17427-control-registers.js > 17427

The output on the terminal should be 17427 on the first line then the value of the digital inputs every second. In addition the LED should be flashing and the relays toggling every second.

You must run the app as root (using "sudo") because the hardware access to the serial buses SPI/I2C are through "/dev/mem" and not "/dev/gpiomem" which is required to be run as root.

© à la mods. All rights reserved