> For the complete documentation index, see [llms.txt](https://docs.microside.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.microside.com/en/user-manuals/xide/x-nodes/xn01-digital-inputs/a-r2/xn01-digital-inputs.md).

# XN01 - Digital Inputs

<figure><img src="https://docs.microside.com/~gitbook/image?url=https%3A%2F%2F177299348-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FbyV2zAlQAiqg46a3Lr8z%252Fuploads%252FsbjotlIMvNnOdQI7a07I%252FMODULO%2520X-NODE%2520ENTRADAS%2520DIGITALES%2520XN01%2520XIDE%2520MICROSIDE.webp%3Falt%3Dmedia%26token%3D627723e6-336e-436c-86db-6be4305ffeb5&#x26;width=768&#x26;dpr=1&#x26;quality=100&#x26;sign=487a5aaa&#x26;sv=2" alt=""><figcaption><p>XN01 - Digital Inputs</p></figcaption></figure>

**X-NODE Digital Inputs** is a module that allows reading up to 8 digital inputs. It can read signals generated by push buttons, switches, or sensors through a configurable digital interface (UART/I2C), enabling multiple **X-NODE Digital Inputs** to be connected simultaneously and expanding the number of inputs a system can read from 8 up to 1016.

{% hint style="warning" %}
The inputs of the **X-NODE Digital Inputs** use pull-up resistors. To use external signals, set the switch to the **OFF** position, external signals must be **open collector** type. Signals generated by external buttons or switches should be connected to GND. Never connect voltage sources to the **X-NODE Digital Inputs** or you may damage the device.
{% endhint %}

{% hint style="info" %}
If you need to read digital signals with a voltage range from 5 to 24VDC, NPN or PNP type, check out our [**X-NODE XN26 - 4 x24V Input**](https://docs.microside.com/plataforma-xide-iot/x-nodes/x-node-xn26-4-x-entradas-24v-dc). (Resource in Spanish, English version coming soon...)
{% endhint %}

### TABLE OF CONTENTS

1. [**How does it work?**](#i.-how-does-it-work)
2. [**Hardware description**](#ii.-hardware-description)
3. [**Specification**](#iii.-specification)
4. [**Pinout**](#iv.-pinout)
5. [**Usage**](#v.-usage)
   * [**UART Protocol**](#uart-protocol)
   * [**UART Arduino Framework Example**](#uart-arduino-framework-example)
   * [**I2C Protocol**](#i2c-protocol)
   * [**I2C Arduino Framework Example**](#i2c-arduino-framework-example)
6. [**Downloads**](#vi.-downloads)
   * [**Schematic**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FCThPVRmWZzIfmydz02c3%2Fschematic.pdf?alt=media\&token=ce7c9c1f-3421-45c4-aa1a-99cca2172f7d)
   * [**Dimensions**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FU3pHQiMzNXVmd02ndzQq%2Fdimentions.pdf?alt=media\&token=d122cc96-4637-4904-ad3d-a3e0db7cd58b)

## I. How does it work?

The **X-NODE Digital Inputs** module has an integrated microcontroller that allows you to read various digital inputs without advanced hardware knowledge. You only need to send a series of ASCII commands via the UART serial communication protocol or using the I2C protocol, making the X-NODE compatible with any system based on a microcontroller, microprocessor, or industrial equipment. The module integrates an 8 position slider with lever-type switches that can toggle between ON<>OFF states, a 9 pin terminal block connector for AWG 26 to 18 cables, ideal for desktop testing and connecting external controls.

**X-NODE Digital Inputs** is compatible with the [mikroBUS™](https://www.mikroe.com/mikrobus) standard from [Mikroe®](https://www.mikroe.com/) for easy use with a large hardware development ecosystem. It also has JST connectors compatible with the [Qwiic®](https://www.sparkfun.com/qwiic) standard from [SparkFun®](https://www.sparkfun.com/) for quick and easy I2C communication between various modules and development boards.

## II. Hardware description

<figure><img src="/files/jtV55bM6pP80DG2v36iw" alt=""><figcaption></figcaption></figure>

1. 9 pin terminal block connector for AWG 26 to 18 cables
2. Slide switch
3. JST connectors compatible with [Qwiic®](https://www.sparkfun.com/qwiic)
4. Hardware controller
5. UART <> I2C communication ports
6. X-NODE model
7. X-NODE type
8. [mikroBUS™](https://www.mikroe.com/mikrobus) standard connectors
9. Hardware version: R2
10. Main component in the X-NODE

## III. Specification

<table data-header-hidden><thead><tr><th width="129"></th><th></th></tr></thead><tbody><tr><td><strong>Applications</strong></td><td>Integration with IoT projects and general purpose use, such as reading state changes, sequences, or configuration of indicators and actuators in an electronic circuit or project.</td></tr><tr><td><strong>Features</strong></td><td>8 position slider with lever-type switches, electrical life up to 2000 cycles, insulation resistance up to 100 MΩ, and can operate in a temperature range from -10 °C to 80 °C. Terminal block for 8 external inputs and GND.</td></tr><tr><td><strong>Interface</strong></td><td>UART, I2C</td></tr><tr><td><strong>Compatibility</strong></td><td><a href="https://www.mikroe.com/mikrobus">mikroBUS™</a> standard and <a href="https://www.sparkfun.com/qwiic">Qwiic®</a> standard</td></tr><tr><td><strong>Size</strong></td><td>67.13 x 25.4 x 22 mm</td></tr><tr><td><strong>Voltage</strong></td><td>3.3 V</td></tr></tbody></table>

{% hint style="warning" %}
The inputs of the **X-NODE Digital Inputs** use pull-up resistors. To use external signals, set the switch to the **OFF** position, external signals must be **open collector** type. Signals generated by external buttons or switches should be connected to GND. Never connect voltage sources to the **X-NODE Digital Inputs** or you may damage the device.
{% endhint %}

{% hint style="info" %}
**Warning!** Never connect voltage sources to the inputs of the X-NODE Digital Inputs, doing so may damage the device. Use open-drain signals to interface with the device.
{% endhint %}

## IV. Pinout

The following table shows the pinout of the **X-NODE Digital Inputs** according to the [mikroBUS™](https://www.mikroe.com/mikrobus) standard (shown in the two center columns).

<figure><img src="https://docs.microside.com/~gitbook/image?url=https%3A%2F%2F177299348-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FbyV2zAlQAiqg46a3Lr8z%252Fuploads%252FJo1oZSK1hQRwkYoRQILz%252Fuser-manual-mikrobus-pinout-table.jpg%3Falt%3Dmedia%26token%3D658ae120-a66c-401f-8bd0-e8a7e97a22e6&#x26;width=768&#x26;dpr=4&#x26;quality=100&#x26;sign=ed36da55&#x26;sv=2" alt=""><figcaption></figcaption></figure>

## V. Usage

For easy and quick use of the X-NODE, you can use the ASCII commands provided by the integrated hardware controller via UART serial communication or more advanced use via the I2C protocol.

### UART Protocol

#### Configuration

UART communication uses the following settings:

* Baud rate: 115,200 bps
* Parity: None
* Data bits: 8
* Stop bits: 1

#### Syntax

The UART protocol allows sending instructions in plain *ASCII* text, each instruction consists of the **X-NODE identifier, a command, and an end-of-line**.

**Identifier**

The **ID** identifier consists of the X-NODE model, which can be found at point 6 in the **Hardware Description** section, and is complemented by an index, which can be a letter from A to Z (default is **A**). To connect more than one module of the same model in a system, you must configure a unique identifier for each module, allowing up to 26 modules of the same model to be connected via UART.

<figure><img src="/files/TlgH49djKUwudquC2WUh" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Note:** From this point, the default index of the X-NODE **XN01 - Digital Inputs** will be used for the rest of the manual: **XN01A**.
{% endhint %}

**Command List**

<table data-header-hidden><thead><tr><th width="173"></th><th></th></tr></thead><tbody><tr><td><strong>XN01A?</strong></td><td>Checks if communication was successfully established.<br><strong>Response:</strong> OK</td></tr><tr><td><strong>XN01A+V</strong></td><td>Gets the current firmware version integrated in the X-NODE.<br><strong>Response:</strong> XN01A=Version<br><strong>Example:</strong> XN01A=0.1</td></tr><tr><td><strong>XN01A+ID=(A-Z)</strong></td><td>Changes the ID index to a different uppercase letter from A to Z. Once changed, you must use the new ID to change it again.<br><strong>Response:</strong> OK<br><strong>Send example:</strong> XN01C+ID=H</td></tr><tr><td><strong>XN01A+TW=(1-126)</strong></td><td>Changes the factory I2C address to a different one. The new address is written in decimal, selecting a value from 1 to 126.<br><strong>Response:</strong> OK<br><strong>Send example:</strong> XN01A+TW=28</td></tr><tr><td><strong>XN01A+GS</strong></td><td>Gets the status of each of the 8 inputs, either from the switches or the port. Returns 1 (High) and 0 (Low) depending on the state of each input. Input 1 is the first value on the left, interpreting the value from left to right.<br><strong>Response:</strong> XN01A=int1, int2, int3, int4, int5, int6, int7, int8<br><strong>Example:</strong> XN01A=11011011</td></tr></tbody></table>

#### Advanced Commands

<table data-header-hidden><thead><tr><th width="170"></th><th></th></tr></thead><tbody><tr><td><strong>XN01A+ETW=(0-1)</strong></td><td>Enables (1) or disables (0) the device's I2C interface.<br><strong>Note</strong>: This setting is volatile, disconnecting the device from power or sending the reset command will restore the I2C interface.<br><strong>Response:</strong> OK<br><strong>Send example:</strong> XN01A+ETW=0</td></tr><tr><td><strong>XN01A+SLP</strong></td><td>Enables deep sleep mode to reduce power consumption, during deep sleep, the device will not respond to UART commands. To wake the device, send a logic low (0) to the WAKEUP/UPDI pin.<br><strong>Response:</strong> OK<br><strong>Send example:</strong> XN01A+SLP</td></tr><tr><td><strong>XN01A+RST</strong></td><td>Resets the device, non-volatile values (e.g., ID, I2C address) will be retained, and volatile values will return to their default settings.<br><strong>Response:</strong> OK</td></tr></tbody></table>

#### End of Line

The X-NODE will only respond to a command when a set of end-of-line characters is sent, each command must end with these characters: **\<CR+LF>**

* CR means carriage return.
* LF means line feed.

The combination of both characters is a common way for computers to represent a new line, for example, in a word processor to separate paragraphs.

For the X-NODE, the **\<CR+LF>** characters are used to identify when a command has finished being sent. If the identifier matches the node, the command exists, and it ends immediately with **\<CR+LF>**, then the node will send a response.

Depending on your system, you must configure the sending of these characters in different ways.

### UART Arduino Framework Example

{% hint style="info" %}
Example code for [XC01 - R5](https://docs.microside.com/plataforma-xide/xide-iot-i4.0/iot/x-nodes/xc01-mcu-wifi-ble-esp32-wroom-32). Check the manual to use our [XC01 - R5](https://docs.microside.com/plataforma-xide/xide-iot-i4.0/iot/x-nodes/xc01-mcu-wifi-ble-esp32-wroom-32) in **Arduino IDE/PlatformIO**
{% endhint %}

```cpp
// This example shows the status of the inputs
// of the X-NODE. Slide the switch position
// to observe state changes.

#include "Arduino.h"

void setup()
{
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize UART communication on mikroBUS port
  Serial2.begin(115200, SERIAL_8N1, 9, 10);
}

void loop()
{
    // Clear the buffer before sending the command
    while( Serial2.available() ) {
        Serial2.read();
    }

    // Send the command to read the inputs:
    // ID+GS:
    // Where the default ID is XN01A
    // The \r\n characters represent the
    // <CR+LF> in C-like languages
    Serial2.print( "XN01A+GS\r\n" );

    // Wait until a response is received
    String inputs = Serial2.readStringUntil('\n');

    // If the response starts with the ID
    // then communication was successful
    if ( inputs.startsWith( "XN01A=" ) ) {
        Serial.println( inputs );
    } else {
        Serial.println( "Error" );
    }

    delay( 1000 );
}
```

### I2C Protocol

To establish communication, you must know the I2C address of the X-NODE, the factory value consists of the last two digits of the model after "XN". I2C addresses are usually represented in **hexadecimal**, while the X-NODE model is in **decimal**; make sure to use the correct number system.

<figure><img src="/files/UZn5HOuaGTh3D5sWbKlm" alt=""><figcaption></figcaption></figure>

#### Configuration

* Communication speed: 100 kHz
* Address: 7 bits

{% hint style="info" %}
**Note:** Make sure you do not have another device with the same address on the I2C BUS. If so, remember that the X-NODE can change its I2C address with the **XN01A+TW=(1-126)** command.
{% endhint %}

#### Writing

To write to a register of the **X-NODE Digital Inputs**, the I2C controller must perform the following operations:

1. Send a **start condition**: The controller generates a logic low (0) on the SDA pin while SCL remains high (1).
2. Send the **X-NODE address**: The controller sends the 7-bit address.
3. Send the **operation type**: The controller indicates if the operation is read (0) or write (1).
4. Wait for an **acknowledge (ACK)** signal: The controller waits to receive a logic low (0) as confirmation (Acknowledgment) that a target with the sent address exists on the I2C BUS. If no response (1) is received, there was a communication error or the address is incorrect.
5. Write **n bytes** of data: The controller writes in 8-bit (1 byte) sequences, MSB first, as many bytes as needed. The target will send an **ACK** signal for each byte written.
6. Send a **stop condition**: The controller must release the I2C BUS by generating a logic high (1) on SDA while SCL is high (1).

#### Reading

To read from a register of the **X-NODE Digital Inputs**, the I2C controller must perform the following operations:

1. Send a **start condition**: The controller generates a logic low (0) on the SDA pin while SCL remains high (1).
2. Send the **X-NODE address**: The controller sends the 7-bit address.
3. Send the **operation type**: The controller indicates if the operation is read (0) or write (1).
4. Wait for an **acknowledge (ACK)** signal: The controller waits to receive a logic low (0) as confirmation (Acknowledgment) that a target with the sent address exists on the I2C BUS. If no response (1) is received, there was a communication error or the address is incorrect.
5. Read **n bytes** of data: The target will send 8-bit (1 byte) sequences, MSB first, as many bytes as needed. Upon receiving a byte, the controller must generate an **ACK** signal to request another byte, or a **NACK** signal to indicate the end of transmission and request the target to release the BUS.
6. Send a **stop condition**: The controller must release the I2C BUS by generating a logic high (1) on SDA while SCL is high (1).

#### Register List

In an I2C target, registers are memory addresses that allow configuring or obtaining data from the target. There are two types of operations: read (R) and write (W).

<table><thead><tr><th width="114">Register</th><th width="194" align="center">Address (hexadecimal)</th><th width="100" align="center">Type</th><th width="118" align="center">No. Bytes</th><th>Description</th></tr></thead><tbody><tr><td>INPUT</td><td align="center">0x01</td><td align="center">R</td><td align="center">1</td><td>Each bit represents a logical state of an input, where the most significant bit (received first) corresponds to the state of input I8, following an order from highest to lowest.</td></tr><tr><td>STAT</td><td align="center">0x37</td><td align="center">R</td><td align="center">1</td><td>XNODE status, 0x00 if there are no errors, any other value means communication error.</td></tr><tr><td>FW</td><td align="center">0x38</td><td align="center">R</td><td align="center">3</td><td>Firmware version, in major, minor, and patch: 0x02.0x00.0x00</td></tr><tr><td>UART_ID</td><td align="center">0x39</td><td align="center">R/W - NV</td><td align="center">1</td><td>Allows reading and writing the ID index to a different uppercase letter from A (0x41) to Z (0x5A)</td></tr><tr><td>TW_ADD</td><td align="center">0x3A</td><td align="center">R/W - NV</td><td align="center">1</td><td>Allows reading and writing the device's I2C address to a different value from 1 (0x01) to 126 (0x7D). A reset or power-on sequence must happen for this changes to be applied</td></tr><tr><td>UART_EN</td><td align="center">0x3B</td><td align="center">W</td><td align="center">1</td><td>Enables (0x01) or disables (0x00) the device's UART interface.</td></tr><tr><td>SLEEP</td><td align="center">0x3C</td><td align="center">W</td><td align="center">1</td><td>Enables (0x01) or disables (0x00) deep sleep mode, the device will wake up if the controller writes the device's I2C address on the BUS.</td></tr><tr><td>RESET</td><td align="center">0x3D</td><td align="center">W</td><td align="center">1</td><td>Writing 0x01 resets the device.</td></tr><tr><td>WHO_AM_I</td><td align="center">0x3E</td><td align="center">R</td><td align="center">2</td><td>The first byte is the XNODE model, the second byte is the hardware revision</td></tr></tbody></table>

{% hint style="warning" %}
**Note:** The deep sleep mode of the X-NODE **XN01 - Digital Inputs** has a typical consumption of 5 uA, however, each input has a pull-up resistor of \~10kOhm. When the input is activated via switches or an external signal, consumption will be approximately 330uA per input.
{% endhint %}

**Non-volatile Registers (NV)**

Non-volatile registers are stored in the device's EEPROM memory, meaning they retain their values even if the device is powered off.

**INPUT Register Structure:**

<figure><img src="/files/Zt05VzDjxZ8kRaR30Tj3" alt=""><figcaption></figcaption></figure>

### I2C Arduino Framework Example

{% hint style="info" %}
Example code for [XC01 - R5](/en/user-manuals/xide/x-nodes/xc01-mcu-wifi-ble/r5/xc01-mcu-wifi-ble-esp32-s3.md). Check the manual to use our [XC01 - R5](https://docs.microside.com/en/user-manuals/xide/x-nodes/xn01-digital-inputs/a-r2/pages/TCKcf0xHk7ZZYxuwh2OW#v.-setup-and-usage) in **Arduino IDE/PlatformIO**
{% endhint %}

```cpp
#include <Arduino.h>
#include <Wire.h>

void setup()
{
  // Initialize serial monitor
  Serial.begin(115200);

  // Configure I2C communication pins
  Wire.setPins( 12, 13 );
  // Initialize I2C communication
  Wire.begin();

  // Select the register
  Wire.beginTransmission( 0x01 ); // Device address
  Wire.write( 0x01 ); // INPUT register address
  Wire.endTransmission();
}

void loop()
{
    uint8_t bytes_recv = 0;
    uint8_t inputs = 0;
    // Send start condition + address
    // + operation type + number of bytes to read
    bytes_recv = Wire.requestFrom( 0x01, 1 );

    // Confirm that 1 byte was received
    if ( bytes_recv != 1 ) {
        Serial.println( "Error" );
        delay( 1000 );
        return;
    }

    inputs = Wire.read();

    // Show the status in binary format (omits
    // leading 0's)
    Serial.print( "XN01A=" );
    Serial.println( inputs, BIN );

    delay( 1000 );
}
```

### **VI. Downloads**

<table data-card-size="large" data-view="cards"><thead><tr><th align="center"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td align="center"><mark style="color:green;"><strong>Schematic</strong></mark></td><td><a href="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FCThPVRmWZzIfmydz02c3%2Fschematic.pdf?alt=media&#x26;token=ce7c9c1f-3421-45c4-aa1a-99cca2172f7d">https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FCThPVRmWZzIfmydz02c3%2Fschematic.pdf?alt=media&#x26;token=ce7c9c1f-3421-45c4-aa1a-99cca2172f7d</a></td></tr><tr><td align="center"><mark style="color:green;"><strong>Dimensions</strong></mark></td><td><a href="https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FU3pHQiMzNXVmd02ndzQq%2Fdimentions.pdf?alt=media&#x26;token=d122cc96-4637-4904-ad3d-a3e0db7cd58b">https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2FU3pHQiMzNXVmd02ndzQq%2Fdimentions.pdf?alt=media&#x26;token=d122cc96-4637-4904-ad3d-a3e0db7cd58b</a></td></tr></tbody></table>
