Skip to content
Lews Duino Gear
  • Home
  • The Layout Control Operating System
  • The Store
  • Support
    • My Tickets
    • Submit Ticket
  • My Account
    • Your Cart
  • About
    • Company & Product News
    • Contact Us

Arduino Library for Output duinoNodes

Arduino Library for Output duinoNodes

Output duinoNodes (DNOU1 & DNOU8) are 8-bit serial in, parallel out shift register logic devices. Accordingly, board ports can be turned on or off using the Arduino library function shiftout(). The duinoNodes software library provides an addressing system and additional functionality you may find useful.

The library — duinoNodes-biuvvo.zip — should have been automatically added to your cart when you purchased your duinoNode product, and is now available through your Lew’s Duino Gear account.

Download the file and install it by unzipping it into your Arduino/libraries directory. Navigate to Arduino/libraries/duinoNodes/examples/outputNodesDemo/ and load outputNodesDemo.ino. You can attach LEDs and/or relays to the outputs of your boards to see the sketch demo the use of the board(s).

Basic Usage

To use the library, add #include <duinoNodes.h> at the top of your main sketch:

#include <duinoNodes.h>

You must set the number of nodes in use. To do that, define NUM_OUTPUT_NODES before including the header file. Finally, create a global variable for the “outputNodes” object used to reference the boards; in the demo sketch the variable is called “outputs”:

#define NUM_OUTPUT_NODES 2
#include "duinoNodes.h"
outputNodes *outputs;

In setup(), initialize the duinoNodes with this call:

outputs = new outputNodes(NUM_OUTPUT_NODES, OUTPUT_CLOCK, OUTPUT_LATCH, OUTPUT_DATA);

This will instantiate the outputNodes object using the default CLOCK, LATCH and DATA pins — D2, D3 and D4 respectively. To change the defaults define OUTPUT_CLOCK, OUTPUT_LATCH and OUTPUT_DATA with different pin values before including the library header, like this:

#define OUTPUT_CLOCK A1
#define OUTPUT_LATCH A2
#define OUTPUT_DATA 6
#define NUM_OUTPUT_NODES 2 
#include "duinoNodes.h" 
outputNodes *outputs; 

Addressing and Manipulating Ports

Each port can be addressed by its sequential ID. With one board (Board 0), the available sequential IDs are 0 to 7. Each board you add to the chain adds additional sequential IDs. So, ports on board 1 can be addressed by IDs 8 – 15, ports on board 2 can be address by IDs 16 – 23, and so on.

The Sequential ID can be calculated this way, where the Board Number can be from 0 – 64, and the Port Number ranges from 0 – 7:

Sequential ID = (Board Number x 8) + Port Number

To facilitate using ports in groups, each port can also be referenced by a nodeAddress structure, defined as follows:

typedef struct nodeAddress {
  word node;
  byte pin;
};

Addresses in this form can be grouped into a nodeList, allowing all member nodes to be turned on or off at the same time.

typedef struct nodeList {
  int elements; // number of nodes in the list
  nodeAddress *nodes;
};

Methods

The outputsNodes object offers multiple methods for manipulating the ports. Any individual port can be turned on or off using the nodeWrite() method with the sequential ID of the port:

outputs->nodeWrite(ID, 1); //turns port on
outputs->nodeWrite(ID, 0); //turns port off

Sometimes you want to switch multiple ports in parallel, such as where you have a group of lights you want to go on and off at the same time. To do that, you first create an array of nodeAddress objects. In the following example with two nodes, an array of nodeAddresses includes two random ports from each board.

nodeAddress a_group[4] = {
   {word(0, 0), 0},
   {word(0, 0), 4},
   {word(0, 1), 2},
   {word(0, 1), 3}
  };

Next create a nodeList with the array and the number of addresses in the array:

nodeList list_of_items = {4,  a_group};

There are two methods that can be applied to a nodeList:

outputs->nodesOn(list_of_items); // turns all ports on

outputs->nodesOff(list_of_items); // turns all ports off

Pin states are manipulated and maintained in RAM; pin state data is pushed out to the boards whenever there is a change that needs to be communicated. The foregoing methods all set pin states and automatically refresh the outputs to reflect changes.

Sometimes, you may want to manipulate pin states without refreshing the output ports right away. Use the nodeSetPin() method to do this:

outputs->nodeSetPin(ID, state [0 or 1]);

You can also get the current state of a pin using the nodeGetPin() method which returns the pin state as either true (1) or false (0):

outputs->nodeGetPin(ID);

This makes it easy to flip the state of a port:

 outputs->nodeSetPin(ID,  !outputs->nodeGetPin(ID) ); 

You can get or set the pin byte of a node (board) instead of addressing its individual ports; this eliminates address calculations and results in the maximum possible rate of change of port states. This is also useful where you want to manipulate ports asynchronously relative to refresh calls.

Three helper methods are available:

outputs->nodeGet(node) – returns the pin byte for the node. The state of each port is represented by a bit in the pin byte.
outputs->nodeSet(node, pins) – sets the pins byte of the node. Change the value of "pins" bits to turn ports on or off.

Any time you want to refresh the outputs, call the nodesRefresh() method:

outputs->nodesRefresh() – pushes current pin data out to the nodes and refreshes outputs.

Recent Posts

  • Checkout Issue Fixed
  • LCOS Manual is Live
  • Product On Sale Date
  • DCC Client Coming
  • LCOS Product Release Update

Recent Comments

    Categories

    • Company
    • New Releases
    • Products
    • System Events
    • Uncategorized

    Archives

    • January 2022
    • August 2021
    • January 2021

    About Us

    Creators of Intelligent Electronics for Model Railroads

    Copyright © 2021 - 2022, Beagle Bay Inc All Rights Reserved
    Theme by Colorlib Powered by WordPress
    We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
    Do not sell my personal information.
    Cookie settingsACCEPT
    Manage consent

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
    Necessary
    Always Enabled
    Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
    Non-necessary
    Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
    SAVE & ACCEPT