# XN03 - Analog Inputs-Outputs

<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%252FU70sXWBMEPyuBI6acP6L%252FX-NODE%2520Entradas%2520y%2520Salidas%2520Anal%25C3%25B3gicas%2520XN03%2520MICROSIDE%2520XIDE%252001%2520.webp%3Falt%3Dmedia%26token%3Dcff96a13-9b56-4dc2-85c4-d97ef668e37c&#x26;width=768&#x26;dpr=1&#x26;quality=100&#x26;sign=d27f58e5&#x26;sv=2" alt=""><figcaption><p>XN03 - Analog Inputs- Outputs</p></figcaption></figure>

**X-NODE Analog Inputs-Outputs** is a module that allows you to generate up to 3 analog/PWM signals and read up to 4 analog signals (3 inputs + 1 potentiometer). The analog signal generation can be used to control proportional systems, PWM signals to control LED drivers, brushed motor drivers, etc. The analog signal reading can be used to create proportional control systems, measure battery and regulator voltage. All through a digital interface (UART/I2C) that is configurable, allowing you to connect multiple **X-NODE Analog Inputs-Outputs** simultaneously, expanding the number of analog/PWM outputs from 3 up to 381, analog inputs from 3 up to 381, and potentiometers from 1 up to 127.

{% hint style="warning" %}
The **X-NODE Analog Inputs-Outputs** is a device that operates at 3.3V. Before connecting it to a power source, make sure the voltage does not exceed 3.3V on any of the inputs.
{% endhint %}

### TABLE OF CONTENTS

1. [**How does it work?**](#i.-how-does-it-work)
2. [**Hardware Description**](#ii.-hardware-description)
3. [**Specifications**](#iii.-specifications)
4. [**Pinout**](#iv.-pinout)
5. [**Usage**](#v.-usage)
   * [**UART Protocol**](#uart-protocol)
   * [**UART Example Arduino Framework**](#uart-example-arduino-framework)
   * [**I2C Protocol** ](#i2c-protocol)
   * [**I2C Example Arduino Framework**](#i2c-example-arduino-framework)
6. [**Downloads**](#vi.-downloads)
   * [**Schematic**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F60L0iXekuA3YNOY0aqIu%2Fschematic.pdf?alt=media\&token=9ed4a9d0-caa8-48af-acc5-6fb5e4498658)
   * [**Dimensions**](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F0uKPpdW8jtZrE4D9PFIW%2Fdimensions.pdf?alt=media\&token=7cf6b960-d657-473b-8eca-b19280571d1c)

## I. How does it work?

The **X-NODE Analog Inputs-Outputs** is a module that integrates a single-turn potentiometer, an RGB LED, 3 holes for PWM signal access, and a connection port with 3 analog inputs and 3 analog outputs, 3.3VDC, and GND. The hardware controller allows its use without advanced hardware knowledge, as it is only necessary to send a series of ASCII commands via UART serial communication or using the I2C protocol, making the X-NODE able to communicate with any microcontroller based system, microprocessor, or industrial equipment. The potentiometer has a resistance value of 5 kΩ, a tolerance of ± 20%, and a power rating of 5 mW. The RGB LED can generate up to 16 million color combinations by configuring the intensity parameters of the primary colors (Red, Green, and Blue), with an average consumption of 20 mA and operation in a temperature range from 0 °C to 80 °C. The PWM outputs share the channel with the analog outputs, which should be considered when using these outputs; the resolution is 8 bits and the frequency, in the case of PWM signals, is 1.2 kHz. The analog inputs have a resolution of 10 bits, and the reading uses a multiplexer, so the maximum sampling frequency is up to \~37 ksps for each channel.

**X-NODE Analog Inputs-Outputs** is compatible with the [mikroBUS™](https://www.mikroe.com/mikrobus) standard from [Mikroe®](https://www.mikroe.com/) for easy use with a large ecosystem of hardware development kits. 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="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%252FeLeCwjy6cfcE6pl7kHj4%252Fuser-manual-hardware-description.webp%3Falt%3Dmedia%26token%3D89e5947a-ba32-45a7-b131-98e8f8dd4dbc&#x26;width=768&#x26;dpr=1&#x26;quality=100&#x26;sign=da7a53f7&#x26;sv=2" alt=""><figcaption></figcaption></figure>

1. 9 pin terminal block port for AWG 26 to 18 cables
2. Single turn potentiometer
3. JST connectors compatible with [Qwiic®](https://www.sparkfun.com/qwiic)
4. RGB LED indicator
5. PWM signal access holes
6. Hardware controller
7. UART <> I2C communication ports
8. X-NODE model
9. X-NODE type
10. [mikroBUS™](https://www.mikroe.com/mikrobus) standard connectors
11. Hardware version: A-R2
12. Main feature on the X-NODE

## III. Specifications

<table data-header-hidden><thead><tr><th width="137"></th><th></th></tr></thead><tbody><tr><td><strong>Applications</strong></td><td>Integration with IoT projects for general purpose use such as reading proporcional signals with actuators and motors. Potentiometer useful for motion control, system activation, or precise component calibration. RGB LED ideal for visual alerts, ambient lighting in smart homes, as well as status indicator in different components, alarms, and sequences.</td></tr><tr><td><strong>Features</strong></td><td>Single-turn potentiometer with adjustable angle, resistance value of 5 kΩ, tolerance of ± 20%, and power rating of 5 mW. RGB LED capable of generating up to 16 million colors from a PWM signal, with an average consumption of 20 mA and operation in a temperature range from 0 to 80 °C. Connection port with male pins and holes for 3 external analog inputs and 3 outputs, 3.3V, and GND. PWM signal access terminal block.</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>65.09 x 25.38 x 26.98 mm</td></tr><tr><td><strong>Voltage</strong></td><td>3.3 VDC</td></tr></tbody></table>

## **IV. Pinout**

The following table shows the pinout of the **X-NODE Analog Inputs-Outputs** with respect to the [mikroBUS™](https://www.mikroe.com/mikrobus) standard (the latter is 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=1&#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, through the I2C protocol.

### UART Protocol

#### Configuration

UART communication uses the following configuration:

* 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 a line ending.

**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 protocol.

<figure><img src="https://3632356340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwzhjxMFtAHZqHlRBU68T%2Fuploads%2F9mhidnWVAw83kcYZSCyT%2FProtocol%20UART%20X-NODE%20Analog%20Inputs%20-%20Outputs%20%20%20XN03%20XIDE.png?alt=media&#x26;token=73e81500-588c-4b45-b7f8-32ed482adc40" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Note:** From this point on, the default index of the X-NODE **XN03 - Analog Inputs-Outputs** will be used for the rest of the manual: **XN03A**.
{% endhint %}

**Command list**

<table data-header-hidden><thead><tr><th width="229"></th><th></th></tr></thead><tbody><tr><td><strong>XN03A?</strong></td><td>Checks if communication was successfully established.<br><strong>Response:</strong> OK</td></tr><tr><td><strong>XN03A+V</strong></td><td>Gets the current firmware version integrated in the X-NODE.<br><strong>Response:</strong> XN03A=Version<br><strong>Example:</strong> XN03A=2.0.0</td></tr><tr><td><strong>XN03A+ID=(A-Z)</strong></td><td>Changes the ID index to a different uppercase letter from A to Z. Once changed, to change it again you must use the new ID.<br><strong>Response:</strong> OK<br><strong>Example to send:</strong> XN03C+ID=H</td></tr><tr><td><strong>XN03A+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>Example to send:</strong> XN03A+TW=28</td></tr><tr><td><strong>XN03A+GP</strong></td><td>Gets the potentiometer value given by its position. Returns a relative value from 0 to 100.<br><strong>Response:</strong> XN03A=VAL<br><strong>Example:</strong> XN03A=67</td></tr><tr><td><strong>XN03A+S=(Out1/PWM1/Red),(Out2/PWM2/Green),(Out3/PWM3/Blue)</strong></td><td>Changes the state of each of the 3 outputs, either directly on the analog output port, PWM access holes, or the RGB LED indicator colors, with values between 0 and 255. Optionally, sending a fourth value between 0 and 255 allows scaling the channels (RGBa).<br><strong>Response:</strong> OK<strong>Example to send:</strong> XN03A+S=0,25,100</td></tr><tr><td><strong>XN03A+G(P,1,2,3)</strong></td><td>Gets the potentiometer value by its position or the analog inputs (1,2,3). Returns a relative value from 0 to 100.<br><strong>Response:</strong> XN03A=VAL<br><strong>Example to send:</strong> XN03A+GP<br><strong>Example response:</strong> XN03A=67</td></tr><tr><td><strong>XN03A+A(P,1,2,3)</strong></td><td>Gets the potentiometer value by its position or the analog inputs (1,2,3) with ADC resolution (10 bits). Returns a relative value from 0 to 1023.<br><strong>Response:</strong> XN03A=VAL<br><strong>Example to send:</strong> XN03A+AP<br><strong>Example response:</strong> XN03A=512</td></tr></tbody></table>

#### Line ending

The X-NODE will only respond to a command when a set of end-of-line characters are 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 computers 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, if the command exists, and if it is immediately ended with the **\<CR+LF>** characters, then the node will send a response.

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

### UART Example Arduino Framework

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

```cpp
// This example allows you to control the intensity of the
// X-NODE's RGB LED using the potentiometer.

#include "Arduino.h"

// Set this value to change the RGB color
const uint8_t rgb_color[] = { 227, 235, 23 };

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

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

void loop() {
  // Control the intensity of the RGB LED with the XN03 potentiometer

  // Clear the buffer
  if (Serial2.available()) {
    Serial2.read();
  }

  // Send the command to get the potentiometer position
  // The \r\n characters represent the
  // <CR+LF> characters in C/C++ programming language
  Serial2.print("XN03A+GP\r\n");

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

  // If the response starts with the ID
  // then communication was successful
  if (!pot_value.startsWith("XN03A=")) {
    Serial.println("Error");
    delay(1000);
    return;
  }

  // Convert the ASCII value to a decimal value
  int brightness = pot_value.substring(pot_value.indexOf('=') + 1).toInt();

  // Clear the buffer
  if (Serial2.available()) {
    Serial2.read();
  }

  // Send the command to change the output values
  Serial2.print("XN03A+S=");
  Serial2.print(rgb_color[0]);
  Serial2.print(",");
  Serial2.print(rgb_color[1]);
  Serial2.print(",");
  Serial2.print(rgb_color[2]);
  Serial2.print(",");
  Serial2.println(brightness);

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

  // If the response is "OK"
  // then communication was successful
  if (!success.startsWith("OK")) {
    Serial.println("Error");
    delay(1000);
    return;
  }

  delay(100);
}
```

### 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="https://3632356340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwzhjxMFtAHZqHlRBU68T%2Fuploads%2FtAwoujMxqhKeghScJrMs%2FProtocol%20I2C%20XN03%20Analog%20Input%20-%20Outputs%20XIDE.jpg?alt=media&#x26;token=0a923f07-1718-426d-afab-9643ddf26050" 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 **XN03A+TW=(1-126)** command.
{% endhint %}

#### Write

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 whether 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 previously sent address exists on the I2C BUS. If no response (1) is received, it means there was a communication error or the address is incorrect.
5. Write **n bytes** of data: The controller will write in 8 bit (1 byte) sequences, most significant bit first (MSB), n number of bytes to write to the register, the target will send an **acknowledge (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 the SDA pin while SCL is high (1).

#### Read

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 whether 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 previously sent address exists on the I2C BUS. If no response (1) is received, it means 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, most significant bit first (MSB), n number of bytes, upon receiving a byte, the controller must generate an **acknowledge (ACK)** signal to request 1 more byte, or a **not acknowledge (NACK)** signal to indicate that the transmission has ended 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 the SDA pin 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="120">Register</th><th width="145" align="center">Address (hexadecimal)</th><th width="88" align="center">Type</th><th width="95" align="center">No. Bytes</th><th>Description</th></tr></thead><tbody><tr><td>O1_RED</td><td align="center">0x01</td><td align="center">R/W</td><td align="center">1 to 4</td><td>The first byte represents the O-1 (red) DAC channel, the second the O-2 (green) channel, the third the O-3 (blue) channel, sending a 4th byte allows scaling the channel intensities (RGBa)</td></tr><tr><td>O2_GREEN</td><td align="center">0x02</td><td align="center">R/W</td><td align="center">1 to 3</td><td>The first byte represents the O-2 (green) DAC channel, the second the O-3 (blue) channel, sending a 3rd byte allows scaling the intensities of channels O-2 and O-3 (GBa), the first channel is unaffected.</td></tr><tr><td>O3_BLUE</td><td align="center">0x03</td><td align="center">R/W</td><td align="center">1 to 2</td><td>The first byte represents the O-3 (blue) DAC channel, sending a 2nd byte allows scaling the intensity of channel 3 (Ba), channels O-1 and O-2 are unaffected.</td></tr><tr><td>IN_POT</td><td align="center">0x10</td><td align="center">R</td><td align="center">1</td><td>Returns the ADC value of the potentiometer scaled from 0 (0x00) to 100 (0x64)</td></tr><tr><td>IN1</td><td align="center">0x11</td><td align="center">R</td><td align="center">1</td><td>Returns the ADC value of channel I-1 scaled from 0 (0x00) to 100 (0x64)</td></tr><tr><td>IN2</td><td align="center">0x12</td><td align="center">R</td><td align="center">1</td><td>Returns the ADC value of channel I-2 scaled from 0 (0x00) to 100 (0x64)</td></tr><tr><td>IN3</td><td align="center">0x13</td><td align="center">R</td><td align="center">1</td><td>Returns the ADC value of channel I-3 scaled from 0 (0x00) to 100 (0x64)</td></tr><tr><td>ADC_POT</td><td align="center">0x20</td><td align="center">R</td><td align="center">2</td><td>Returns the ADC value of the potentiometer, with 10-bit resolution, 0 (0x00) to 1023 (0x3FF).</td></tr><tr><td>ADC1</td><td align="center">0x21</td><td align="center">R</td><td align="center">2</td><td>Returns the ADC value of channel I-1, with 10-bit resolution, 0 (0x00) to 1023 (0x3FF).</td></tr><tr><td>ADC2</td><td align="center">0x22</td><td align="center">R</td><td align="center">2</td><td>Returns the ADC value of channel I-2, with 10-bit resolution, 0 (0x00) to 1023 (0x3FF).</td></tr><tr><td>ADC3</td><td align="center">0x23</td><td align="center">R</td><td align="center">2</td><td>Returns the ADC value of channel I-3, with 10-bit resolution, 0 (0x00) to 1023 (0x3FF).</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 one 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) the device's deep sleep, 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>

**Non-volatile registers (NV)**

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

**OUT1, OUT2, OUT3 register structure:**

<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%252FcaU5nRdVIJp5KXyT31mi%252Fuser-manual-i2c-protocol-register-outputs-write.png%3Falt%3Dmedia%26token%3D46118953-9171-4c4a-a7bd-6c4f1faa8729&#x26;width=768&#x26;dpr=1&#x26;quality=100&#x26;sign=eb7bd0b1&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**IN\_POT, IN1, IN2, IN3 register structure:**

<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%252FKad0iVwZgU5CFhBN6o9r%252Fuser-manual-i2c-protocol-register-inputs-read.png%3Falt%3Dmedia%26token%3D62d42ca7-ce74-4b7d-9c70-d473959f224f&#x26;width=768&#x26;dpr=1&#x26;quality=100&#x26;sign=93ef0fc3&#x26;sv=2" alt=""><figcaption></figcaption></figure>

**ADC\_POT, ADC1, ADC2, ADC3 register structure:**

<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%252FgmEk0q5UiCYbvtE9tdgD%252Fuser-manual-i2c-protocol-register-inputs-raw-read.png%3Falt%3Dmedia%26token%3Dea9a034b-7d7f-483c-8941-db987940cd9a&#x26;width=768&#x26;dpr=1&#x26;quality=100&#x26;sign=f73b746d&#x26;sv=2" alt=""><figcaption></figcaption></figure>

### I2C Example Arduino Framework

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

```cpp
// This example allows you to control the intensity of the
// X-NODE's RGB LED using the potentiometer.

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

// Set this value to change the RGB color
const uint8_t rgb_color[] = { 227, 235, 23 };

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

  // Set the I2C communication pins
  Wire.setPins( 12, 13 );
  // Initialize I2C communication
  Wire.begin();
}

void loop() {
  // Control the intensity of the RGB LED with the XN03 potentiometer

  uint8_t bytes_recv = 0;
  uint8_t pot = 0;

  // Send start condition + address
  // + operation type
  Wire.beginTransmission(0x03);
  // Write the potentiometer register address (0x1E)
  Wire.write(0x10);

  // Check if the operation was successful
  if (Wire.endTransmission() != 0) {
    Serial.println("Error requesting register");
    delay(1000);
    return;
  }

  // Send start condition + address
  // + operation type + number of bytes to read
  bytes_recv = Wire.requestFrom(0x03, 1);

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

  pot = Wire.read();

  // Send start condition + address
  // + operation type
  Wire.beginTransmission(0x03);

  // Write the channel 1 register address (0x01)
  Wire.write(0x01);
  // Write the value for channel 1 (red)
  Wire.write(rgb_color[0]);
  // Writing sequentially assigns the value for channel 2 (green)
  Wire.write(rgb_color[1]);
  // Channel 3 (blue)
  Wire.write(rgb_color[2]);
  // And the intensity
  Wire.write(pot);

  if (Wire.endTransmission() != 0){
    Serial.println("Error writing RGB value");
    delay(1000);
  }

  delay(100);
}
```

## 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%2F60L0iXekuA3YNOY0aqIu%2Fschematic.pdf?alt=media&#x26;token=9ed4a9d0-caa8-48af-acc5-6fb5e4498658">https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F60L0iXekuA3YNOY0aqIu%2Fschematic.pdf?alt=media&#x26;token=9ed4a9d0-caa8-48af-acc5-6fb5e4498658</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%2F0uKPpdW8jtZrE4D9PFIW%2Fdimensions.pdf?alt=media&#x26;token=7cf6b960-d657-473b-8eca-b19280571d1c">https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbyV2zAlQAiqg46a3Lr8z%2Fuploads%2F0uKPpdW8jtZrE4D9PFIW%2Fdimensions.pdf?alt=media&#x26;token=7cf6b960-d657-473b-8eca-b19280571d1c</a></td></tr></tbody></table>
