diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_CE.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_CE.pdf new file mode 100644 index 0000000000..b916279800 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_CE.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_CE_EMC.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_CE_EMC.pdf new file mode 100644 index 0000000000..d567d6081d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_CE_EMC.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_FCC.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_FCC.pdf new file mode 100644 index 0000000000..adacc98906 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_FCC.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_IC.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_IC.pdf new file mode 100644 index 0000000000..07a4db2eb5 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_IC.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_RCM.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_RCM.pdf new file mode 100644 index 0000000000..3f6f072f26 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_RCM.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_RoHS.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_RoHS.pdf new file mode 100644 index 0000000000..b601836f7b Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_RoHS.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_UKCA.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_UKCA.pdf new file mode 100644 index 0000000000..8a7be0eb97 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_UKCA.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_VCCI.pdf b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_VCCI.pdf new file mode 100644 index 0000000000..9601103c60 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/certifications/Arduino_ABX00142-CERT_VCCI.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/compatibility.yml b/content/hardware/03.nano/boards/nano-r4/compatibility.yml new file mode 100644 index 0000000000..efaa321e7c --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/compatibility.yml @@ -0,0 +1,12 @@ +software: + - arduino-ide + - arduino-cli + - cloud-editor + - iot-cloud +hardware: + boards: ~ + carriers: ~ + shields: + - nano-connector-carrier + - nano-screw-terminal-adapter + - nano-motor-carrier \ No newline at end of file diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/ABX00142-pinout.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/ABX00142-pinout.png new file mode 100644 index 0000000000..86961d9714 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/ABX00142-pinout.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4-Qwiic-connector.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4-Qwiic-connector.png new file mode 100644 index 0000000000..2deed1862a Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4-Qwiic-connector.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4_Block_Diagram.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4_Block_Diagram.png new file mode 100644 index 0000000000..8ad021b746 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4_Block_Diagram.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4_Power_Tree.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4_Power_Tree.png new file mode 100644 index 0000000000..7060b5f1a1 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/Nano_R4_Power_Tree.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/board-connectors.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/board-connectors.png new file mode 100644 index 0000000000..75809a5836 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/board-connectors.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/featured.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/featured.png new file mode 100644 index 0000000000..5900de8179 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/featured.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/mechanicalDrawingNanoR4.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/mechanicalDrawingNanoR4.png new file mode 100644 index 0000000000..edb2dabb62 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/mechanicalDrawingNanoR4.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/assets/topViewNanoR4.png b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/topViewNanoR4.png new file mode 100644 index 0000000000..794861b14c Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/datasheet/assets/topViewNanoR4.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/datasheet/datasheet.md b/content/hardware/03.nano/boards/nano-r4/datasheet/datasheet.md new file mode 100644 index 0000000000..362128b196 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/datasheet/datasheet.md @@ -0,0 +1,430 @@ +--- +identifier: ABX00142-ABX00143 +title: Arduino® Nano R4 +variant: 'Datasheet' +type: maker +--- + +![](assets/featured.png) + +# Description + +The Arduino® Nano R4 is a Nano form factor board based on the RA4M1 series microcontroller from Renesas (R7FA4M1AB3CFM#HA0), which embeds a 48 MHz Arm® Cortex®-M4 microprocessor. The Nano R4's memory is larger than its predecessors, with 256 kB flash, 32 kB SRAM and 8 kB data memory (EEPROM). The Nano R4 board operates at 5 V, making it hardware compatible with Nano form factor accessories with the same operating voltage. + +The Nano R4 is available in two variants: without headers (SKU: ABX00142) and with pre-installed headers (SKU: ABX00143). + +Leverage the on-board Qwiic connector for seamless integration with Modulinos, enabling quick and reliable expansion of your project. + +# Target areas: + +Digital Signal Processing, System on Module, Edge Computing, Rapid Prototyping + +# Contents + +## Application Examples +
+ +**Effortless Transition:** Move seamlessly from prototyping to production with the familiar RA4M1 microcontroller present already in the UNO R4 family. + +**Entry level projects:** If this is your first project within coding and electronics, the Nano R4 is a good fit. It is easy to get started with and has a lot of online documentation (both official + community). + +**Easy power management:** The Nano R4 supports input voltages from 6 to 21 V. It removes the need for additional circuitry required to step down the voltage. + +**Enhanced Connectivity:** Features an onboard Qwiic connector for easy integration with a wide range of sensors and peripherals. Exposing a new I2C connection apart from the standard one found on A4 and A5 pins. The Qwiic connector makes the Nano R4 compatible with the Arduino Modulino boards. + +**Cross compatibility:** The Nano form factor automatically makes it compatible with hundreds of existing third-party shields and other official accessories. +
+ +## Features +### General Specifications Overview + +The Nano R4 is an evolution of its predecessor, the Nano Classic, which was previously based on 8-bit AVR microcontrollers. There are thousands of guides, tutorials and books written about the Nano board, where Nano R4 continues its legacy. + +The board features the standard 14x digital I/O ports, 8x analog channels, dedicated pins for I2C, SPI and UART +connections. Compared to its predecessors the board has a much larger memory: 8x times more flash memory (256 kB) and 16x times more SRAM (32 kB). + +| Feature | Description | +| --------------------- | ---------------------------------------------------------------------------------------------------------------- | +| Microcontroller | R7FA4M1AB3CFM 32-bit Arm® Cortex®-M4 | +| Frequency | 48 MHz | +| Internal Memory | 256 kB Flash / 32 kB RAM / 8 kB EEPROM | +| USB Connectivity | USB-C® port for power and data | +| Power | Input voltage (VIN): 6-21 V / Power via USB-C® at 5 V | +| Digital Inputs | GPIO (21x - All exposed I/O can be used as digital), PWM (6x) | +| Analog Inputs | 14-bit ADC (8x) | +| Real-time Clock (RTC) | Yes (external crystal oscillator included) | +| Communication | UART (1x), I2C (2x) (5 V over breakout and 3.3 V over Qwiic), SPI (1x), CAN (external transceiver required) (1x) | +| Dimensions | 18 mm x 45 mm | +| Operating Temperature | -40 °C to +85 °C | + +### Microcontroller + +The Nano R4 is based on the 32-bit RA4M1 series microcontroller, **R7FA4M1AB3CFM#HA0**, from Renesas, which uses a 48 MHz Arm® Cortex®-M4 microprocessor with a floating point unit (FPU). + +On the Nano R4, the operating voltage is fixed at 5 V to be fully retro compatible with shields, accessories and circuits originally designed for older Nano revisions. + +| Component | Details | +| -------------------------------------- | --------------------------------------------------------------------------- | +| R7FA4M1AB3CFM Processor | Arm® Cortex®-M4 core at up to 48 MHz | +| Flash Memory | 256 kB of Flash Memory | +| Programming Memory | 32 kB of RAM | +| Data Memory | 8 kB of EEPROM | +| Real-time Clock (RTC) | Yes (external crystal oscillator included) | +| Direct Memory Access Controller (DMAC) | Yes (4x) | +| ADC | Yes (14-bit) | +| DAC | Yes (12-bit) | +| Operational Amplifier (OPAMP) | Yes (ranges specified on dedicated [section](#operational-amplifier-opamp)) | +| CAN bus | Yes (external transceiver required) | + + +For more technical details on this microcontroller, visit [Renesas - RA4M1 series official documentation](https://www.renesas.com/us/en/products/microcontrollers-microprocessors/ra-cortex-m-mcus/ra4m1-32-bit-microcontrollers-48mhz-arm-cortex-m4-and-lcd-controller-and-cap-touch-hmi). + +### USB-C® Connector + +The Nano R4 has one USB-C® port, used to power and program your board as well as send and receive serial communication. + +
+You should not power the board with more than 5 V via the USB-C® port. +
+ +### Digital Analog Converter (DAC) + +The Nano R4 has a DAC with up to 12-bit resolution attached to the A0 analog pin. A DAC is used to convert a digital signal to an analog signal. + +### Operational Amplifier (OPAMP) + +The Nano R4 features one Operational Amplifier accessible through the board analog pins. See the [pinout](#pinout) section for details. + +| Parameter | Conitions | Min | Typ | Max | Unit | +| ----------------------- | --------------- | --- | --- | ------- | ---- | +| Common mode input range | Low power mode | 0.2 | - | VCC-0.5 | V | +| Common mode input range | High-speed mode | 0.3 | - | VCC-0.6 | V | +| Output voltage range | Low power mode | 0.1 | - | VCC-0.1 | V | +| Output voltage range | High-speed mode | 0.1 | - | VCC-0.1 | V | + +### Qwiic I2C Connector + +The I2C Qwiic connector SM04B-SRSS-TB(LF)(SN) is connected to a secondary I2C bus on the board. This connector is powered via 3.3 V following the Qwiic standard system and makes the Nano R4 compatible with the Arduino Modulino nodes. + +The Qwiic connector logic level is fixed to 3.3 V, and it is translated to 5 V to communicate with the RA4M1 microcontroller as illustrated in the figure below: + +![Arduino Nano R4 Qwiic Connector](assets/Nano_R4-Qwiic-connector.png) + +The standard I2C is accessible through the Nano breakout pins A4 for SDA and A5 for SCL as its predecessors. + +
+A4 and A5 are connected to the main I2C bus, these pins should not be used as ADC inputs whenever the bus is in use. You can however connect I2C devices to each of these pins and connectors simultaneously. +
+ +### Realtime Clock (RTC) + +The Nano R4 features a Real-time Clock allowing you to keep accurate time (date and clock), even when the board is powered off. This is ideal for data logging, scheduling tasks, or timestamping events. + +The Realtime Clock (RTC) has two counting modes: calendar count mode and binary count mode, both are controlled by the register settings. + +- For calendar count mode, the RTC has a 100-year calendar from 2000 to 2099 and automatically adjusts dates for leap years. +- For binary count mode, the RTC counts seconds and retains the information as a serial value. Binary count mode can be used for calendars other than the Gregorian (Western) calendar. + +
+The Nano R4 features an external 16 MHz crystal oscillator that improve considerably the accuracy of the RTC and other sub-clock dependent peripherals. +
+ +### Board Actuators + +The Nano R4 features an RGB LED and single color built-in LED, both can be controlled through the Nano R4 GPIOs. See the [pinout](#pinout) section for a detailed overview. + +### Related Products + +- Arduino Nano (A000005) +- Arduino® UNO R4 Minima (ABX00080) +- Arduino® UNO R4 WiFi (ABX00087) +- Arduino Modulino nodes +- Nano Connector Carrier (ASX00061) + +## Power and Ratings +### Recommended Operating Conditions + +| Symbol | Description | Min | Typ | Max | Unit | +| --------------- | -------------------------------- | --- | --- | ---- | ---- | +| VIN | Input voltage from VIN pad | 6.0 | 7.0 | 21.0 | V | +| VUSB | Input voltage from USB connector | 4.8 | 5.0 | 5.5 | V | +| TOP | Operating Temperature | -40 | 25 | 85 | °C | + +**Note:** VDD controls the logic level and is connected to the 5 V power rail. VAREF set the reference for the analog logic. + +### Power Options + +Power can either be supplied via the VIN pin, or via USB-C® connector. If power is supplied via VIN, the MP2322GQH buck converter steps the voltage down to 5 V. + +A power OR circuit manages the selection between the USB and the +5 VDC output of the buck converter supplied from VIN, automatically routing the available voltage to the system's main power rail. + +
+When using the 3V3 pin to power external peripherals, notice that above 150 mA the board may become very hot due to LDO regulator functioning basis. +
+ +#### Power Tree + +The following diagram illustrates the Nano R4 main system power architecture. + +![Arduino Nano R4 Power Tree](assets/Nano_R4_Power_Tree.png) + +### GPIO Voltage + +The Nano R4 operates at 5 V as do all pins on this board except for the **Qwiic** connector that works at **3.3 V**. This connector draws power from the AP2112K-3.3TRG1 regulator. + +### GPIO Current + +The GPIOs on the R7FA4M1AB3CFM microcontroller can handle up to **8 mA**. Never connect devices that draw higher current directly to a GPIO. + +In case you need to drive external devices that require more current, e.g. high brightness LEDs, use an external current amplifier interface (e.g. a MOSFET or a transistor). + +### RTC Battery Backup + +The Nano R4 features a battery backup function. It can be powered through the **VBATT** pin (see [pinout](#pinout) section). +The battery backup will power the RTC, the 32.768 kHz oscillators, the wakeup control and the backup memory. + +During normal operation, the battery powered area is powered by the main power supply, which is the VCC pin. When a VCC voltage drop is detected, the power source is switched to +the dedicated battery backup power pin, the VBATT pin. When the voltage rises again, the power source is switched from the VBATT pin to the VCC pin. + +| Parameter | Min | Typ | Max | Unit | +| ------------------------------------------------------- | ---- | ---- | ---- | ---- | +| VBATT power supply voltage | 1.6 | - | 3.6 | V | +| Voltage level for switching to battery backup (falling) | 1.99 | 2.09 | 2.19 | V | + +
+ +## Functional Overview + +The core of the Nano R4 is the R7FA4M1AB3CFM microcontroller from Renesas. The board also contains +several peripherals connected to its microcontroller. + +### Pinout + +The Nano breakout connectors pinout is shown in the following figure. + +![Pinout for Nano R4](assets/ABX00142-pinout.png) + +#### Analog (JP1) + +| Pin | Function | Type | Description | +| --- | --------- | --------- | --------------------------------------- | +| 1 | D13 / SCK | Digital | Serial Clock | +| 2 | +3V3 | Power Out | +3V3 Power Rail | +| 3 | B0 / AREF | Analog | Analog Reference | +| 4 | A0 | Analog | Analog input 0 / DAC | +| 5 | A1 | Analog | Analog input 1 / OPAMP + | +| 6 | A2 | Analog | Analog input 2 / OPAMP - | +| 7 | A3 | Analog | Analog input 3 / OPAMP Out | +| 8 | A4 | Analog | Analog input 4 / I²C Serial Data (SDA) | +| 9 | A5 | Analog | Analog input 5 / I²C Serial Clock (SCL) | +| 10 | A6 | Analog | Analog input 6 | +| 11 | A7 | Analog | Analog input 7 | +| 12 | 5V | Power | USB power (5 V) | +| 13 | BOOT1 | Mode | Board Reset 1 | +| 14 | GND | Power | Ground | +| 15 | VIN | Power | Voltage Input | + +#### Digital (JP2) + +| Pin | Function | Type | Description | +| --- | ---------- | -------- | --------------------------------------- | +| 15 | D12 / CIPO | Digital | Controller In Peripheral Out | +| 14 | D11 / COPI | Digital | Controller Out Peripheral In / PWM | +| 13 | D10 / CS | Digital | Chip Select / PWM | +| 12 | D9 | Digital | Digital pin 9 / PWM | +| 11 | D8 | Digital | Digital pin 8 | +| 10 | D7 | Digital | Digital pin 7 | +| 9 | D6 | Digital | Digital pin 6 / PWM | +| 8 | D5 | Digital | Digital pin 5 / PWM / CAN (RX) | +| 7 | D4 | Digital | Digital pin 4 / CAN (TX) | +| 6 | D3 | Digital | Digital pin 3 / PWM | +| 5 | D2 | Digital | Digital pin 2 | +| 4 | GND | Power | Ground | +| 3 | RST | Internal | Reset (features a button) | +| 2 | D0/RX | Digital | Digital pin 0 / Serial Receiver (RX) | +| 1 | D1/TX | Digital | Digital pin 1 / Serial Transmitter (TX) | + + +### Block Diagram + +An overview of the Nano R4 high-level architecture is illustrated in the figure below. + +![Arduino Nano R4 Block Diagram](assets/Nano_R4_Block_Diagram.png) + +## Board Topology +### Overall View + +![Top View of Arduino Nano R4](assets/topViewNanoR4.png) + +| **Reference** | **Description** | +| ------------- | ---------------------------------------- | +| U1 | R7FA4M1AB3CFM Microcontroller IC | +| U2 | MP2322GQH Buck Converter | +| U3 | AP2112K-3.3TRG1 Dropout linear regulator | +| PB1 | RESET Button | +| JP1 | Analog input/output headers | +| JP2 | Digital input/output headers | +| J1 | CX90B-16P USB-C® connector | +| J2 | I2C Qwiic connector | +| DL1 | RGB LED | + + +## Device Operation + +### Getting Started - IDE + +If you want to program your Nano R4 while offline you need to install the Arduino® Desktop IDE **[1]**. To connect the Nano R4 to your computer, you will need a Type-C® USB cable, which can also provide power to the board, as indicated by the LED (DL3). + +### Getting Started - Arduino Cloud Editor + +All Arduino boards, including this one, work out-of-the-box on the Arduino Cloud Editor **[2]**, by just installing a simple plugin. + +The Arduino Cloud Editor is hosted online, therefore it will always be up-to-date with the latest features and support for all boards. Follow **[3]** to start coding on the browser and upload sketches onto your board. + +### Online Resources + +Now that you have gone through the basics of what you can do with the board you can explore the endless possibilities it provides by checking exciting projects on Arduino Project Hub **[4]**, the Arduino Library Reference **[5]**, and the online store **[6]**; where you will be able to complement your board with sensors, actuators and more. + +### Board Recovery + +All Arduino boards have a built-in bootloader which allows flashing the board via USB. In case a sketch locks up the processor and the board is not reachable anymore via USB, it is possible to enter bootloader mode by double-tapping the reset button right after the power-up. + +
+ +## Mechanical Information + +The Nano R4 is a one side 43.18 mm x 17.78 mm board with a USB-C® port overhanging the top edge. + +The Nano R4 (ABX00142) has dual castellated/through-hole pins around the two long edges and a Qwiic connector on the bottom edge. + +The Nano R4 with headers pre-installed (ABX00143) is also available, providing convenient access for probing and testing. + +### Board Dimensions +Nano R4 board outline and mounting holes dimensions can be seen in following figure; all the dimensions are in mm. + +![Mechanical View of Arduino Nano R4](assets/mechanicalDrawingNanoR4.png) + +The Nano R4 has four 1.65 mm drilled mounting holes for mechanical fixing. + +### Board Connectors + +Connectors of the Nano R4 are place on the top side of the board, their placement can be seen in the figure below; all the dimensions are in mm. + +![Mechanical View of Arduino Nano R4's Connectors](assets/board-connectors.png) + +

+The Nano R4 was designed to be usable as a surface-mount module and presents a dual inline package (DIP) format with the Nano-styled header connectors on a 2.54 mm pitch grid with 1 mm holes. +

+ +## Certifications + +### Certificactions Summary + +| **Certification** | **Status** | +| :-----------------: | :--------: | +| CE (European Union) | Yes | +| RoHS | Yes | +| REACH | Yes | +| WEEE | Yes | +| FCC (USA) | Yes | +| IC (Canada) | Yes | +| UKCA (UK) | Yes | +| RCM (Australia) | Yes | + +### Declaration of Conformity CE DoC (EU) + +We declare under our sole responsibility that the products above are in conformity with the essential requirements of the following EU Directives and therefore qualify for free movement within markets comprising the European Union (EU) and European Economic Area (EEA). + +### Declaration of Conformity to EU RoHS & REACH 211 01/19/2021 + +Arduino boards are in compliance with RoHS 2 Directive 2011/65/EU of the European Parliament and RoHS 3 Directive 2015/863/EU of the Council of 4 June 2015 on the restriction of the use of certain hazardous substances in electrical and electronic equipment. + +| **Substance** | **Maximum Limit (ppm)** | +| -------------------------------------- | ----------------------- | +| Lead (Pb) | 1000 | +| Cadmium (Cd) | 100 | +| Mercury (Hg) | 1000 | +| Hexavalent Chromium (Cr6+) | 1000 | +| Poly Brominated Biphenyls (PBB) | 1000 | +| Poly Brominated Diphenyl ethers (PBDE) | 1000 | +| Bis(2-Ethylhexyl) phthalate (DEHP) | 1000 | +| Benzyl butyl phthalate (BBP) | 1000 | +| Dibutyl phthalate (DBP) | 1000 | +| Diisobutyl phthalate (DIBP) | 1000 | + +Exemptions : No exemptions are claimed. + +Arduino Boards are fully compliant with the related requirements of European Union Regulation (EC) 1907 /2006 concerning the Registration, Evaluation, Authorization and Restriction of Chemicals (REACH). We declare none of the SVHCs ([https://echa.europa.eu/web/guest/candidate-list-table](https://echa.europa.eu/web/guest/candidate-list-table)), the Candidate List of Substances of Very High Concern for authorization currently released by ECHA, is present in all products (and also package) in quantities totaling in a concentration equal or above 0.1%. To the best of our knowledge, we also declare that our products do not contain any of the substances listed on the "Authorization List" (Annex XIV of the REACH regulations) and Substances of Very High Concern (SVHC) in any significant amounts as specified by the Annex XVII of Candidate list published by ECHA (European Chemical Agency) 1907 /2006/EC. + +### Conflict Minerals Declaration + +As a global supplier of electronic and electrical components, Arduino is aware of our obligations with regards to laws and regulations regarding Conflict Minerals, specifically the Dodd-Frank Wall Street Reform and Consumer Protection Act, Section 1502. Arduino does not directly source or process conflict minerals such as Tin, Tantalum, Tungsten, or Gold. Conflict minerals are contained in our products in the form of solder, or as a component in metal alloys. As part of our reasonable due diligence Arduino has contacted component suppliers within our supply chain to verify their continued compliance with the regulations. Based on the information received thus far we declare that our products contain Conflict Minerals sourced from conflict-free areas. + +### FCC Caution + +Any Changes or modifications not expressly approved by the party responsible for compliance could void the user’s authority to operate the equipment. + +This device complies with part 15 of the FCC Rules. Operation is subject to the following two conditions: + +(1) This device may not cause harmful interference + +(2) this device must accept any interference received, including interference that may cause undesired operation. + +**FCC RF Radiation Exposure Statement:** + +1. This Transmitter must not be co-located or operating in conjunction with any other antenna or transmitter. + +2. This equipment complies with RF radiation exposure limits set forth for an uncontrolled environment. + +3. This equipment should be installed and operated with a minimum distance of 20 cm between the radiator & your body. + +English: +User manuals for licence-exempt radio apparatus shall contain the following or equivalent notice in a conspicuous location in the user manual or alternatively on the device or both. This device complies with Industry Canada licence-exempt RSS standard(s). Operation is subject to the following two conditions: + +(1) this device may not cause interference + +(2) this device must accept any interference, including interference that may cause undesired operation of the device. + +French: +Le présent appareil est conforme aux CNR d’Industrie Canada applicables aux appareils radio exempts de licence. L’exploitation est autorisée aux deux conditions suivantes : + +(1) l’ appareil nedoit pas produire de brouillage + +(2) l’utilisateur de l’appareil doit accepter tout brouillage radioélectrique subi, même si le brouillage est susceptible d’en compromettre le fonctionnement. + +**IC SAR Warning:** + +English +This equipment should be installed and operated with a minimum distance of 20 cm between the radiator and your body. + +French: +Lors de l’ installation et de l’ exploitation de ce dispositif, la distance entre le radiateur et le corps est d ’au moins 20 cm. + +**Important:** The operating temperature of the EUT can’t exceed 85 ℃ and shouldn’t be lower than -40 ℃. + +Hereby, Arduino S.r.l. declares that this product is in compliance with essential requirements and other relevant provisions of Directive 201453/EU. This product is allowed to be used in all EU member states. + +## Company Information + +| Company name | Arduino S.r.l. | +| --------------- | -------------------------------------------- | +| Company Address | Via Andrea Appiani, 25 - 20900 MONZA (Italy) | + +## Reference Documentation + +| Ref | Link | +| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Arduino IDE (Desktop) | [https://www.arduino.cc/en/Main/Software](https://www.arduino.cc/en/Main/Software) | +| Arduino IDE (Cloud) | [https://create.arduino.cc/editor](https://create.arduino.cc/editor) | +| Cloud IDE Getting Started | [https://docs.arduino.cc/cloud/web-editor/tutorials/getting-started/getting-started-web-editor](https://docs.arduino.cc/cloud/web-editor/tutorials/getting-started/getting-started-web-editor) | +| Project Hub | [https://create.arduino.cc/projecthub?by=part&part_id=11332&sort=trending](https://create.arduino.cc/projecthub?by=part&part_id=11332&sort=trending) | +| Library Reference | [https://github.com/arduino-libraries/](https://github.com/arduino-libraries/) | +| Online Store | [https://store.arduino.cc/](https://store.arduino.cc/) | + +## Change Log + +| Date | **Revision** | **Changes** | +| ---------- | ------------ | ------------------------------------- | +| 07/07/2025 | 3 | ADC and current limitation info added | +| 23/05/2025 | 2 | Headers variant added | +| 31/03/2025 | 1 | First Release | diff --git a/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-cad-files.zip b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-cad-files.zip new file mode 100644 index 0000000000..ecddaa6076 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-cad-files.zip differ diff --git a/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-full-pinout.pdf b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-full-pinout.pdf new file mode 100644 index 0000000000..d470cba5c1 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-full-pinout.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-schematics.pdf b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-schematics.pdf new file mode 100644 index 0000000000..25df49f2ea Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-schematics.pdf differ diff --git a/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-step.zip b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-step.zip new file mode 100644 index 0000000000..eae68df8c1 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/downloads/ABX00142-step.zip differ diff --git a/content/hardware/03.nano/boards/nano-r4/essentials.md b/content/hardware/03.nano/boards/nano-r4/essentials.md new file mode 100644 index 0000000000..0b63b4d2e9 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/essentials.md @@ -0,0 +1,30 @@ +--- +productsLibrariesMap: + - arduino:renesas_uno +--- + + + + All you need to know to get started with your new Arduino Nano R4 board. + + + + Learn how to create your own custom hardware that is compatible with the Arduino Nano Family. + + + + Get started with the Arduino Cloud and connect your Nano R4 to the web. + + + + + + Built-in Examples are sketches included in the Arduino IDE and demonstrate all basic Arduino commands. + + + Discover interesting articles, principles and techniques related to the Arduino ecosystem. + + + Arduino programming language can be divided in three main parts: functions, values (variables and constants), and structure. + + diff --git a/content/hardware/03.nano/boards/nano-r4/features.md b/content/hardware/03.nano/boards/nano-r4/features.md new file mode 100644 index 0000000000..0bee009b81 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/features.md @@ -0,0 +1,57 @@ + +The Arduino Nano R4 features the powerful Renesas RA4M1 microcontroller with a 32-bit Arm® Cortex®-M4 core running at 48 MHz. Its Nano family board form factor ensures compatibility with countless accessories. At the same time, modern features like USB-C®, CAN bus and an onboard Qwiic connector make it a versatile choice for embedded, automation and prototyping projects. + + + + + +Easily connect sensors and peripherals using the onboard Qwiic connector, which enables plug-and-play I²C communication at 3.3 V logic levels while interfacing with the 5 V system. + + + + + + +The Nano R4 board features a built-in operational amplifier (OPAMP) that provides signal conditioning and amplification capabilities + + + + + + +Use the onboard 12-bit DAC to build sophisticated audio projects. + + + + + + +The Nano R4 features a USB-C® connector for streamlined power and data transfer. + + + +The Nano R4 supports CAN communication, making it suitable for industrial and automotive applications. This requires an external transceiver. + + + + + + +Keep track of time & date and set alarms with the built-in RTC. + + + + + + +The RA4M1 and the GPIOs of this board operates on 5 V. + + + +Build game controllers by emulating a mouse/keyboard. + + + + + + diff --git a/content/hardware/03.nano/boards/nano-r4/image.svg b/content/hardware/03.nano/boards/nano-r4/image.svg new file mode 100644 index 0000000000..1ca40af57b --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/image.svg @@ -0,0 +1,383 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/content/hardware/03.nano/boards/nano-r4/interactive/ABX00142-pinout.png b/content/hardware/03.nano/boards/nano-r4/interactive/ABX00142-pinout.png new file mode 100644 index 0000000000..3beadd599e Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/interactive/ABX00142-pinout.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/product.md b/content/hardware/03.nano/boards/nano-r4/product.md new file mode 100644 index 0000000000..2543b51dc5 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/product.md @@ -0,0 +1,13 @@ +--- +title: Nano R4 +url_shop: https://store.arduino.cc/products/nano-r4 +primary_button_url: /tutorials/nano-r4/user-manual/#first-use +primary_button_title: Get Started +core: +certifications: [CE, RoHS, REACH, WEEE, UKCA, RCM, FCC, IC, VCCI] +forumCategorySlug: '/hardware/nano-family/nano-r4/190' +productCode: '212' +sku: [ABX00142, ABX00143] +--- + +The **Arduino Nano R4** brings the power of a 32-bit **Arm® Cortex®-M4** processor to the beloved Nano family board form factor. Based on the **Renesas RA4M1** microcontroller, it features **256 kB Flash**, **32 kB SRAM** and an **8 kB EEPROM**, all running at **48 MHz** with a built-in **real-time clock** (RTC), **14-bit ADC** and a **12-bit DAC**. diff --git a/content/hardware/03.nano/boards/nano-r4/suggestions.md b/content/hardware/03.nano/boards/nano-r4/suggestions.md new file mode 100644 index 0000000000..c0b96a6aa2 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/suggestions.md @@ -0,0 +1,21 @@ + + + A technical reference to the Nano R4 board. + + + + Get started with the Arduino Cloud + + + + + + Built-in Examples are sketches included in the Arduino IDE and demonstrate all basic Arduino commands. + + + Discover interesting articles, principles and techniques related to the Arduino ecosystem. + + + Arduino programming language can be divided in three main parts: functions, values (variables and constants), and structure. + + diff --git a/content/hardware/03.nano/boards/nano-r4/tech-specs.md b/content/hardware/03.nano/boards/nano-r4/tech-specs.md new file mode 100644 index 0000000000..b2bdca6e56 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/tech-specs.md @@ -0,0 +1,15 @@ +Here you will find the technical specifications for the Arduino® Nano R4. + +**Please read: operating voltage** + +The **Nano R4** microcontroller operates at +5 VDC, making it fully compatible with traditional Arduino shields, modules, and accessories designed for +5 VDC logic levels. This allows seamless reuse of existing components and simplifies interfacing with various +5 VDC sensors and actuators. + +The board supports multiple power input options: + +The VIN pin accepts an input voltage range of +6–21 VDC, which is internally regulated down to +5 VDC. + +The board can also be powered directly via the board's USB-C® port, which supplies +5 VDC to the system. + +All GPIO pins operate at +5 VDC and can source or sink up to 8 mA of current per pin. + +Always verify the voltage requirements of any connected peripheral to the board and avoid drawing more current than the board’s limits to prevent instability or permanent damage. \ No newline at end of file diff --git a/content/hardware/03.nano/boards/nano-r4/tech-specs.yml b/content/hardware/03.nano/boards/nano-r4/tech-specs.yml new file mode 100644 index 0000000000..a4483c8300 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/tech-specs.yml @@ -0,0 +1,30 @@ +Board: + Name: Arduino® Nano R4 + SKU: ABX00142 (Castellated Pins) / ABX00143 (With Headers) +Microcontroller: Renesas RA4M1 (Arm® Cortex®-M4) +USB: + USB-C®: Programming Port +Pins: + Digital I/O Pins: 21 (all the exposed I/O can be used as digital I/O pins) + Analog input pins: 8 + DAC: 1 (A0) + OPAMP: A1, A2, A3 + VBAT: J5 + PWM pins: 6 + External interrupts: 2,3 +Communication: + UART: 1 + I2C: "2 (5 V: A4, A5 / 3.3 V: QWIIC, J3, J4)" + SPI: 1 + CAN: 1 +Power: + Circuit operating voltage: +5 VDC + Input voltage (VIN): +6-21 VDC + DC Current per I/O Pin: 8 mA +Clock speed: + Main core: 48 MHz +Memory: + RA4M1: 256 kB Flash, 32 kB RAM, 8 kB EEPROM +Dimensions: + Width: 18 mm + Length: 45 mm \ No newline at end of file diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-1.png new file mode 100644 index 0000000000..2fa8ac1b87 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-2.png new file mode 100644 index 0000000000..adf49695dd Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-3.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-3.png new file mode 100644 index 0000000000..53c4c493ab Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/analog-3.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/dac-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/dac-1.png new file mode 100644 index 0000000000..1d84eafbe2 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/dac-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/dac-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/dac-2.png new file mode 100644 index 0000000000..9e04b84f96 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/dac-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/digital-pins-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/digital-pins-1.png new file mode 100644 index 0000000000..9858ceb705 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/digital-pins-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/digital-pins-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/digital-pins-2.png new file mode 100644 index 0000000000..27d56c4023 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/digital-pins-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/eeprom-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/eeprom-1.png new file mode 100644 index 0000000000..e794516a67 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/eeprom-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/front-page.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/front-page.png new file mode 100644 index 0000000000..be24874920 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/front-page.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hero-banner.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hero-banner.png new file mode 100644 index 0000000000..7889ae2b33 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hero-banner.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-1.png new file mode 100644 index 0000000000..776782987d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-2.gif b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-2.gif new file mode 100644 index 0000000000..f426b8c4cf Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-2.gif differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-3.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-3.png new file mode 100644 index 0000000000..00401d0d99 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-3.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-4.gif b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-4.gif new file mode 100644 index 0000000000..1aabde8b3d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/hid-4.gif differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/i2c-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/i2c-1.png new file mode 100644 index 0000000000..a29dd5c5b7 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/i2c-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/i2c-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/i2c-2.png new file mode 100644 index 0000000000..dc4bd35dde Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/i2c-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/opamp-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/opamp-1.png new file mode 100644 index 0000000000..4a205f202b Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/opamp-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/opamp-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/opamp-2.png new file mode 100644 index 0000000000..c629894316 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/opamp-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-1.gif b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-1.gif new file mode 100644 index 0000000000..740cba09e2 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-1.gif differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-2.png new file mode 100644 index 0000000000..92792674fe Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-3.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-3.png new file mode 100644 index 0000000000..5069938465 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/pwm-3.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/rtc-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/rtc-1.png new file mode 100644 index 0000000000..f664627f1d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/rtc-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/simple-pinout.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/simple-pinout.png new file mode 100644 index 0000000000..86961d9714 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/simple-pinout.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/spi-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/spi-1.png new file mode 100644 index 0000000000..a841dfee50 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/spi-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/spi-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/spi-2.png new file mode 100644 index 0000000000..2293cd0a93 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/spi-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/uart-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/uart-1.png new file mode 100644 index 0000000000..77cff1d231 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/uart-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/uart-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/uart-2.png new file mode 100644 index 0000000000..169a75a736 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/uart-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/unboxing.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/unboxing.png new file mode 100644 index 0000000000..d6ad44c1a3 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/unboxing.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-1.png new file mode 100644 index 0000000000..7688fba83d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-10.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-10.png new file mode 100644 index 0000000000..858cb7567d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-10.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-12.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-12.png new file mode 100644 index 0000000000..40378270ca Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-12.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-13.gif b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-13.gif new file mode 100644 index 0000000000..21e18e9159 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-13.gif differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-2.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-2.png new file mode 100644 index 0000000000..939af0dfc8 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-2.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-3.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-3.png new file mode 100644 index 0000000000..67312c9fec Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-3.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-4.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-4.png new file mode 100644 index 0000000000..f0ba8dddb5 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-4.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-5.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-5.png new file mode 100644 index 0000000000..6cc6308f8a Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-5.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-6.gif b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-6.gif new file mode 100644 index 0000000000..ee6f8f96ac Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-6.gif differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-7.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-7.png new file mode 100644 index 0000000000..b25ffd56cc Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-7.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-8.png b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-8.png new file mode 100644 index 0000000000..9c38d1ee23 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-8.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-9.gif b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-9.gif new file mode 100644 index 0000000000..d7bd06124d Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/assets/user-manual-9.gif differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/content.md b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/content.md new file mode 100644 index 0000000000..0db6be1589 --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/tutorials/01.user-manual/content.md @@ -0,0 +1,2250 @@ +--- +title: 'Nano R4 User Manual' +difficulty: beginner +compatible-products: [nano-r4] +description: 'Learn about the hardware and software features of the Arduino® Nano R4 board.' +tags: + - Cheat sheet + - User manual +author: 'José Bagur' +hardware: + - hardware/04.nano/boards/nano-r4 +software: + - ide-v1 + - ide-v2 + - iot-cloud + - web-editor +--- + +This user manual provides a comprehensive overview of the Nano R4 board, highlighting its hardware and software elements. With it, you will learn how to set up, configure and use all the main features of the Nano R4 board. + +![ ](assets/hero-banner.png) + +## Hardware and Software Requirements + +### Hardware Requirements + +- [Nano R4](https://store.arduino.cc/products/nano-r4) (x1) +- [USB-C® cable](https://store.arduino.cc/products/usb-cable2in1-type-c) (x1) +- [Breadboard](https://store.arduino.cc/products/breadboard-400-contacts) (x1) (recommended) +- [Male/male jumper wires](https://store.arduino.cc/products/breadboard-400-contacts) (recommended) + +### Software Requirements + +- [Arduino IDE 2.0+](https://www.arduino.cc/en/software) or [Arduino Web Editor](https://create.arduino.cc/editor) +- [Arduino UNO R4 Boards core](https://github.com/arduino/ArduinoCore-renesas) + +***The Nano R4 is compatible with the complete Arduino ecosystem and can be programmed directly as a standalone device.*** + +## Nano R4 Overview + +The Nano R4 board represents the natural evolution of the Nano family, combining the powerful RA4M1 microcontroller from Renesas with the compact and familiar Nano form factor. This board is designed to facilitate seamless transition from prototyping to production, using the same powerful core already used in the UNO R4 family. + +![ ](assets/front-page.png) + +The Nano R4 includes a high-performance 32-bit microcontroller (R7FA4M1AB3CFM), expanded connectivity through an onboard Qwiic connector and advanced features such as DAC, CAN and operational amplifiers. Its compact dimensions (18 mm x 45 mm) and robust construction make the Nano R4 board an excellent choice for projects that demand sensor fusion capabilities and the computational power of modern microcontrollers. + + +### Nano R4 Architecture Overview + +The Nano R4 board features a secure, certified and durable design that suits various applications, such as industrial automation, building automation and rapid prototyping. + +The top view of the Nano R4 board is shown in the image below: + +![The Nano R4 main components (top view)](assets/user-manual-1.png) + +The bottom view of the Nano R4 board is shown in the image below: + +![The Nano R4 main components (bottom view)](assets/user-manual-2.png) + +***The bottom side of the Nano R4 board features only test points for debugging and development purposes, along with the board's certification markings and identification information (board model and SKU).*** + + +Here is an overview of the board's main components shown in the images above: + +- **Microcontroller**: At the heart of the Nano R4 board there is a Renesas RA4M1 family microcontroller ([R7FA4M1AB3CFM](https://www.renesas.com/en/document/dst/ra4m1-group-datasheet?srsltid=AfmBOoryT-HIws0lHBASVG1QdfHDNWNQ5FNnoQV3hpoQ0FbncC7FI3h4)). This single-chip microcontroller, recognized as one of the industry's most energy-efficient microcontroller, is based on a 48 MHz Arm® Cortex®-M4 core with up to 256 KB of flash memory and 32 KB of SRAM memory. +- **USB-C connector**: The Nano R4 board features a modern USB-C connector for programming, power supply and serial communication with the external world. +- **Qwiic connector**: The Nano R4 board also includes an onboard Qwiic connector to expand the board's communication capabilities via I²C, facilitating connection with a wide range of boards, sensors, actuators and different peripherals. + +- **Programmable RGB LED**: The Nano R4 board has an onboard user-programmable RGB LED to provide visual feedback about different operating states. +- **User LED**: In addition to the onboard user-programmable RGB LED, the board also includes an additional onboard user-programmable orange LED for basic status indications. +- **Castellated pins**: The board's castellated pins allow surface mounting as a module, facilitating integration into custom hardware designs. +- **Advanced microcontroller features**: The R7FA4M1AB3CFM microcontroller has integrated peripherals such as a 12-bit Digital-to-Analog Converter (DAC), CAN bus for industrial communications, integrated Operational Amplifiers (OpAmp) and HID emulation capabilities (keyboard/mouse). + +### Board Core and Libraries + +The **Arduino UNO R4 Boards** core contains the libraries and examples to work with the Arduino Nano R4's peripherals and onboard components, such as its RA4M1 microcontroller, advanced peripherals (DAC, CAN and OpAmp), Qwiic connector and the onboard RGB LED. To install the core for the Nano R4 board, navigate to **Tools > Board > Boards Manager** or click the **Boards Manager** icon in the left tab of the IDE. In the Boards Manager tab, search for `UNO R4` and install the latest Arduino UNO R4 Boards version. + + +![Installing the Arduino UNO R4 Boards core in the Arduino IDE](assets/user-manual-3.png) + +The Arduino UNO R4 Boards core provides support for the following: + +- Board control and configuration (reset, pin configuration and power management) +- Advanced peripheral functions (12-bit DAC, ADC, CAN bus and OpAmp) +- Communication interfaces (UART, I²C and SPI) +- Onboard LED control (RGB LED and orange LED) +- Real-time clock (RTC) functionality +- HID emulation capabilities (keyboard and mouse) +- Standard Arduino libraries compatibility + +***__Important note:__ Since the Nano R4 uses the same RA4M1 microcontroller as the UNO R4 WiFi and the UNO R4 Minima, it shares complete code and library compatibility, making it easy to transition projects between these boards.*** + + +### Pinout + +![Nano R4 pinout](assets/simple-pinout.png) + +The full pinout is available and downloadable as PDF from the link below: + +- [Nano R4 pinout](https://docs.arduino.cc/resources/pinouts/ABX00142-full-pinout.pdf) + +### Datasheet + +The complete datasheet is available and downloadable as PDF from the link below: + +- [Nano R4 datasheet](https://docs.arduino.cc/resources/datasheets/ABX00142-datasheet.pdf) + +### Schematics + +The complete schematics are available and downloadable as PDF from the link below: + +[- Nano R4 schematics](https://docs.arduino.cc/resources/schematics/ABX00142-schematics.pdf) + +### STEP Files + +The complete STEP files are available and downloadable from the link below: + +- [Nano R4 STEP files](../../downloads/ABX00142-step.zip) + +## First Use + +### Unboxing the Product + +When opening the Nano R4 box, you will find the board and its corresponding documentation. **The Nano R4 does not include additional cables**, so you will need a USB-C cable ([available separately here](https://store.arduino.cc/products/usb-cable2in1-type-c)) to connect the board to your computer. + +![Nano R4 unboxing](assets/unboxing.png) + +The Nano R4 is a standalone device that can be programmed directly without requiring additional boards. However, for more complex projects, you can easily combine it with Arduino shields compatible with the Nano family or connect it to other Arduino devices through its onboard Qwiic connector. + +### Connecting the Board + +The Nano R4 can be connected to your computer using its onboard USB-C connector. It can also be integrated into larger projects using the following: + +- **Direct USB-C connection**: For programming, power supply and serial communication with the computer +- **Pin connection**: For integration into breadboards or custom PCBs +- **Qwiic connection**: For rapid expansion with compatible sensors and modules + +- **Module mounting**: Using the board's castellated pins for direct soldering to PCBs + +***__Important note:__ The Nano R4 operates at +5 VDC natively. When connecting sensors or modules that operate at +3.3 VDC, make sure to verify voltage compatibility to avoid component damage.*** + +### Powering the Board + +The Nano R4 can be powered in several ways: + +- **Via USB-C connector**: The most common method during development and programming +- **Via `VIN` pin**: Using an external +6-21 VDC power supply that will be internally regulated to +5 VDC +- **Via `5V` pin**: Directly connecting a regulated +5 VDC source (with caution) + +![Different ways to power the Nano R4 board](assets/user-manual-4.png) + +***__Important note:__ The Nano R4's `VIN` pin accepts a voltage range of +6-21 VDC. Do not connect voltages outside this range as you could permanently damage the board. Always verify all the connections before applying power.*** + +#### Internal +3.3 VDC Power Supply + +The Nano R4 also includes an onboard +3.3 VDC regulator ([AP2112K](https://www.diodes.com/assets/Datasheets/AP2112.pdf)) that provides power for the following: + +- **Qwiic connector**: Supplies +3.3 VDC power to connected I²C devices +- **I²C level translation**: Enables communication between the +5 VDC microcontroller and +3.3 VDC Qwiic devices +- **Internal +3.3 VDC peripherals**: Powers certain internal circuits that require +3.3 VDC operation + +This internal +3.3 VDC supply allows the board to interface with both +5 VDC and +3.3 VDC devices through the Qwiic ecosystem while maintaining the +5 VDC operation of the board's main microcontroller. + +#### VBATT Pin + +The `VBATT` pin allows the connection of a backup battery (within the +1.6-3.6 VDC range) to maintain the microcontroller's real-time clock (RTC) and certain low-power functions when the main power source is disconnected from the board. This is particularly useful for applications that need to keep track of time or maintain certain settings of the microcontroller during power outages. + +Common battery options for this purpose include the following: + +- Coin cell batteries (CR2032: +3 VDC) +- Rechargeable LiPo batteries (+3.7 VDC nominal) +- AA/AAA batteries (+1.5-3 VDC depending on the chemistry of the battery) + + +### Hello World Example + +Let's program the Nano R4 to reproduce the classic `Hello World` example used in the Arduino ecosystem: the `Blink` sketch. We will use this example to verify that the Nano R4's connection to the computer works correctly, that the Arduino IDE is properly configured, and that both the board and development environment function as expected. + +First, connect your Nano R4 to your computer using a USB-C cable, open the Arduino IDE, and make sure that the board is connected correctly. If you are new to the Arduino IDE, please refer to the official Arduino documentation for more detailed information about initial setup. Copy and paste the following example sketch into a new Arduino IDE file: + +```arduino +/** +Blink Example for the Arduino Nano R4 Board +Name: nano_r4_blink.ino +Purpose: This sketch demonstrates how to blink the built-in +user LED of the Arduino Nano R4 board. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +// Built-in LED pin +#define LED_PIN LED_BUILTIN + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Configure LED pin as output + pinMode(LED_PIN, OUTPUT); + + // Startup message + Serial.println("- Arduino Nano R4 - Blink Example started..."); +} + +void loop() { + // Turn on the LED, wait 1 second + digitalWrite(LED_PIN, HIGH); + Serial.println("- LED on!"); + delay(1000); + + // Turn off the LED, wait 1 second + digitalWrite(LED_PIN, LOW); + Serial.println("- LED off!"); + delay(1000); +} +``` + +To upload the sketch to the board, click the **Verify** button to compile the sketch and check for errors, then click the **Upload** button to program the device with the sketch. + +![Uploading a sketch to the Nano R4 in the Arduino IDE](assets/user-manual-5.png) + +As shown in the animation below, you should see the built-in orange user LED of your Nano R4 board turn on for one second, then turn off for one second, repeating this cycle continuously. + +![Onboard orange user LED blinking](assets/user-manual-6.gif) + +Additionally, you can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the status messages that the example sketch sends each time the LED state changes. + +![Arduino IDE Serial Monitor output for the Blink sketch](assets/user-manual-7.png) + +This example confirms the following: + +- The Nano R4 board is correctly connected +- The Arduino IDE is properly configured +- The board is functioning correctly +- USB communication is working +- Digital pins respond to commands + +Congratulations! You have successfully completed your first program on the Nano R4 board. You are now ready to explore the more advanced features of this tiny but powerful board. + +## LEDs + +This user manual section covers the Nano R4 built-in LEDs, showing their main hardware and software characteristics. + +### RGB LED + +The Nano R4 features a built-in RGB LED that can be used as a visual feedback indicator for the user. + +![Built-in RGB LED of the Nano R4 board](assets/user-manual-8.png) + +The built-in RGB LED can be accessed through the following macro definitions: + +| **Built-in LED** | **Macro Definition** | **Microcontroller Pin** | +| :--------------: | :------------------: | :---------------------: | +| Red LED | `LEDR` | `P409` | +| Green LED | `LEDG` | `P411` | +| Blue LED | `LEDB` | `P410` | + +***The built-in RGB LED on the Nano R4 must be pulled to ground (`GND`) to make it light up. This means that a voltage level of `LOW` on each of their pins will turn the specific color of the LED on, and a voltage level of `HIGH` will turn them off.*** + +The following example sketch each of the RGB LED colors at an interval of 500 ms: + +```arduino +/** +RGB LED Example for the Arduino Nano R4 Board +Name: nano_r4_rgb_led.ino +Purpose: This sketch demonstrates how to control the built-in +RGB LED of the Arduino Nano R4 board. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Initialize LEDR, LEDG and LEDB as outputs + pinMode(LEDR, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDB, OUTPUT); + + // Turn off all LEDs initially + digitalWrite(LEDR, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDB, HIGH); + + Serial.println("- Arduino Nano R4 - RGB LED Example started..."); +} + +void loop() { + // Turn on the built-in red LED and turn off the rest + digitalWrite(LEDR, LOW); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDB, HIGH); + Serial.println("- Red LED on!"); + delay(500); + + // Turn on the built-in green LED and turn off the rest + digitalWrite(LEDR, HIGH); + digitalWrite(LEDG, LOW); + digitalWrite(LEDB, HIGH); + Serial.println("- Green LED on!"); + delay(500); + + // Turn on the built-in blue LED and turn off the rest + digitalWrite(LEDR, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDB, LOW); + Serial.println("- Blue LED on!"); + delay(500); + + // Turn off all LEDs + digitalWrite(LEDR, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDB, HIGH); + Serial.println("- All LEDs off!"); + delay(500); +} +``` + +You should now see the built-in RGB LED cycling through red, green, and blue colors, followed by a brief moment with all LEDs off, repeating this pattern continuously. + +![Onboard RGB user LED blinking](assets/user-manual-9.gif) + +Additionally, you can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the status messages that the example sketch sends each time the RGB LEDs state changes. + +![Arduino IDE Serial Monitor output for the RGB LED example sketch](assets/user-manual-10.png) + +### Orange LED + +The Nano R4 also features a built-in orange user LED that can be used for basic status indications and debugging purposes. + +![Built-in user LED of the Nano R4 board](assets/user-manual-12.png) + + +The built-in user LED can be accessed through the following macro definition: + +| **Built-in LED** | **Macro Definition** | **Microcontroller Pin** | +| :--------------: | :------------------: | :---------------------: | +| Orange User LED | `LED_BUILTIN` | `P204` | + +***Unlike the RGB LED, the built-in user LED on the Nano R4 operates with standard logic levels. This means that a voltage level of `HIGH` will turn the LED on, and a voltage level of `LOW` will turn it off.*** + +The following example sketch demonstrates how to control the built-in user LED: + +```arduino +/** +User LED Example for the Arduino Nano R4 Board +Name: nano_r4_user_led.ino +Purpose: This sketch demonstrates how to control the built-in +user LED of the Arduino Nano R4 board. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Configure LED_BUILTIN pin as output + pinMode(LED_BUILTIN, OUTPUT); + + // Turn off LED initially + digitalWrite(LED_BUILTIN, LOW); + + Serial.println("- Arduino Nano R4 - User LED Example started..."); +} + +void loop() { + // Turn on the built-in user LED + digitalWrite(LED_BUILTIN, HIGH); + Serial.println("- User LED on!"); + delay(1000); + + // Turn off the built-in user LED + digitalWrite(LED_BUILTIN, LOW); + Serial.println("- User LED off!"); + delay(1000); +} +``` + +You should now see the built-in orange user LED blinking on and off at 1-second intervals, repeating this pattern continuously. + +![Onboard RGB user LED blinking](assets/user-manual-13.gif) + +Additionally, you can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the status messages that the example sketch sends each time the user LED state changes. + +![Arduino IDE Serial Monitor output for the orange LED example sketch](assets/user-manual-7.png) + +## Pins + +This user manual section provides comprehensive information about the Nano R4's pin capabilities and functionality. Understanding the board's pins capabilities and configurations is important for making the most of your projects with the Nano R4 board. + + +### Pins Overview + +The Nano R4 features a total of **20 accessible pins** arranged in the classic Nano form factor, maintaining compatibility with existing Nano shields and breadboard layouts. These pins provide various functionalities including digital I/O, analog input, PWM output and several communication protocols. + +![Nano R4 pinout overview](assets/simple-pinout.png) + +### Pins Specifications and Characteristics + +The Nano R4's pins are organized into the following categories: + +| **Pin Type** | **Count** | **Pin Numbers** | **Primary Functions** | +| :--------------: | :-------: | :-----------------------: | :----------------------------------------: | +| **Digital Pins** | 14 | `D0` - `D13` | Digital I/O, PWM (6 pins), SPI, UART | +| **Analog Pins** | 8 | `A0` - `A7` | Analog input, Digital I/O, I²C, DAC (`A0`) | +| **Power Pins** | 4 | `VIN`, `5V`, `3V3`, `GND` | Power supply and ground | +| **Special Pins** | 2 | `RESET`, `VBATT` | System control and backup | + +The Nano R4 offers several advanced pin capabilities including multi-function pins that can serve multiple purposes depending on your project needs, native +5 VDC operation for compatibility with classic Arduino shields, internal +3.3 VDC level translation for modern sensors and electronic components via Qwiic, and built-in advanced peripherals such as DAC, CAN bus and operational amplifiers on specific pins of the board. + + +The following table shows the electrical specifications and operating limits for all pins on the Nano R4 board: + +| **Specification** | **Value** | **Notes** | +| :---------------------: | :----------: | :------------------------------: | +| **Operating Voltage** | +5 VDC | Logic level for all digital pins | +| **Input Voltage Range** | 0 - +5.5 VDC | +5 VDC tolerant inputs | +| **Max Current per Pin** | 8 mA | Source/sink current limit | +| **Max Total Current** | 200 mA | Combined current for all pins | +| **Analog Reference** | +5 VDC | Default `AREF` voltage | + +***__Important safety considerations when working with the Nano R4 pins:__ Never exceed +5.5 VDC on any pin to avoid permanent damage, respect the 8 mA per pin and 200 mA total current limits, handle the board with proper anti-static precautions, avoid connecting pins directly to ground or power and always verify voltage levels when connecting +3.3 VDC devices.*** + + +### Digital Pins + +The Nano R4 features 14 digital pins (`D0` to `D13`) that can be configured as either digital inputs or digital outputs. These pins operate at +5 VDC logic levels and can source or sink up to 8 mA of current per pin. Digital pins are the foundation of most Arduino projects, allowing you to control LEDs, read button states, interface with sensors and communicate with other devices. + +The Nano R4 digital pins provide the following functionality: + +| **Arduino Pin** | **Microcontroller Pin** | **Additional Functions** | **Special Features** | +| :-------------: | :---------------------: | :----------------------: | :------------------: | +| `D0` | `P104` | UART RX, PWM | Serial communication | +| `D1` | `P105` | UART TX, PWM | Serial communication | +| `D2` | `P213` | PWM | External interrupt | +| `D3` | `P212` | PWM | External interrupt | +| `D4` | `P109` | CAN TX, PWM | CAN communication | +| `D5` | `P110` | CAN RX, PWM | CAN communication | +| `D6` | `P107` | PWM | Digital I/O | +| `D7` | `P106` | PWM | Digital I/O | +| `D8` | `P300` | PWM | Digital I/O | +| `D9` | `P108` | PWM | Digital I/O | +| `D10` | `P103` | SPI CS, PWM | SPI communication | +| `D11` | `P101` | SPI MOSI, PWM | SPI communication | +| `D12` | `P100` | SPI MISO | SPI communication | +| `D13` | `P102` | SPI SCK | SPI communication | + +***__Important note:__ Pins `D0` and `D1` are used for serial communication (UART) and should be avoided for general digital I/O when using Serial communication. Pins `D4` and `D5` can be used for CAN bus communication. Pins `D10`, `D11`, `D12` and `D13` are used for SPI communication.*** + + +The Nano R4's digital pins offer the following specifications: + +| **Specification** | **Value** | **Notes** | +| :------------------: | :------------: | :---------------------------: | +| Logic Voltage | +5 VDC | `HIGH` and `LOW` logic levels | +| Input Voltage | 0 to +5.5 VDC | +5 VDC tolerant inputs | +| Max Current (Source) | 8 mA | Per pin source current | +| Max Current (Sink) | 8 mA | Per pin sink current | +| Total Max Current | 200 mA | Combined for all pins | +| Input Resistance | 20-50 kΩ | Internal pull-up resistor | +| Digital `HIGH` | +3.5 to +5 VDC | Minimum voltage for `HIGH` | +| Digital `LOW` | 0 to +1.5 VDC | Maximum voltage for `LOW` | + +Digital pins can be configured and controlled using the following basic Arduino functions. + +You can configure a pin's mode using the `pinMode()` function: + +```arduino +pinMode(pin, mode); +``` + +To write a digital value to an output pin, use the `digitalWrite()` function: + +```arduino +digitalWrite(pin, value); +``` + +To read the state of a digital input pin, use the `digitalRead()` function: + +```arduino +digitalRead(pin); +``` + +The available pin modes are `OUTPUT` for digital output, `INPUT` for digital input with high impedance, and `INPUT_PULLUP` for digital input with internal pull-up resistor enabled. Digital output values can be `HIGH` (+5 VDC) or `LOW` (0 VDC), and digital input readings will return `HIGH` or `LOW` based on the voltage level detected on the pin. + +***The following example demonstrate basic digital pin functionality using simple connections that you can easily test with the Nano R4 board.*** + +The following example demonstrates using both digital input and output simultaneously by reading a button and controlling the built-in LED of the board: + +```arduino +/** +Combined Digital I/O Example for the Arduino Nano R4 Board +Name: nano_r4_digital_io_combined.ino +Purpose: This sketch demonstrates reading a button input and toggling +the built-in LED state each time the button is pressed. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +// Pin definitions +const int buttonPin = 2; // Button input on D2 +const int ledPin = LED_BUILTIN; // Built-in LED + +// Variables to store button and LED state +int buttonState = 0; +int lastButtonState = HIGH; +bool ledState = false; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Configure pins + pinMode(buttonPin, INPUT_PULLUP); + pinMode(ledPin, OUTPUT); + + // Turn off LED initially + digitalWrite(ledPin, LOW); + + Serial.println("- Arduino Nano R4 - Combined Digital I/O Example started..."); + Serial.println("- Press button to toggle the built-in LED"); +} + +void loop() { + // Read current button state + buttonState = digitalRead(buttonPin); + + // Check if button was just pressed (state change from HIGH to LOW) + if (buttonState == LOW && lastButtonState == HIGH) { + // Button press detected - toggle LED state + ledState = !ledState; + digitalWrite(ledPin, ledState); + + Serial.print("- Button pressed! LED is now "); + if (ledState) { + Serial.println("ON"); + } else { + Serial.println("OFF"); + } + + // Simple debounce delay + delay(50); + } + + // Save current button state for next iteration + lastButtonState = buttonState; + + // Small delay for stability + delay(10); +} +``` + +To test this example, connect a push button to the Nano R4 board as follows: + +- Connect one leg of a push button to pin `D2` +- Connect the other leg of the push button to `GND` +- No external components needed (using built-in LED and internal pull-up) + +![Digital pins test circuit on the Nano R4 board](assets/digital-pins-1.png) + +You should now see the built-in LED toggle on and off each time you press the button. The LED will stay in its current state until you press the button again. Additionally, you can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see messages indicating when the button is pressed and the current LED state. + +![Arduino IDE Serial Monitor output for the combined digital I/O example sketch](assets/digital-pins-2.png) + +### Analog Pins + +The Nano R4 features **8 analog input pins** (`A0` to `A7`) that can be read using the `analogRead()` function. These pins allow you to measure continuously varying voltages, making them perfect for reading sensors like potentiometers, light sensors, temperature sensors and other analog components and devices. The analog-to-digital converter (ADC) built into the RA4M1 microcontroller of the Nano R4 board converts the analog voltage into a digital value that your sketch can process. + +The Nano R4 analog pins provide the following functionality: + +| **Arduino Pin** | **Microcontroller Pin** | **Additional Functions** | **Special Features** | +| :-------------: | :---------------------: | :----------------------: | :-------------------: | +| `A0` | `P000` | DAC | 12-bit DAC output | +| `A1` | `P001` | OPAMP + | Operational amplifier | +| `A2` | `P002` | OPAMP - | Operational amplifier | +| `A3` | `P003` | OPAMP OUT | Operational amplifier | +| `A4` | `P004` | SDA (I²C) | I²C communication | +| `A5` | `P010` | SCL (I²C) | I²C communication | +| `A6` | `P014` | Analog In | Analog input only | +| `A7` | `P015` | Analog In | Analog input only | + +***__Important note:__ Pin `A0` has a built-in 12-bit Digital-to-Analog Converter (DAC) for analog output. Pins `A1`, `A2` and `A3` are connected to the integrated operational amplifier. Pins `A4` and `A5` are primarily used for I²C communication (SDA and SCL respectively).*** + + +The Nano R4's analog pins offer the following specifications: + +| **Specification** | **Value** | **Notes** | +| :----------------: | :----------: | :--------------------------: | +| Input Voltage | 0 to +5 VDC | Maximum safe input voltage | +| Default Resolution | 10-bit | Values 0-1023 | +| Maximum Resolution | 14-bit | Values 0-16383 | +| Default Reference | +5 VDC | AREF voltage | +| Internal Reference | +1.5 VDC | Built-in precision reference | +| Sample Rate | Up to 1 MSPS | Maximum sampling speed | +| Accuracy | ±2 LSB | Typical conversion accuracy | + +You can read analog values using the `analogRead()` function: + +```arduino +value = analogRead(pin); +``` + +The default reference voltage of these pins is +5 VDC, but this can be changed using the `analogReference()` function. You can use `analogReference(AR_DEFAULT)` for the default reference of +5 VDC or `analogReference(AR_INTERNAL)` for the built-in reference of +1.5 VDC. + +The default resolution is set to 10-bit, but it can be updated to 12-bit and 14-bit resolutions using the `analogReadResolution()` function in the `setup()` of your sketch. Available options are analogReadResolution(10) for default 10-bit, analogReadResolution(12) for 12-bit, or analogReadResolution(14) for maximum 14-bit resolution. + + +***The following examples demonstrate basic analog pin functionality using simple connections that you can easily test with the Nano R4 board.*** + +The following example demonstrates how to read an analog value and display it on the Serial Monitor: + +```arduino +/** +Analog Input Example for the Arduino Nano R4 Board +Name: nano_r4_analog_input.ino +Purpose: This sketch demonstrates how to read an analog input +and display the value on the Serial Monitor. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +// Analog input pin +const int analogPin = A0; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - Analog Input Example started..."); + Serial.println("- Reading analog values from pin A0"); +} + +void loop() { + // Read the analog value (0 - 1023 with 10-bit resolution) + int analogValue = analogRead(analogPin); + + // Convert to voltage (0 to +5 VDC) + float voltage = analogValue * (5.0 / 1023.0); + + // Display the results + Serial.print("- Analog Value: "); + Serial.print(analogValue); + Serial.print(" | Voltage: "); + Serial.print(voltage, 2); + Serial.println(" VDC"); + + // Wait half a second before next reading + delay(500); +} +``` + +To test this example, connect a potentiometer to the Nano R4 board as follows: + +- Connect the middle pin of a potentiometer to `A0` +- Connect one outer pin of the potentiometer to +5 VDC +- Connect the other outer pin of the potentiometer to `GND` + +![ADC test circuit on the Nano R4 board](assets/analog-1.png) + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the real-time analog values and voltage measurements as you adjust the potentiometer. As you turn the potentiometer, the values will range from 0 to 1023, with corresponding voltage readings from 0 to +5 VDC. + +![Arduino IDE Serial Monitor output for the analog input example sketch](assets/analog-2.png) + +The following example demonstrates how to use 14-bit resolution for more precise analog readings; **use the same potentiometer connection from the first example**: + +```arduino +/** +High-Resolution Analog Input Example for the Arduino Nano R4 Board +Name: nano_r4_analog_high_res.ino +Purpose: This sketch demonstrates how to use 14-bit resolution +for precise analog input measurements. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +// Analog input pin +const int analogPin = A0; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Set analog read resolution to 14-bit (0 - 16383) + analogReadResolution(14); + + Serial.println("- Arduino Nano R4 - High-Resolution Analog Input Example started..."); + Serial.println("- Using 14-bit resolution (0 - 16383)"); +} + +void loop() { + // Read the analog value (0 - 16383 with 14-bit resolution) + int analogValue = analogRead(analogPin); + + // Convert to voltage (0 - +5 VDC) + float voltage = analogValue * (5.0 / 16383.0); + + // Calculate percentage (0 - 100%) + float percentage = (analogValue / 16383.0) * 100.0; + + // Display the results + Serial.print("- Analog Value: "); + Serial.print(analogValue); + Serial.print(" | Voltage: "); + Serial.print(voltage, 3); + Serial.print(" VDC | Percentage: "); + Serial.print(percentage, 1); + Serial.println(" %"); + + // Wait half a second before next reading + delay(500); +} +``` + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the high-resolution analog values, voltage measurements and percentage calculations as you adjust the potentiometer. With 14-bit resolution, the values will range from 0 to 16383 instead of the standard 0 to 1023, providing significantly higher precision for sensitive measurements. + +![Arduino IDE Serial Monitor output for the high-resolution analog input example sketch](assets/analog-3.png) + +### PWM (Pulse Width Modulation) + +The Nano R4 board features multiple pins with PWM capability that can be used to generate analog-like output signals. PWM works by rapidly switching a digital output between `HIGH` and `LOW` states, where the ratio of `HIGH` time to the total period determines the effective analog voltage output. + +The Nano R4 board provides PWM functionality on the following pins: + +| **Arduino Pin** | **Microcontroller Pin** | **PWM Channel** | **Primary Function** | +| :-------------: | :---------------------: | :-------------: | :-------------------: | +| `D3` | `P212` | Channel 0B | Digital I/O | +| `D5` | `P110` | Channel 1B | Digital I/O | +| `D6` | `P107` | Channel 0A | Digital I/O | +| `D9` | `P108` | Channel 0B | Digital I/O | +| `D10` | `P103` | Channel 2A | Digital I/O, SPI CS | +| `D11` | `P101` | Channel 5A | Digital I/O, SPI MOSI | + +***__Important note:__ Pins `A4` and `A5` also have PWM capability but are primarily used for I²C communication (SDA and SCL respectively). The onboard LEDs (`LEDR`, `LEDG`, `LEDB`, `LED_BUILTIN`) also support PWM for brightness control.*** + + +You can use PWM pins as analog output pins with the `analogWrite()` function: + +```arduino +analogWrite(pin, value); +``` + +By default, the resolution is 8-bit (0 to 255). You can use analogWriteResolution() to change this, supporting up to 12-bit (0 to 4095) resolution: + +```arduino +analogWriteResolution(resolution); +``` + +***The following PWM examples use the built-in orange user LED (`LED_BUILTIN`) of the Nano R4 board, which supports PWM for brightness control. This eliminates the need for external components and allows you to test PWM functionality immediately.*** + +The following example demonstrates how to control the brightness of the built-in orange user LED using PWM: + +```arduino +/** +PWM Example for the Arduino Nano R4 Board +Name: nano_r4_pwm_led.ino +Purpose: This sketch demonstrates how to use PWM to control +the brightness of the built-in user LED of the Nano R4 board. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +// Built-in LED pin (supports PWM) +const int ledPin = LED_BUILTIN; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // No need to set pinMode for PWM pins - analogWrite() handles this + + Serial.println("- Arduino Nano R4 - PWM LED Example started..."); + Serial.println("- Built-in LED will fade in and out continuously"); +} + +void loop() { + // Fade in (0 to 255) + for (int brightness = 0; brightness <= 255; brightness++) { + analogWrite(ledPin, brightness); + delay(5); + } + + Serial.println("- LED at maximum brightness"); + delay(500); + + // Fade out (255 to 0) + for (int brightness = 255; brightness >= 0; brightness--) { + analogWrite(ledPin, brightness); + delay(5); + } + + Serial.println("- LED turned off"); + delay(500); +} +``` + +You should now see the built-in orange user LED of your Nano R4 board gradually fade in and out, creating a smooth breathing effect that repeats continuously. + +![Onboard RGB user LED fading](assets/pwm-1.gif) + +Additionally, you can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the status messages that the example sketch sends at key brightness levels. + +![Arduino IDE Serial Monitor output for the PWM example sketch](assets/pwm-2.png) + +The following example demonstrates how to use a 12-bit PWM resolution for more precise control of the built-in orange user LED: + +```arduino +/** +High-Resolution PWM Example for the Arduino Nano R4 Board +Name: nano_r4_pwm_high_res.ino +Purpose: This sketch demonstrates how to use 12-bit PWM resolution +for precise control of the built-in orange user LED brightness. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +// Built-in LED pin (supports PWM) +const int pwmPin = LED_BUILTIN; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Set PWM resolution to 12-bit (0-4095) + analogWriteResolution(12); + + Serial.println("- Arduino Nano R4 - High-Resolution PWM Example started..."); + Serial.println("- Using 12-bit resolution (0-4095) with built-in LED"); +} + +void loop() { + // Generate a smooth sine wave using 12-bit PWM + for (int i = 0; i < 360; i++) { + // Calculate sine wave value and map to 12-bit range + float sineValue = sin(i * PI / 180.0); + int pwmValue = (int)((sineValue + 1.0) * 2047.5); // Map -1 to 1 → 0 to 4095 + + analogWrite(pwmPin, pwmValue); + + // Print current values every 30 degrees + if (i % 30 == 0) { + Serial.print("- Angle: "); + Serial.print(i); + Serial.print("°, PWM Value: "); + Serial.println(pwmValue); + } + + delay(10); + } + + Serial.println("- Sine wave cycle completed"); + delay(1000); +} +``` + +This high-resolution example creates a smooth sine wave pattern with the built-in LED brightness, demonstrating the precision available with a 12-bit PWM resolution. You should see a very smooth transition in the LED brightness following a sine wave pattern. Additionally, you can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the angle and PWM value outputs that demonstrate the precise 12-bit control values being used. + +![Arduino IDE Serial Monitor output for the high-resolution PWM example sketch](assets/pwm-3.png) + +### Operational Amplifier (OPAMP) + +The Nano R4 board features a built-in operational amplifier (OPAMP) that provides signal conditioning and amplification capabilities directly on the board. The OPAMP is connected to analog pins `A1`, `A2` and `A3`, allowing you to perform analog signal processing without requiring external amplifier circuits. This feature is particularly useful for sensor signal amplification, buffering and analog filtering applications. + +The Nano R4 board OPAMP provides the following pin connections: + +| **Arduino Pin** | **Microcontroller Pin** | **OPAMP Function** | **Description** | +| :-------------: | :---------------------: | :----------------: | :---------------------: | +| `A1` | `P001` | OPAMP + | Non-inverting input (+) | +| `A2` | `P002` | OPAMP - | Inverting input (-) | +| `A3` | `P003` | OPAMP OUT | Amplifier output | + +***__Important note:__ When using the OPAMP functionality, pins `A1`, `A2` and `A3` cannot simultaneously be used as regular analog inputs. The positive supply (Vs+) is fixed to approximately +5 VDC and the negative supply (Vs-) is fixed to `GND`.*** + + +The Nano R4's OPAMP offers the following electrical characteristics: + +| **Parameter** | **Low-Speed Mode** | **High-Speed Mode** | **Unit** | **Notes** | +| :------------------------: | :----------------: | :-----------------: | :------: | :--------------------: | +| Common Input Voltage Range | +1.8 to +5.5 | +0.3 to +4.4 | VDC | Typical with 5V supply | +| Output Voltage Range | +0.1 to +4.9 | +0.1 to +4.9 | VDC | Typical with 5V supply | +| Input Offset Voltage | -10 to +10 | -10 to +10 | mV | - | +| Open Loop Gain | 60 (typical) | 125 (typical) | dB | - | +| Gain-Bandwidth Product | - | 1.7 | MHz | High-speed mode | +| Slew Rate | 0.12 | - | V/μs | CL = 20 pF | +| Settling Time | 650 | 13 | μs | To 1% accuracy | +| Load Current | -100 to +100 | -100 to +100 | μA | Maximum | +| Load Capacitance | 20 | 20 | pF | Maximum | + +You can configure and use the OPAMP using the dedicated `OPAMP.h` library, which is included in the Arduino UNO R4 Boards core. To startup the OPAMP, simply include the library and call `OPAMP.begin(speed)` where speed can be `OPAMP_SPEED_LOWSPEED` for lower power consumption or `OPAMP_SPEED_HIGHSPEED` for better performance. + +The following example demonstrates how to initialize and use the OPAMP. The same code works for both voltage follower and amplifier configurations, **the difference is only in the external connections**: + +```arduino +/** +OPAMP Example for the Arduino Nano R4 Board +Name: nano_r4_opamp_example.ino +Purpose: This sketch demonstrates how to initialize the built-in OPAMP. +Works for both voltage follower and amplifier configurations. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - OPAMP Example started..."); + Serial.println("- Initializing OPAMP in high-speed mode..."); + + // Initialize OPAMP in high-speed mode + OPAMP.begin(OPAMP_SPEED_HIGHSPEED); + + Serial.println("- OPAMP initialized successfully!"); + Serial.println("- OPAMP is now ready for use with external connections"); + Serial.println("- The behavior depends on how you connect the external components"); +} + +void loop() { + // The OPAMP operates automatically based on external connections + // No additional code needed in the loop + + Serial.println("- OPAMP running..."); + delay(2000); +} +``` + +To configure the OPAMP as a **voltage follower**, connect the Nano R4 board as follows: + +- Connect pin `A2` (-) to pin `A3` (Output) with a jumper wire +- Connect the input signal to pin `A1` (+) + +For testing, connect pin `A1` to `GND` to see 0 VDC output, or connect pin `A1` to +3.3 VDC to verify voltage following. + +![Voltage follower test circuit on the Nano R4 board](assets/opamp-1.png) + +***In voltage follower configuration, any voltage applied at `A1` should be mirrored onto `A3`. This provides a high-impedance buffer that doesn't load down the input signal source.*** + +The Nano R4 OPAMP can also be configured as a **non-inverting amplifier** to amplify small signals. For example, a simple 2x amplifier can be built using two 10k Ω resistors as follows: + +- Connect one 10k Ω resistor between `A2` (-) and `GND` +- Connect another 10k Ω resistor between `A3` (Output) and `A2` (-) + +For testing, apply an input signal to `A1` (+). + +![Non inverting amplifier test circuit on the Nano R4 board](assets/opamp-2.png) + +The output at `A3` will be double the amplitude of the input signal. + +***In a non-inverting amplifier configuration, remember that the input signal and the Nano R4 should share the same GND, and the amplified output signal should not exceed approximately +4.7 VDC to avoid clipping.*** + +## Digital-to-Analog Converter (DAC) + +The Nano R4 features a built-in 12-bit Digital-to-Analog Converter (DAC) connected to pin `A0`. Unlike PWM pins that simulate analog output through rapid switching, the DAC provides true analog voltage output. This makes it ideal for applications requiring precise analog signals, such as audio generation, sensor calibration, control systems and waveform generation. + +The Nano R4 DAC provides the following functionality: + +| **Specification** | **Value** | **Notes** | +| :------------------: | :---------------: | :------------------------------: | +| Resolution | 12-bit | 4096 discrete output levels | +| Output Pin | `A0` | Dedicated DAC output pin | +| Output Voltage Range | +0.35 to +4.5 VDC | Typical range with +5 VDC supply | +| Default Resolution | 8-bit | 0 to 255 | +| Maximum Resolution | 12-bit | 0 to 4095 | +| Output Impedance | 5Ω (typical) | Low impedance output | +| Conversion Time | Max 30 μs | Time to update output voltage | +| Resistive Load | Min 30 kΩ | Minimum recommended load | +| Load Capacitance | Max 50 pF | Maximum capacitive load | + +***__Important note:__ When using the DAC on pin `A0`, this pin cannot simultaneously be used as an analog input. The DAC provides true analog output, making it superior to PWM for applications requiring smooth, continuous voltage levels.*** + + +The Nano R4's DAC offers the following technical specifications: + +| **Parameter** | **Min** | **Typ** | **Max** | **Unit** | **Notes** | +| :-----------------------------: | :-----: | :-----: | :-----: | :------: | :-----------------: | +| Differential Nonlinearity (DNL) | - | ±0.5 | ±2.0 | LSB | DNL error | +| Integral Nonlinearity (INL) | - | ±2.0 | ±16.0 | LSB | INL error | +| Offset Error | - | - | ±30 | mV | Output offset | +| Full-Scale Error | - | - | ±30 | mV | Full-scale accuracy | + +You can write analog values to the DAC using the `analogWrite()` function: + +```arduino +analogWrite(DAC, value); +``` + +The default resolution is 8-bit (0 to 255), but this can be changed using the `analogWriteResolution()` function. You can use `analogWriteResolution(8)` for 8-bit resolution, `analogWriteResolution(10)` for 10-bit resolution or `analogWriteResolution(12)` for maximum 12-bit resolution. + +The DAC reference voltage depends on the selected reference mode, and the output voltage is calculated as: `Output Voltage = (DAC_Value / 4095) × Reference_Voltage`. The output voltage range is typically from +0.35 VDC to +4.5 VDC when using the supply voltage as reference. + +***The following examples demonstrate basic DAC functionality that you can easily test with the Nano R4 board.*** + +The following example demonstrates how to generate a simple voltage output using the DAC. **No external components are needed for this example**: + +```arduino +/** +DAC Basic Output Example for the Arduino Nano R4 Board +Name: nano_r4_dac_basic.ino +Purpose: This sketch demonstrates how to use the DAC to generate +precise analog voltages on pin A0. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Set DAC resolution to 12-bit for maximum precision + analogWriteResolution(12); + + Serial.println("- Arduino Nano R4 - DAC Basic Output Example started..."); + Serial.println("- Generating precise voltages on pin A0"); + Serial.println("- Connect a multimeter to A0 to measure output"); +} + +void loop() { + // Generate different voltage levels + // 0, +1.25, +2.5, +3.75 and +5 VDC + int dacValues[] = {0, 1024, 2048, 3072, 4095}; + float voltages[] = {0.0, 1.25, 2.5, 3.75, 5.0}; + + for (int i = 0; i < 5; i++) { + analogWrite(DAC, dacValues[i]); + + Serial.print("- DAC Value: "); + Serial.print(dacValues[i]); + Serial.print(" | Target Voltage: "); + Serial.print(voltages[i], 2); + Serial.println(" VDC"); + + // Hold each voltage for 2 seconds + delay(2000); + } + + Serial.println("- Cycle completed, repeating..."); + delay(1000); +} +``` + +To test this example, connect a digital multimeter between pin `A0` and `GND` to measure the output voltage. You should see the voltage change in precise steps every two seconds, showing the DAC's ability to generate exact analog voltages. For best results, connect an oscilloscope to pin `A0` to visualize the step output. + +![Step output oscilloscope output](assets/dac-1.png) + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the DAC values and corresponding target voltages. The output should closely match the calculated voltages with high precision. + +The following example demonstrates how to generate a smooth sine wave using the DAC. **No external components are needed for this example**: + +```arduino +/** +DAC Sine Wave Generator for the Arduino Nano R4 Board +Name: nano_r4_dac_sine_wave.ino +Purpose: This sketch generates a smooth sine wave using the 12-bit DAC +for testing and signal generation applications. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Set DAC resolution to 12-bit for smooth waveform + analogWriteResolution(12); + + Serial.println("- Arduino Nano R4 - DAC Sine Wave Generator started..."); + Serial.println("- Generating sine wave on pin A0"); + Serial.println("- Connect an oscilloscope to A0 to view waveform"); +} + +void loop() { + // Generate one complete sine wave cycle (360 degrees) + for (int angle = 0; angle < 360; angle++) { + // Calculate sine value (-1 to +1) and convert to DAC range (0 to 4095) + float sineValue = sin(angle * PI / 180.0); + int dacValue = (int)((sineValue + 1.0) * 2047.5); // Center at +2.5 VDC + + // Output the calculated value to DAC + analogWrite(DAC, dacValue); + + // Print debug info every 30 degrees + if (angle % 30 == 0) { + float voltage = (dacValue / 4095.0) * 5.0; + Serial.print("- Angle: "); + Serial.print(angle); + Serial.print("° | DAC: "); + Serial.print(dacValue); + Serial.print(" | Voltage: "); + Serial.print(voltage, 2); + Serial.println(" VDC"); + } + + // Control wave frequency (~28 Hz) + delayMicroseconds(100); + } +} +``` + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the sine wave generation progress with angle, DAC values, and corresponding voltages. + +For best results, connect an oscilloscope to pin `A0` to visualize the smooth sine wave output. + +![Sine wave output oscilloscope output](assets/dac-2.png) + +## Real-Time Clock (RTC) + +The Nano R4 features a built-in Real-Time Clock (RTC) that allows your projects to keep track of date and time. The RTC is integrated within the RA4M1 microcontroller and can maintain accurate timekeeping for applications that require scheduling, data logging or time-based events. With optional backup power support via the board's `VBATT` pin, the RTC can continue running even when the main power is disconnected, using a 100-year calendar from 2000 to 2099 that automatically adjusts dates for leap years. + +The RTC is particularly useful when your project needs to know the actual date and time, rather than just measuring time intervals. While Arduino functions like `millis()` and `delay()` are perfect for timing operations (like blinking an LED every second), the RTC is essential for applications like data loggers that need timestamps, alarm clocks, scheduling systems or any project that needs to know "what time is it right now?" even after being powered off and on again. + +The Nano R4's RTC offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +| :-----------------: | :------------: | :---------------: | +| Time Range | 2000 to 2099 | 100-year calendar | +| Backup Voltage | 1.6V to 3.6V | Via VBATT pin | +| Current Consumption | ~1 μA | In backup mode | +| Temperature Range | -40°C to +85°C | Operating range | + +You can configure and use the RTC using the dedicated `RTC.h` library, which is included in the Arduino UNO R4 Boards core. The library provides functions to set time, get time, check RTC status and configure alarms. + +The following example demonstrates how to initialize the RTC and display the current date and time: + +```arduino +/** +RTC Basic Example for the Arduino Nano R4 Board +Name: nano_r4_rtc_basic.ino +Purpose: This sketch demonstrates how to use the built-in RTC +to keep track of date and time. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include "RTC.h" + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - RTC Basic Example started..."); + Serial.println("- Initializing RTC..."); + + // Initialize RTC + RTC.begin(); + + // Set initial time: January 15, 2025, 12:00:00 PM, Monday + RTCTime startTime(15, Month::JANUARY, 2025, 12, 0, 0, DayOfWeek::MONDAY, SaveLight::SAVING_TIME_INACTIVE); + RTC.setTime(startTime); + + Serial.println("- RTC time has been set to January 15, 2025, 12:00:00 PM"); + Serial.println("- Current date and time will be displayed every second"); +} + +void loop() { + // Get current time from RTC + RTCTime currentTime; + RTC.getTime(currentTime); + + // Get individual values + int year = currentTime.getYear(); + int month = Month2int(currentTime.getMonth()); + int day = currentTime.getDayOfMonth(); + + int hour = currentTime.getHour(); + int minute = currentTime.getMinutes(); + int second = currentTime.getSeconds(); + + // Display date (YYYY/MM/DD) + Serial.print("Date: "); + Serial.print(year); + Serial.print("/"); + if (month < 10) Serial.print("0"); + Serial.print(month); + Serial.print("/"); + if (day < 10) Serial.print("0"); + Serial.print(day); + + // Display time (HH:MM:SS) + Serial.print(" | Time: "); + if (hour < 10) Serial.print("0"); + Serial.print(hour); + Serial.print(":"); + if (minute < 10) Serial.print("0"); + Serial.print(minute); + Serial.print(":"); + if (second < 10) Serial.print("0"); + Serial.print(second); + + // Display day of week + Serial.print(" | Day: "); + DayOfWeek dayOfWeek = currentTime.getDayOfWeek(); + + if (dayOfWeek == DayOfWeek::MONDAY) { + Serial.print("Monday"); + } else if (dayOfWeek == DayOfWeek::TUESDAY) { + Serial.print("Tuesday"); + } else if (dayOfWeek == DayOfWeek::WEDNESDAY) { + Serial.print("Wednesday"); + } else if (dayOfWeek == DayOfWeek::THURSDAY) { + Serial.print("Thursday"); + } else if (dayOfWeek == DayOfWeek::FRIDAY) { + Serial.print("Friday"); + } else if (dayOfWeek == DayOfWeek::SATURDAY) { + Serial.print("Saturday"); + } else if (dayOfWeek == DayOfWeek::SUNDAY) { + Serial.print("Sunday"); + } + + Serial.println(); + + // Wait one second before next reading + delay(1000); +} +``` + +***To test this example, no external connections are needed. The RTC operates internally within the microcontroller.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the real-time date and time updates. The display will show the current date, time, and day of the week, updating every second. + +![Arduino IDE Serial Monitor output for the RTC example sketch](assets/rtc-1.png) + +To maintain RTC timekeeping when the main power is disconnected, you can connect a backup battery to the `VBATT` pin: + +- Connect the positive terminal of a 3V coin cell battery (CR2032) to the `VBATT` pin of the board +- Connect the negative terminal of the battery to `GND` + +With this configuration, the board's RTC will continue running on backup power when main power is removed. You can also set the board's RTC time programmatically using the following format. Remember to update the date and time values to match the current date when you upload your sketch: + +```arduino +// Create RTCTime object with current date and time +// Format: day, month, year, hour, minute, second, dayOfWeek, daylightSaving +RTCTime newTime(30, Month::JUNE, 2025, 15, 30, 45, DayOfWeek::MONDAY, SaveLight::SAVING_TIME_INACTIVE); + +// Set the RTC time +RTC.setTime(newTime); +``` + +When working with the RTC on the Nano R4, there are several key points to keep in mind for successful implementation: + +- **The RTC requires an initial time setting** before it can provide accurate timekeeping, so make sure to configure the date and time when you first start your project. For applications that need continuous timekeeping even when the main power is disconnected, connecting a backup battery to the VBATT pin is highly recommended. +- Keep in mind that **the RTC stores time exactly as you set it**, so you'll need to handle time zone conversions and daylight saving time adjustments in your application code if needed. + +## EEPROM (Non-Volatile Memory) + +The Nano R4 board features built-in EEPROM (Electrically Erasable Programmable Read-Only Memory) that allows your projects to store data permanently, even when the board is powered off. The EEPROM is implemented using flash memory emulation within the RA4M1 microcontroller and provides 8 KB of non-volatile storage space for applications that need to remember settings, sensor calibrations, or user preferences between power cycles. + +EEPROM is particularly useful when your project needs to remember information permanently, rather than just during program execution. While variables stored in SRAM are lost when power is removed, EEPROM retains data indefinitely. This makes it essential for applications like saving user preferences, storing sensor calibration values, keeping configuration settings, or any project that needs to "remember" data even after being unplugged and reconnected. + +The Nano R4's EEPROM offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +|:-----------------:|:-----------------:|:------------------------:| +| Capacity | 8 KB | Data area | +| Memory Type | Data flash memory | SuperFlash® technology | +| Write Cycles | 100,000 | Program/erase cycles max | +| Programming Unit | 64-bit | Minimum write unit | +| Erase Unit | 1 KB | Minimum erase unit | +| Read Speed | 6 clock cycles | Time to read data | +| Retention Time | 10+ years | Data retention period | +| Operating Voltage | +5 VDC | Same as board | + +You can read and write to EEPROM using the dedicated `EEPROM.h` library, which is included in the Arduino UNO R4 Boards core. The library provides simple functions to store and retrieve individual bytes or larger data structures. + +The following example demonstrates how to store and retrieve data from EEPROM: + +```arduino +/** +EEPROM Basic Example for the Arduino Nano R4 Board +Name: nano_r4_eeprom_basic.ino +Purpose: This sketch demonstrates how to store and retrieve data +from the built-in EEPROM memory. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - EEPROM Basic Example started..."); + + // Read a counter from EEPROM address 0 + int bootCounter = EEPROM.read(0); + + // If this is the first time (EEPROM starts with 255), set counter to 0 + if (bootCounter == 255) { + bootCounter = 0; + Serial.println("- First boot detected!"); + } + + // Add 1 to the counter + bootCounter = bootCounter + 1; + + // Save the new counter value to EEPROM + EEPROM.write(0, bootCounter); + + // Show the results + Serial.print("- This board has been reset "); + Serial.print(bootCounter); + Serial.println(" times"); + + // Store a user preference (LED brightness) + int brightness = 128; // Value from 0 to 255 + EEPROM.write(1, brightness); + Serial.print("- LED brightness setting saved: "); + Serial.println(brightness); + + // Read the brightness setting back + int savedBrightness = EEPROM.read(1); + Serial.print("- LED brightness setting loaded: "); + Serial.println(savedBrightness); + + Serial.println("- Reset the board to see the counter increase!"); +} + +void loop() { + // Nothing to do in the loop + // The counter only increases when you reset the board + delay(1000); +} +``` + +***To test this example, no external connections are needed. The EEPROM operates internally within the microcontroller.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the EEPROM operations. Each time you reset the board, the boot counter will increment, demonstrating that the value persists in EEPROM memory. + +![Arduino IDE Serial Monitor output for the EEPROM example sketch](assets/eeprom-1.png) + +You can also store complex data structures using the `EEPROM.put()` and `EEPROM.get()` functions: + +```arduino +// Define a structure for complex data +struct Settings { + int threshold; + float calibration; + bool enabled; + char deviceName[16]; +}; + +// Store structure to EEPROM +Settings mySettings = {512, 3.14, true, "NanoR4Device"}; +EEPROM.put(0, mySettings); + +// Read structure from EEPROM +Settings loadedSettings; +EEPROM.get(0, loadedSettings); +``` + +When working with EEPROM on the Nano R4, there are several key points to keep in mind for successful implementation: + +- The EEPROM requires careful management of write operations since flash memory has a limited number of write cycles (100,000). Avoid writing to the same address repeatedly in tight loops, as this will quickly wear out the memory. Instead, only write when values actually change, and consider spreading data across different addresses to distribute wear evenly. +- Keep in mind that EEPROM stores data as individual bytes (0 to 255), so larger data types need to be broken down or use the `put()` and `get()` functions for automatic handling. +- The EEPROM retains data for over 10 years under normal conditions, making it excellent for long-term storage of configuration data and user preferences. + +## UART Communication + +The Nano R4 board features built-in UART (Universal Asynchronous Receiver-Transmitter) communication that allows your projects to communicate with other devices through serial data transmission. UART is implemented within the RA4M1 microcontroller and provides two separate hardware serial ports: one connected to the USB-C connector for computer communication, and another available on pins `D0` and `D1` for external device communication. This makes it perfect for projects that need to communicate with sensors, modules or other microcontrollers while maintaining USB connectivity for debugging. + +UART is particularly useful when your project needs to communicate with devices that require simple, reliable serial communication, rather than the more complex protocols like SPI or I²C. While SPI excels at high-speed communication and I²C is ideal for multiple device networks, UART provides straightforward point-to-point communication that works well with GPS modules, Bluetooth® modules, Wi-Fi® modules and other serial devices. UART communication is asynchronous, meaning it doesn't require a shared clock signal, making it robust over longer distances. + +The Nano R4's UART interface offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +|:-----------------:|:--------------:|:--------------------:| +| Baud Rates | 300 to 2000000 | Common: 9600, 115200 | +| Data Bits | 8-bit | Standard data width | +| Communication | Full-duplex | Simultaneous TX/RX | +| Hardware Ports | 2 | USB Serial + Serial1 | +| UART Pins | `D0`, `D1` | RX, TX respectively | +| Operating Voltage | +5 VDC | TTL logic levels | +| Flow Control | Software | XON/XOFF supported | + +The Nano R4 board uses the following pins for UART communication: + +| **Arduino Pin** | **Microcontroller Pin** | **UART Function** | **Description** | +|:---------------:|:-----------------------:|:-----------------:|:---------------:| +| `D0` | `P104` | RX | Receive Data | +| `D1` | `P105` | TX | Transmit Data | + +You can communicate via UART using the built-in `Serial` and `Serial1` objects. The `Serial` object is connected to the USB-C port for computer communication, while `Serial1` is connected to pins `D0` and `D1` for external device communication. + +The following example demonstrates basic UART communication patterns: + +```arduino +/** +UART Basic Example for the Arduino Nano R4 Board +Name: nano_r4_uart_basic.ino +Purpose: This sketch demonstrates basic UART communication +using both USB Serial and hardware Serial1. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +void setup() { + // Initialize USB serial communication at 115200 baud + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + // Initialize hardware serial on pins D0/D1 at 9600 baud + Serial1.begin(9600); + + Serial.println("- Arduino Nano R4 - UART Basic Example started..."); + Serial.println("- USB Serial (Serial): 115200 baud"); + Serial.println("- Hardware Serial (Serial1): 9600 baud on D0/D1"); + Serial.println("- Connect logic analyzer to D0 (RX) and D1 (TX)"); + Serial.println("- Type messages in Serial Monitor to send via Serial1"); + Serial.println(); +} + +void loop() { + // Check for data from USB Serial (computer) + if (Serial.available()) { + String message = Serial.readString(); + + // Remove newline characters + message.trim(); + + if (message.length() > 0) { + Serial.print("- USB received: \""); + Serial.print(message); + Serial.println("\""); + + // Send the message via Serial1 (D0/D1) + Serial1.print("- Message from USB: "); + Serial1.println(message); + + Serial.println("- Message sent via Serial1 (D0/D1)!"); + } + } + + // Check for data from Serial1 (external device on D0/D1) + if (Serial1.available()) { + String response = Serial1.readString(); + + // Remove newline characters + response.trim(); + + if (response.length() > 0) { + Serial.print("- Serial1 received: \""); + Serial.print(response); + Serial.println("\""); + } + } + + // Send periodic test data via Serial1 + static unsigned long lastSend = 0; + if (millis() - lastSend > 3000) { + lastSend = millis(); + + // Send test data with timestamp + Serial1.print("Test data: "); + Serial1.print(millis()); + Serial1.println(" ms"); + + Serial.println("- Periodic test data sent via Serial1!"); + } + + delay(10); +} +``` + +***To test this example, no external UART devices are required, the code will demonstrate UART communication patterns that can be observed with a logic analyzer. You can type messages in the Arduino IDE's Serial Monitor to see them transmitted via `Serial1` on pins `D0`/`D1`.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to interact with the USB serial port and observe the communication patterns. Connect a logic analyzer to pins `D0` (RX) and `D1` (TX) to observe the actual UART protocol signals. + +![Arduino IDE Serial Monitor output for the UART example sketch](assets/uart-1.png) + +The image below shows how the UART communication from our example appears in the Digilent Waveforms logic analyzer software, with the decoded protocol showing the transmitted data bytes and timing. + +![Digilent Waveforms logic analyzer output for UART](assets/uart-2.png) + +The Nano R4 board provides two distinct UART communication channels, giving you the flexibility to handle multiple communication tasks simultaneously. The first channel is the USB Serial (`Serial`), which is your primary interface for programming and debugging. This channel offers several key features: + +- Connected to the onboard USB-C connector +- Used for programming and debugging +- Typically runs at 115200 baud +- Automatic baud rate detection +- No external connections required + +The second channel is the Hardware Serial (`Serial1`), which is dedicated to external device communication. This channel provides robust connectivity for your project peripherals: + +- Connected to pins `D0` (RX) and `D1` (TX) +- Used for external device communication +- Configurable baud rate (300 to 2000000) +- TTL voltage levels (0 VDC/+5 VDC) +- Requires external device connection + +Here is a practical example of how to use both UART channels simultaneously, such as when connecting a GPS module: + +```arduino +// Example: Connecting a GPS module via Serial1 +void setup() { + Serial.begin(115200); // USB debugging + Serial1.begin(9600); // GPS module communication + + Serial.println("GPS module communication started"); +} + +void loop() { + // Forward GPS data to USB Serial for monitoring + if (Serial1.available()) { + String gpsData = Serial1.readString(); + Serial.print("GPS: "); + Serial.print(gpsData); + } + + // Send commands to GPS module from USB Serial + if (Serial.available()) { + String command = Serial.readString(); + Serial1.print(command); + Serial.println("Command sent to GPS"); + } +} +``` + +When working with UART on the Nano R4, there are several key points to keep in mind for successful implementation: + +- The dual UART design is different from the UNO R3 board that shared one UART between USB and pins D0/D1. This separation allows simultaneous USB debugging and external device communication. +- Always ensure that both devices use the same baud rate, data bits (typically 8), and stop bits (typically 1) for successful communication. +- Keep in mind that UART communication uses TTL voltage levels (0 VDC for logic `LOW`, +5 VDC for logic `HIGH`). If you need to communicate over longer distances or with RS-232 devices, you'll need a level converter. +- When connecting external devices, remember that TX connects to RX and RX connects to TX (crossover connection). +- The Nano R4's UART ports are full-duplex, meaning they can send and receive data simultaneously, making them perfect for interactive communication with modules like GPS, Bluetooth®, Wi-Fi®, or other microcontrollers. + +## SPI Communication + +The Nano R4 board features built-in SPI (Serial Peripheral Interface) communication that allows your projects to communicate with external devices like sensors, displays, memory cards and other microcontrollers. SPI is implemented within the RA4M1 microcontroller and uses four dedicated pins to provide high-speed synchronous serial communication. + +SPI is particularly useful when your project needs to communicate with external components at high speeds, rather than using slower protocols. While I²C is perfect for simple sensor communication and UART for basic serial data exchange, SPI excels at high-speed communication with devices like SD cards, TFT displays, wireless modules or external memory chips. SPI can achieve much faster data rates than I²C and can handle multiple devices on the same bus through individual chip select lines. + +The Nano R4's SPI interface offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +|:-----------------:|:------------:|:---------------------------:| +| Clock Speed | Up to 24 MHz | Maximum SPI frequency | +| Data Transfer | 8-bit | Standard data width | +| Communication | Full-duplex | Simultaneous send/receive | +| SPI Pins | `D10`-`D13` | `CS`, `MOSI`, `MISO`, `SCK` | +| Multiple Devices | Supported | Via different `CS` pins | +| Operating Voltage | +5 VDC | Same as board | +| Protocol Support | Mode 0,1,2,3 | All SPI modes available | + +The Nano R4 board uses the following pins for SPI communication: + +| **Arduino Pin** | **Microcontroller Pin** | **SPI Function** | **Description** | +|:---------------:|:-----------------------:|:----------------:|:--------------------:| +| `D10` | `P103` | `CS` | Chip Select | +| `D11` | `P101` | `MOSI` | Master Out, Slave In | +| `D12` | `P100` | `MISO` | Master In, Slave Out | +| `D13` | `P102` | `SCK` | Serial Clock | + +You can communicate via SPI using the dedicated `SPI.h` library, which is included in the Arduino UNO R4 Boards core. The library provides simple functions to initialize the bus, send and receive data and manage multiple devices. + +The following example demonstrates how to use SPI communication to send and receive data: + +```arduino +/** +SPI Basic Example for the Arduino Nano R4 Board +Name: nano_r4_spi_basic.ino +Purpose: This sketch demonstrates how to use SPI communication +to send and receive data. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include + +// Chip Select pin for SPI device +const int CS_PIN = 10; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - SPI Basic Example started..."); + + // Set CS pin as output and set it HIGH (inactive) + pinMode(CS_PIN, OUTPUT); + digitalWrite(CS_PIN, HIGH); + + // Initialize SPI communication + SPI.begin(); + + // Configure SPI settings + // - Clock speed: 1 MHz (1000000 Hz) + // - Data order: Most Significant Bit first + // - Data mode: Mode 0 (Clock polarity = 0, Clock phase = 0) + SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); + + Serial.println("- SPI initialized successfully"); + Serial.println("- Ready to communicate with SPI devices"); + + // Example: Send some test data + sendSPIData(); +} + +void loop() { + // Send a counter value every 2 seconds + static int counter = 0; + + // Select the device (CS LOW) + digitalWrite(CS_PIN, LOW); + + // Send counter value + byte response = SPI.transfer(counter); + + // Deselect the device (CS HIGH) + digitalWrite(CS_PIN, HIGH); + + // Display results + Serial.print("- Sent: "); + Serial.print(counter); + Serial.print(" | Received: "); + Serial.println(response); + + // Increment counter and wrap around at 255 + counter++; + if (counter > 255) { + counter = 0; + } + + delay(2000); +} + +void sendSPIData() { + Serial.println("- Sending test data..."); + + // Select the device + digitalWrite(CS_PIN, LOW); + + // Send a sequence of test bytes + for (int i = 0; i < 5; i++) { + byte testData = 0x10 + i; // Send 0x10, 0x11, 0x12, 0x13, 0x14 + byte response = SPI.transfer(testData); + + Serial.print(" Sent: 0x"); + if (testData < 16) Serial.print("0"); + Serial.print(testData, HEX); + Serial.print(" | Received: 0x"); + if (response < 16) Serial.print("0"); + Serial.println(response, HEX); + + delay(100); + } + + // Deselect the device + digitalWrite(CS_PIN, HIGH); + + Serial.println("- Test data transmission complete"); +} +``` + +***To test this example, no external SPI device is required. The code will demonstrate SPI communication patterns, though without a connected device, the received data will typically be `0xFF`.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the SPI communication in action. The example sketch shows how to properly select devices, send data and handle responses. + +![Arduino IDE Serial Monitor output for the SPI example sketch](assets/spi-1.png) + +The image below shows how the SPI communication from our example appears in the Digilent Waveforms logic analyzer software, with the decoded protocol showing the chip select, clock and data signals being transmitted. + +![Digilent Waveforms logic analyzer output for SPI](assets/spi-2.png) + +For connecting multiple SPI devices, you can use different digital pins as additional Chip Select (`CS`) lines while sharing the `MOSI`, `MISO` and `SCK` pins: + +```arduino +// Multiple device example +const int DEVICE1_CS = 10; // First SPI device +const int DEVICE2_CS = 9; // Second SPI device +const int DEVICE3_CS = 8; // Third SPI device + +void setup() { + SPI.begin(); + + // Configure all CS pins + pinMode(DEVICE1_CS, OUTPUT); + pinMode(DEVICE2_CS, OUTPUT); + pinMode(DEVICE3_CS, OUTPUT); + + // Set all CS pins HIGH (inactive) + digitalWrite(DEVICE1_CS, HIGH); + digitalWrite(DEVICE2_CS, HIGH); + digitalWrite(DEVICE3_CS, HIGH); +} +``` + +When working with SPI on the Nano R4, there are several key points to keep in mind for successful implementation: + +- The SPI protocol requires careful attention to timing and device selection. Always ensure that only one device is selected (`CS LOW`) at a time, and remember to deselect devices (`CS HIGH`) after communication to avoid conflicts. +- Different SPI devices may require different clock speeds and modes, so check your device's datasheet for the correct `SPISettings()` parameters. +- Keep in mind that SPI is a synchronous protocol, meaning that data is transferred in both directions simultaneously with each clock pulse. Even if you only need to send data, you'll still receive data back, and vice versa. +- The Nano R4 board can communicate with multiple SPI devices by using different Chip Select (`CS`) pins, making it perfect for complex projects that need to interface with various sensors, displays and storage devices. + +## I²C Communication + +The Nano R4 board features built-in I²C (Inter-Integrated Circuit) communication that allows your projects to communicate with multiple devices using just two wires. I²C is implemented within the RA4M1 microcontroller and uses two dedicated pins to provide reliable serial communication with sensors, displays, memory modules and other microcontrollers. This makes it perfect for projects that need to connect several devices without using many pins. + +I²C is particularly useful when your project needs to communicate with multiple sensors and devices in a simple way, rather than using complex wiring. While SPI is excellent for high-speed communication and UART for basic serial data exchange, I²C excels at connecting many devices with minimal wiring. Multiple I²C devices can share the same two-wire bus, each with its own unique address, making it ideal for sensor networks, display modules and expandable systems. + +The Nano R4's I²C interface offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +|:-----------------:|:-----------------:|:--------------------------:| +| Clock Speed | Up to 400 kHz | Standard/Fast mode | +| Data Transfer | 8-bit | Standard data width | +| Communication | Half-duplex | One direction at a time | +| I²C Pins | `A4`, `A5` | SDA, SCL respectively | +| Device Addressing | 7-bit/10-bit | Up to 127 unique addresses | +| Operating Voltage | +5 VDC | Same as board | +| Pull-up Resistors | External required | No internal pull-ups | + +The Nano R4 uses the following pins for I²C communication: + +| **Arduino Pin** | **Microcontroller Pin** | **I²C Function** | **Description** | +|:---------------:|:-----------------------:|:----------------:|:-----------------:| +| `A4` | `P004` | SDA | Serial Data Line | +| `A5` | `P010` | SCL | Serial Clock Line | + +You can communicate via I²C using the dedicated `Wire.h` library, which is included in the Arduino UNO R4 Boards core. The library provides simple functions to initialize the bus, send and receive data and manage multiple devices. + +The following example demonstrates basic I²C communication patterns: + +```arduino +/** +I2C Basic Example for the Arduino Nano R4 Board +Name: nano_r4_i2c_basic.ino +Purpose: This sketch demonstrates basic I2C communication +patterns for protocol analysis. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include + +// Example device address +const int DEVICE_ADDRESS = 0x48; + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - I2C Basic Example started..."); + + // Initialize I2C communication as master + Wire.begin(); + + Serial.println("- I2C initialized successfully"); + Serial.println("- Connect protocol analyzer to A4 (SDA) and A5 (SCL)"); + Serial.println("- Starting I2C communication patterns..."); + + delay(2000); +} + +void loop() { + // Write a single byte + Serial.println("- Writing single byte (0xAA) to device 0x48..."); + Wire.beginTransmission(DEVICE_ADDRESS); + Wire.write(0xAA); + Wire.endTransmission(); + + delay(1000); + + // Write multiple bytes + Serial.println("- Writing multiple bytes (0x10, 0x20, 0x30) to device 0x48..."); + Wire.beginTransmission(DEVICE_ADDRESS); + Wire.write(0x10); + Wire.write(0x20); + Wire.write(0x30); + Wire.endTransmission(); + + delay(1000); + + // Request data from device + Serial.println("- Requesting 2 bytes from device 0x48..."); + Wire.requestFrom(DEVICE_ADDRESS, 2); + + // Read any available data + while (Wire.available()) { + int data = Wire.read(); + Serial.print("Received: 0x"); + if (data < 16) Serial.print("0"); + Serial.println(data, HEX); + } + + delay(2000); + Serial.println("---"); +} +``` +***To test this example, no external I²C devices are required. The code will generate I²C communication patterns that can be analyzed with a protocol analyzer. Without devices connected, read operations will typically return `0xFF`.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the I²C operations being performed. Connect a protocol analyzer to pins `A4` (SDA) and `A5` (SCL) to observe the actual I²C protocol signals. + +![Arduino IDE Serial Monitor output for the I²C example sketch](assets/i2c-1.png) + +The image below shows how the I²C communication from our example appears in the Digilent Waveforms logic analyzer software, with the decoded protocol showing the device address and data bytes being transmitted. + +![Arduino IDE Serial Monitor output for the I²C example sketch](assets/i2c-2.png) + +***The I²C protocol requires pull-up resistors on both SDA and SCL lines. __The Nano R4 board does not have internal pull-ups on `A4` and `A5` to avoid interference with their analog input functionality, so external 4.7kΩ pull-up resistors to +5 VDC are required for proper I²C operation__.*** + +One of the main advantages of I²C is the ability to connect multiple devices to the same bus. Here is how to connect multiple I²C devices: + +```arduino +// Example: Communicating with multiple I2C devices +void communicateWithMultipleDevices() { + // Device addresses (examples) + const int SENSOR_ADDRESS = 0x48; // Temperature sensor + const int DISPLAY_ADDRESS = 0x3C; // OLED display + const int EEPROM_ADDRESS = 0x50; // External EEPROM + + // Read from temperature sensor + Wire.beginTransmission(SENSOR_ADDRESS); + Wire.write(0x00); // Register to read + Wire.endTransmission(); + + Wire.requestFrom(SENSOR_ADDRESS, 2); + if (Wire.available() >= 2) { + int tempHigh = Wire.read(); + int tempLow = Wire.read(); + Serial.print("Temperature: "); + Serial.println((tempHigh << 8) | tempLow); + } + + // Send data to display + Wire.beginTransmission(DISPLAY_ADDRESS); + Wire.write(0x40); // Data mode + Wire.write(0xFF); // Sample data + Wire.endTransmission(); + + // Write to EEPROM + Wire.beginTransmission(EEPROM_ADDRESS); + Wire.write(0x00); // Memory address + Wire.write(0x55); // Data to write + Wire.endTransmission(); +} +``` + +When working with I²C on the Nano R4 board, there are several key points to keep in mind for successful implementation: + +- Each I²C device must have a unique address on the bus, so check device datasheets to avoid address conflicts. +- Keep in mind that I²C is a half-duplex protocol, meaning data flows in only one direction at a time. The master device (your Nano R4 board) controls the clock line and initiates all communication. +- When connecting multiple devices, simply connect all SDA pins together and all SCL pins together, along with power and ground connections. +- The Nano R4 board can communicate with up to 127 different I²C devices on the same bus, making it perfect for complex sensor networks and expandable systems. + +## CAN Communication + +The Nano R4 board features built-in CAN (Controller Area Network) communication that allows your projects to communicate with automotive systems, industrial devices, and other CAN-enabled equipment. CAN is implemented within the RA4M1 microcontroller and uses two dedicated pins to provide robust, real-time communication over longer distances with multiple devices. This makes it perfect for automotive applications, industrial automation and distributed control systems that require reliable communication in noisy environments. + +CAN is particularly useful when your project needs to communicate in industrial or automotive environments where reliability and noise immunity are critical, rather than simple point-to-point communication. While UART excels at simple serial communication and SPI provides high-speed data transfer, CAN offers multi-node networking with built-in error detection, collision handling and message prioritization. CAN communication is differential signaling, making it highly resistant to electromagnetic interference and suitable for harsh environments. + +The Nano R4's CAN interface offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +|:-----------------:|:-------------:|:------------------------:| +| Baud Rates | Up to 1 Mbps | Configurable speed | +| Data Frames | 0-8 bytes | Standard CAN frame | +| Communication | Multi-master | Multiple nodes support | +| CAN Pins | `D4`, `D5` | TX, RX respectively | +| Message IDs | 11-bit/29-bit | Standard/Extended format | +| Operating Voltage | +5 VDC | Requires CAN transceiver | +| External Hardware | Required | CAN transceiver needed | + +The Nano R4 uses the following pins for CAN communication: + +| **Arduino Pin** | **Microcontroller Pin** | **CAN Function** | **Description** | +|:---------------:|:-----------------------:|:----------------:|:---------------:| +| `D4` | `P109` | `CAN_TX` | CAN Transmit | +| `D5` | `P110` | `CAN_RX` | CAN Receive | + +***__Important note__: The Nano R4's CAN interface provides logic-level signals only. You must use an external CAN transceiver (such as SN65HVD230 from Texas Instruments® or the MCP2561 from Microchip®) to convert these signals to the differential CAN bus levels (`CANH`/`CANL`) required for actual CAN communication.*** + +You can communicate via CAN using the built-in `Arduino_CAN` library included in the Arduino UNO R4 Boards core. The library provides functions to initialize the bus, send and receive CAN frames and handle message filtering. + +The following example demonstrates basic CAN communication patterns: + +```arduino +/** +CAN Basic Example for the Arduino Nano R4 Board +Name: nano_r4_can_basic.ino +Purpose: This sketch demonstrates basic CAN communication +for automotive and industrial applications. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - CAN Basic Example started..."); + + // Initialize CAN communication at 500k baud + if (!CAN.begin(CanBitRate::BR_500k)) { + Serial.println("- Error: Failed to initialize CAN bus!"); + while (1) delay(10); + } + + Serial.println("- CAN bus initialized at 500k baud"); + Serial.println("- Connect CAN transceiver to D4 (TX) and D5 (RX)"); + Serial.println("- Sending periodic CAN messages..."); + + delay(1000); +} + +void loop() { + // Send periodic CAN messages + static unsigned long lastSend = 0; + if (millis() - lastSend > 1000) { + lastSend = millis(); + + // Create a CAN message + uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; + CanMsg msg(CAN_ID(0x123), sizeof(data), data); + + // Send the message + int result = CAN.write(msg); + if (result == 1) { + Serial.print("- CAN message sent - ID: 0x"); + Serial.print(0x123, HEX); + Serial.print(", Data: "); + for (int i = 0; i < 8; i++) { + Serial.print("0x"); + if (data[i] < 16) Serial.print("0"); + Serial.print(data[i], HEX); + if (i < 7) Serial.print(" "); + } + Serial.println(); + } else { + Serial.println("- Error: Failed to send CAN message!"); + } + } + + // Check for incoming CAN messages + if (CAN.available()) { + CanMsg receivedMsg = CAN.read(); + + Serial.print("- CAN message received - ID: 0x"); + Serial.print(receivedMsg.id, HEX); + Serial.print(", Length: "); + Serial.print(receivedMsg.data_length); + Serial.print(", Data: "); + + for (int i = 0; i < receivedMsg.data_length; i++) { + Serial.print("0x"); + if (receivedMsg.data[i] < 16) Serial.print("0"); + Serial.print(receivedMsg.data[i], HEX); + if (i < receivedMsg.data_length - 1) Serial.print(" "); + } + Serial.println(); + } + + delay(10); +} +``` + +***To test this example, you need an external CAN transceiver connected to pins `D4` and `D5`. The code will demonstrate CAN communication patterns that can be observed with a CAN analyzer. Without a CAN transceiver and CAN network, the messages will not be transmitted on the actual CAN bus.*** + +Since the Nano R4's CAN interface provides only logic-level signals, you'll need an external CAN transceiver to convert these signals to the differential voltage levels required by CAN networks. The transceiver acts as a bridge between your Nano R4 board and the actual CAN bus, handling the electrical requirements and providing isolation. + +For prototyping with the Nano R4 board, you need a +5 VDC-compatible transceiver like the [MCP2561 from Microchip](https://ww1.microchip.com/downloads/en/DeviceDoc/20005167C.pdf), which matches the board's +5 VDC logic levels. While the [SN65HVD230 from Texas Instruments](https://www.ti.com/lit/ds/symlink/sn65hvd230.pdf) is popular and widely used, it operates at +3.3 VDC and may require level shifting when used with the +5 VDC Nano R4. + +When working with CAN on the Nano R4, there are several key points to keep in mind for successful implementation: + +- Always ensure proper termination with 120 Ω resistors at both ends of the CAN bus to prevent signal reflections. +- Keep in mind that CAN uses message-based communication with unique identifiers rather than device addresses. Lower ID numbers have higher priority, so critical messages should use lower IDs. +- The CAN protocol provides automatic error detection, retransmission and collision resolution, making it extremely reliable for safety-critical applications. +- The Nano R4 supports both standard (11-bit) and extended (29-bit) CAN identifiers, allowing compatibility with most automotive and industrial CAN networks. + +## HID (Human Interface Device) Communication + +The Nano R4 board features built-in HID (Human Interface Device) communication that allows your projects to emulate input devices like keyboards and mice. HID is implemented within the RA4M1 microcontroller and uses the USB-C connection to communicate directly with computers as standard input devices. This makes it perfect for automation projects, assistive technologies, gaming controllers and interactive installations that need to control computers or send keystrokes and mouse movements. + +HID is particularly useful when your project needs to interact directly with computer software, rather than just sending data through serial communication. While serial communication requires special software on the computer to interpret data, HID devices are recognized automatically by any operating system as standard keyboards or mice. This allows your Nano R4 to trigger keyboard shortcuts, type text, move the mouse cursor, or click buttons, making it ideal for presentation controllers, accessibility devices and automation systems. + +The Nano R4's HID interface offers the following technical specifications: + +| **Parameter** | **Value** | **Notes** | +|:----------------:|:----------------:|:-------------------------:| +| Device Types | Keyboard & Mouse | Standard HID classes | +| Connection | USB-C | Native USB connection | +| Compatibility | Cross-platform | Windows, macOS, Linux | +| Key Modifiers | All standard | Ctrl, Alt, Shift, GUI/Cmd | +| Mouse Buttons | 3 buttons | Left, Right, Middle | +| Mouse Movement | Relative/Delta | Smooth cursor movement | +| Scroll Wheel | Supported | Vertical scroll only | +| Multiple Devices | Supported | Keyboard + Mouse together | + +The Nano R4 uses the USB-C connector for HID communication: + +| **Connection** | **Function** | **Description** | +|:--------------:|:------------:|:----------------------------:| +| USB-C | HID | Keyboard and Mouse emulation | + +***__Important note__: When HID functionality is active, the Nano R4 board will be recognized by your computer as an input device. Be careful with your code to avoid sending unintended keystrokes or mouse movements that could interfere with normal computer operation.*** + +You can use HID communication through the dedicated `Keyboard.h` and `Mouse.h` libraries, which are included in the Arduino UNO R4 Boards core. These libraries provide simple functions to send keystrokes, key combinations, mouse movements and clicks. + +The following example demonstrates basic keyboard emulation capabilities: + +```arduino +/** +HID Keyboard Example for the Arduino Nano R4 Board +Name: nano_r4_hid_keyboard.ino +Purpose: This sketch demonstrates how to use the Nano R4 as a +USB keyboard to send keystrokes and key combinations. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include "Keyboard.h" + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - HID Keyboard Example started..."); + Serial.println("- WARNING: This will send actual keystrokes to your computer!"); + + // Wait 5 seconds before starting HID to give user time to read warning + Serial.println("- Starting in 5 seconds..."); + for (int i = 5; i > 0; i--) { + Serial.print(i); + Serial.println(" seconds remaining"); + delay(1000); + } + + // Initialize keyboard functionality + Keyboard.begin(); + Serial.println("- Keyboard HID initialized. Starting demonstration..."); + + delay(1000); + + // Demonstrate basic text typing + Serial.println("- Typing basic text..."); + Keyboard.print("Hello from Nano R4! "); + delay(1000); + + // Demonstrate special keys + Serial.println("- Pressing Enter key..."); + Keyboard.press(KEY_RETURN); + delay(100); + Keyboard.releaseAll(); + delay(1000); + + // Demonstrate keyboard shortcuts + Serial.println("- Sending Ctrl+A (Select All)..."); + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press('a'); + delay(100); + Keyboard.releaseAll(); + delay(1000); + + Serial.println("- Keyboard demonstration completed!"); +} + +void loop() { + // Send a timestamp every 10 seconds + static unsigned long lastMessage = 0; + if (millis() - lastMessage > 10000) { + lastMessage = millis(); + + Serial.println("- Sending periodic message..."); + + // Send message with only letters, numbers and spaces + Keyboard.print("Nano R4 "); + Keyboard.print(millis() / 1000); + Keyboard.print(" seconds"); + Keyboard.press(KEY_RETURN); + delay(50); + Keyboard.releaseAll(); + } + + delay(100); +} +``` + +***To test this example, no external components are needed. The code will wait 5 seconds before activating HID functionality, then automatically demonstrate various keyboard functions.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the status messages. + +![Arduino IDE Serial Monitor output for the keyboard emulation example sketch](assets/hid-1.png) + +After 5 seconds, the Nano R4 board will type text directly into whatever application has focus on your computer. + +![Keyboard emulation example](assets/hid-2.gif) + +The following example demonstrates mouse emulation capabilities: + +```arduino +/** +HID Mouse Example for the Arduino Nano R4 Board +Name: nano_r4_hid_mouse.ino +Purpose: This sketch demonstrates how to use the Nano R4 as a +USB mouse to control cursor movement and clicking. + +@author Arduino Product Experience Team +@version 1.0 01/06/25 +*/ + +#include "Mouse.h" + +void setup() { + // Initialize serial communication and wait up to 2.5 seconds for a connection + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(500)); + + Serial.println("- Arduino Nano R4 - HID Mouse Example started..."); + Serial.println("- WARNING: This will control your actual mouse cursor!"); + + // Wait 5 seconds before starting HID + Serial.println("- Starting in 5 seconds..."); + for (int i = 5; i > 0; i--) { + Serial.print(i); + Serial.println(" seconds remaining"); + delay(1000); + } + + // Initialize mouse functionality + Mouse.begin(); + Serial.println("- Mouse HID initialized. Starting demonstration..."); + + delay(1000); + + // Demonstrate basic mouse movement + Serial.println("- Moving mouse in a square pattern..."); + Mouse.move(100, 0); // Move right + delay(500); + Mouse.move(0, 100); // Move down + delay(500); + Mouse.move(-100, 0); // Move left + delay(500); + Mouse.move(0, -100); // Move up + delay(500); + + // Demonstrate mouse clicks + Serial.println("- Performing mouse clicks..."); + Mouse.click(MOUSE_LEFT); + delay(500); + Mouse.click(MOUSE_RIGHT); + delay(500); + + // Demonstrate scrolling + Serial.println("- Demonstrating scroll wheel..."); + Mouse.move(0, 0, 3); // Scroll up + delay(500); + Mouse.move(0, 0, -3); // Scroll down + delay(500); + + Serial.println("- Mouse demonstration completed!"); +} + +void loop() { + // Create a gentle circular mouse movement every 15 seconds + static unsigned long lastMovement = 0; + if (millis() - lastMovement > 15000) { + lastMovement = millis(); + + Serial.println("- Creating circular mouse movement..."); + for (int angle = 0; angle < 360; angle += 30) { + int x = (int)(10 * cos(angle * PI / 180)); + int y = (int)(10 * sin(angle * PI / 180)); + Mouse.move(x, y); + delay(100); + } + } + + delay(100); +} +``` + +***To test this example, no external components are needed. The code will automatically demonstrate mouse movement, clicking and scrolling functions.*** + +You can open the Arduino IDE's Serial Monitor (Tools > Serial Monitor) to see the status messages. + +![Arduino IDE Serial Monitor output for the mouse emulation example sketch](assets/hid-3.png) + +The mouse cursor will move and click according to the button presses. + +![Mouse emulation example](assets/hid-4.gif) + +When working with HID on the Nano R4, there are several key points to keep in mind for successful implementation: + +- HID functionality makes your Nano R4 board appear as a real keyboard and mouse to your computer, so always include safeguards and delays in your code to prevent unintended actions that could interfere with normal computer operation. +- Always include a delay or warning period before activating HID functionality to give yourself time to prepare or stop the program if needed. +- Keep in mind that HID devices are automatically recognized by all modern operating systems without requiring special drivers, making your projects instantly compatible with Windows, macOS and Linux. +- For debugging HID projects, use `Serial.println()` statements to track what your code is doing, since you cannot rely on the Arduino IDE's Serial Monitor once HID actions start interfering with your computer. +- The Nano R4 can function as both a keyboard and mouse simultaneously, allowing for complex automation sequences that combine typing, shortcuts and mouse control. +- Remember that different operating systems may have slightly different keyboard layouts and shortcuts, so test your HID projects on your target platform to ensure compatibility. + +## Support + +If you encounter any issues or have questions while working with your Nano R4 board, we provide various support resources to help you find answers and solutions. + +### Help Center + +Explore our Help Center, which offers a comprehensive collection of articles and guides for Nano family boards. The Help Center is designed to provide in-depth technical assistance and help you make the most of your device. + +- [Nano family help center page](https://support.arduino.cc/hc/en-us/sections/360004605400-Nano-Family) + +### Forum + +Join our community forum to connect with other Nano family board users, share your experiences, and ask questions. The Forum is an excellent place to learn from others, discuss issues, and discover new ideas and projects related to the Nano R4. + +- [Nano category in the Arduino Forum](https://forum.arduino.cc/c/official-hardware/nano-family/87) + +### Contact Us + +Please get in touch with our support team if you need personalized assistance or have questions not covered by the help and support resources described before. We're happy to help you with any issues or inquiries about the Nano family boards. + +- [Contact us page](https://www.arduino.cc/en/contact-us/) \ No newline at end of file diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/anomaly-detection.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/anomaly-detection.png new file mode 100644 index 0000000000..7a51621cce Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/anomaly-detection.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/anomaly-explorer.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/anomaly-explorer.png new file mode 100644 index 0000000000..52d5933c60 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/anomaly-explorer.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/classifier.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/classifier.png new file mode 100644 index 0000000000..e4a2885c24 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/classifier.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/daemon-version.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/daemon-version.png new file mode 100644 index 0000000000..6f0a0b5624 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/daemon-version.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/data-collection.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/data-collection.png new file mode 100644 index 0000000000..5b362f9dae Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/data-collection.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/data-forwarder-configuration.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/data-forwarder-configuration.png new file mode 100644 index 0000000000..f59fd5634b Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/data-forwarder-configuration.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/device-verification.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/device-verification.png new file mode 100644 index 0000000000..a174f5a0fe Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/device-verification.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/download-button.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/download-button.png new file mode 100644 index 0000000000..4ff5d7f9e6 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/download-button.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/example-sketch-1.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/example-sketch-1.png new file mode 100644 index 0000000000..9618358881 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/example-sketch-1.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/feature-explorer.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/feature-explorer.png new file mode 100644 index 0000000000..168cb5f0d0 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/feature-explorer.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/hardware-setup.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/hardware-setup.png new file mode 100644 index 0000000000..c378b7cb92 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/hardware-setup.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/hero-banner.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/hero-banner.png new file mode 100644 index 0000000000..2761cbb97c Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/hero-banner.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/impulse-design.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/impulse-design.png new file mode 100644 index 0000000000..ccfd3e5f8a Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/impulse-design.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/ml-monitor-output.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/ml-monitor-output.png new file mode 100644 index 0000000000..e2924f346a Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/ml-monitor-output.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/model-deployment.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/model-deployment.png new file mode 100644 index 0000000000..d938973ebc Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/model-deployment.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/model-validation.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/model-validation.png new file mode 100644 index 0000000000..9c0c2ec197 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/model-validation.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/motor_anomaly_detection.zip b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/motor_anomaly_detection.zip new file mode 100644 index 0000000000..5e4134b599 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/motor_anomaly_detection.zip differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/motor_vibration_collector.zip b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/motor_vibration_collector.zip new file mode 100644 index 0000000000..791b610361 Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/motor_vibration_collector.zip differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/new-project.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/new-project.png new file mode 100644 index 0000000000..10a628011c Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/new-project.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/spectral-features.png b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/spectral-features.png new file mode 100644 index 0000000000..fa77ac22cf Binary files /dev/null and b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/assets/spectral-features.png differ diff --git a/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/content.md b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/content.md new file mode 100644 index 0000000000..b078f4ef3f --- /dev/null +++ b/content/hardware/03.nano/boards/nano-r4/tutorials/02.anomaly-detection-application-note/content.md @@ -0,0 +1,964 @@ +--- +title: 'Motor Anomaly Detection with the Arduino® Nano R4' +description: "This application note describes how to implement a motor anomaly detection system using the Nano R4 board, the ADXL335 accelerometer and Edge Impulse." +difficulty: intermediate +compatible-products: [nano-r4] +tags: + - Motor monitoring + - Anomaly detection + - Classification + - Application note + - Machine learning + - Edge Impulse + - ADXL335 + - Nano R4 +author: 'José Bagur' +hardware: + - hardware/04.pro/boards/nano-r4 +software: + - ide-v2 + - edge-impulse +--- + +## Introduction + +Motor condition monitoring is essential in industrial settings where unexpected equipment failures can cause significant downtime and high maintenance costs. This application note shows how to build a motor anomaly detection system using the Nano R4 board, an ADXL335 accelerometer and Edge Impulse®. + +![ ](assets/hero-banner.png) + +The developed system monitors vibration patterns in real-time to identify unusual operating conditions that may signal mechanical problems, wear or potential failures. The system uses machine learning to detect vibration patterns that differ from normal motor operation, enabling predictive maintenance. + +## Goals + +This application note will help you to: + +- Build a motor anomaly detection system that monitors vibration patterns in real-time using an accelerometer. +- Collect and analyze vibration data from motors to create baseline patterns and detect changes. +- Train a machine learning model using Edge Impulse to detect anomalies based on vibration data. +- Deploy the trained model directly to the Nano R4 board for real-time anomaly detection without needing cloud connectivity. +- Set up visual feedback through the board's built-in LED to show detected anomalies and system status. +- Create industrial predictive maintenance solutions using cost-effective embedded intelligence. + +## Hardware and Software Requirements + +### Hardware Requirements + +- [Arduino Nano R4](https://store.arduino.cc/products/nano-r4) (x1) +- [ADXL335 accelerometer breakout board](https://www.adafruit.com/product/163) (x1) +- [USB-C® cable](https://store.arduino.cc/products/usb-cable2in1-type-c) (x1) +- Breadboard and jumper wires (x1 set) +- Motor or rotating equipment for testing (for example, a small DC motor or fan) (x1) +- Power supply for the motor (if needed) (x1) + +### Software Requirements + +- [Arduino IDE 2.0+](https://www.arduino.cc/en/software) or [Arduino Web Editor](https://create.arduino.cc/editor) +- [Arduino Renesas Core](https://github.com/arduino/ArduinoCore-renesas) (needed for the Nano R4 board) +- [Edge Impulse account](https://studio.edgeimpulse.com/) (free tier available) +- [Edge Impulse CLI tools](https://docs.edgeimpulse.com/docs/cli-installation) for data collection + +***The Nano R4 board offers improved processing power with a 32-bit Renesas RA4M1 microcontroller running at 48 MHz, 256 kB Flash memory and 32 kB SRAM for machine learning tasks. For complete hardware specifications, see the [Arduino Nano R4 documentation](https://docs.arduino.cc/hardware/nano-r4/).*** + +## Hardware Setup Overview + +The electrical connections for the motor anomaly detection system are shown in the diagram below: + +![The motor anomaly detection system hardware setup](assets/hardware-setup.png) + +This diagram shows how the system components connect. **The Nano R4 board acts as the main controller**, while **the ADXL335 accelerometer collects vibration data** from the motor. + +The ADXL335 accelerometer connects to the Nano R4 board using analog input pins. In this setup, an external +5 VDC power supply powers both the Nano R4 and the test motor, while the ADXL335 gets power through its built-in voltage regulator from the board's +5 VDC pin. + +***__Important note__: This power setup is for testing and demonstration only. In real industrial environments, proper power system design should include electrical isolation, noise filtering, surge protection and compliance with industrial safety standards for your specific application.*** + +### Circuit Connections + +The following connections establish the interface between the Nano R4 board and the ADXL335 accelerometer: + +| **ADXL335 Pin** | **Nano R4 Pin** | **Description** | +|:---------------:|:---------------:|:--------------------:| +| `VCC` | `5V` | Power supply | +| `GND` | `GND` | Ground reference | +| `X` | `A0` | X-axis analog output | +| `Y` | `A1` | Y-axis analog output | +| `Z` | `A2` | Z-axis analog output | +| `ST` | Not connected | Self-test (optional) | + +### Physical Mounting Considerations + +Proper accelerometer mounting is essential for effective vibration monitoring. The sensor must be securely attached to the motor housing or equipment using appropriate mechanical fasteners. Good mechanical connection between the mounting surface and sensor ensures accurate vibration transmission and reliable measurements. + +***For this application note, we will use a computer cooling fan to simulate motor operation and demonstrate the anomaly detection system. The ADXL335 accelerometer will be mounted on top of the fan using a custom 3D-printed enclosure, providing a stable and consistent mounting solution for testing.*** + +## Understanding Motor Vibration Analysis + +Motor vibrations contain valuable information about the mechanical condition of the equipment. Normal motor operation produces characteristic vibration patterns that stay relatively consistent during healthy operation. Abnormal conditions show up as changes in vibration amplitude, frequency content or timing patterns. + +### Common Motor Faults + +Common motor faults that can be detected through vibration analysis include: + +- **Bearing wear**: Creates higher frequency components and increased vibration levels across all axes +- **Misalignment**: Produces specific frequency patterns related to rotational speed, typically appearing in radial directions +- **Imbalance**: Results in increased vibration at the main rotational frequency, primarily in radial directions +- **Looseness**: Causes widespread increases in vibration across multiple frequencies and directions +- **Electrical issues**: May create vibrations at twice the line frequency due to magnetic field changes + +### The Role of Sensors in Vibration Monitoring + +Effective motor condition monitoring relies on sensors that can accurately detect and measure mechanical vibrations. These sensors must capture the small changes in vibration patterns that indicate developing faults or abnormal operating conditions. The choice of sensor technology directly affects the system's ability to detect problems early and provide reliable maintenance information. + +This application note uses the [ADXL335 accelerometer](https://www.analog.com/media/en/technical-documentation/data-sheets/adxl335.pdf) to provide accurate, real-time measurements of motor vibrations. The ADXL335 offers several key advantages for motor monitoring applications: + +- **3-Axis measurement**: Captures vibrations in X, Y, and Z directions +- **Analog output**: Direct compatibility with the Nano R4 board analog inputs without needing complex digital interfaces +- **Low power consumption**: Only 320 μA current consumption makes it suitable for continuous monitoring applications +- **Wide frequency range**: 0.5 Hz to 1600 Hz bandwidth covers most common motor fault frequencies + +The ADXL335 technical specifications include: + +| **Specification** | **Value** | **Notes** | +|:-----------------:|:---------------------------:|:------------------------------------------------:| +| Measurement range | ±3g on all axes | Appropriate for common motor vibration levels | +| Sensitivity | 330 mV/g nominal | Provides good resolution for vibration analysis | +| Output | Ratiometric analog voltages | +1.65 VDC represents 0g acceleration | +| Power supply | +1.8 to +3.6 VDC | Usually regulated to +3.3 VDC on breakout boards | + +Signal processing considerations include selecting appropriate sampling rates based on the expected frequency content of motor vibrations, typically following the Nyquist rule to avoid aliasing. The Nano R4 board's 14-bit ADC provides sufficient resolution for most vibration monitoring applications. + +## Simple Vibration Monitor Example Sketch + +Now that we have covered the hardware components and vibration analysis basics, let's look at the software that enables vibration data collection. Before implementing intelligent anomaly detection, we need to collect training data representing normal motor operation for Edge Impulse, a platform that simplifies embedded AI development. + +Edge Impulse needs training data in a specific format to build effective anomaly detection models. Our data collection sketch formats the accelerometer readings so Edge Impulse can analyze normal operation patterns and create a model that identifies when new data differs from these patterns. + +This section breaks down the example sketch and guides you through its functionality. We will explore how the accelerometer is initialized, how vibration data is collected at consistent intervals, and how the results are formatted for Edge Impulse data collection and model training. + +The complete example sketch is shown below. + +```arduino +/** + Motor Vibration Data Collection for Edge Impulse + Name: motor_vibration_collector.ino + Purpose: This sketch reads 3-axis acceleration data from an ADXL335 + accelerometer connected to an Arduino Nano R4. The data is formatted + for Edge Impulse data collection and training. + + @version 1.0 01/06/25 + @author Arduino Product Experience Team +*/ + +// Pin definitions for ADXL335 +const int xPin = A0; +const int yPin = A1; +const int zPin = A2; + +// Arduino ADC specifications +const int ADCMaxVal = 16383; // 14-bit ADC max value +const float mVMaxVal = 5000.0; // ADC reference voltage in mV + +// ADXL335 specifications (calibrated values for this specific breakout board) +const float supplyMidPointmV = 1237.0; // Measured 0g bias point +const float mVperg = 303.0; // Measured sensitivity (mV/g) + +// Sampling parameters +const int sampleRate = 100; // 100 Hz +const unsigned long sampleTime = 1000 / sampleRate; // 10ms between samples + +// Conversion factor from ADC to mV +const float mVPerADC = mVMaxVal / ADCMaxVal; + +// Data collection variables +unsigned long lastSample = 0; + +void setup() { + Serial.begin(115200); + analogReadResolution(14); + + Serial.println("- Motor Vibration Data Collector"); + Serial.println("- Streaming continuous data for Edge Impulse"); + Serial.println("- Data format: X_accel,Y_accel,Z_accel"); + + delay(1000); +} + +void loop() { + unsigned long currentTime = millis(); + + if (currentTime - lastSample >= sampleTime) { + // Read raw ADC values + int xRaw = analogRead(xPin); + int yRaw = analogRead(yPin); + int zRaw = analogRead(zPin); + + // Convert ADC values to millivolts + float xVoltmV = xRaw * mVPerADC; + float yVoltmV = yRaw * mVPerADC; + float zVoltmV = zRaw * mVPerADC; + + // Convert to acceleration in g units + float xAccel = (xVoltmV - supplyMidPointmV) / mVperg; + float yAccel = (yVoltmV - supplyMidPointmV) / mVperg; + float zAccel = (zVoltmV - supplyMidPointmV) / mVperg; + + // Output CSV format + Serial.print(xAccel, 4); + Serial.print(","); + Serial.print(yAccel, 4); + Serial.print(","); + Serial.println(zAccel, 4); + + lastSample = currentTime; + } +} +``` + +The following sections will help you understand the main components of the example sketch, which can be divided into the following areas: + +- Hardware configuration and calibration +- Data collection timing and control +- Signal processing and conversion +- Edge Impulse data formatting + +### Hardware Configuration and Calibration + +Before we can collect vibration data, we need to configure the Nano R4 board to interface with the ADXL335 accelerometer and set its calibration parameters. + +```arduino +// Pin definitions for ADXL335 +const int xPin = A0; +const int yPin = A1; +const int zPin = A2; + +// Arduino ADC specifications +const int ADCMaxVal = 16383; // 14-bit ADC max value +const float mVMaxVal = 5000.0; // ADC reference voltage in mV + +// ADXL335 specifications (calibrated values for this specific breakout board) +const float supplyMidPointmV = 1237.0; // Measured 0g bias point +const float mVperg = 303.0; // Measured sensitivity (mV/g) + +// Conversion factor from ADC to mV +const float mVPerADC = mVMaxVal / ADCMaxVal; +``` +In this code: + +- Pin assignments map each accelerometer axis to specific analog inputs on the Nano R4 board +- ADC specifications define the 14-bit resolution and 5V reference voltage used by the Nano R4 +- ADXL335 specifications use calibrated values measured from the actual breakout board +- The conversion factor translates raw ADC readings to millivolts for processing + +***__Important note__: ADXL335 breakout boards typically include onboard voltage regulators that convert the input voltage (+5 VDC from the Nano R4) to a lower voltage (usually +3.3 VDC or less) to power the accelerometer chip. This means the actual supply voltage to the ADXL335 may be different from what you expect. The values shown in this code (supplyMidPointmV = 1237.0 and mVperg = 303.0) are calibrated for a specific breakout board and may need adjustment for your hardware.*** + +### Data Collection Timing and Control + +To ensure accurate vibration analysis and successful machine learning training, we need consistent data collection timing. These parameters control how data is gathered: + +```arduino +// Sampling parameters +const int sampleRate = 100; // 100 Hz +const unsigned long sampleTime = 1000 / sampleRate; // 10 ms between samples +``` + +In this code: + +- Sample rate of 100 Hz captures enough frequency response for detecting most motor faults +- Sample time calculation automatically determines the precise timing needed between measurements +- The system streams data continuously without requiring manual start/stop commands + +### Signal Processing and Conversion + +Once we have the raw sensor readings, we need to convert them into useful acceleration values. This conversion process transforms the ADC readings into calibrated acceleration data: + +```arduino +void loop() { + unsigned long currentTime = millis(); + + if (currentTime - lastSample >= sampleTime) { + // Read raw ADC values + int xRaw = analogRead(xPin); + int yRaw = analogRead(yPin); + int zRaw = analogRead(zPin); + + // Convert ADC values to millivolts + float xVoltmV = xRaw * mVPerADC; + float yVoltmV = yRaw * mVPerADC; + float zVoltmV = zRaw * mVPerADC; + + // Convert to acceleration in g units + float xAccel = (xVoltmV - supplyMidPointmV) / mVperg; + float yAccel = (yVoltmV - supplyMidPointmV) / mVperg; + float zAccel = (zVoltmV - supplyMidPointmV) / mVperg; +``` + +In this code: + +- Timing control maintains consistent sample intervals, which is essential for proper frequency analysis +- ADC conversion uses the Nano R4's 14-bit resolution to convert raw readings to millivolts +- Acceleration calculation applies the calibrated zero-point and sensitivity values to get accurate g-force measurements + +***__Important note__: For accurate measurements, you should calibrate your specific ADXL335 breakout board by placing it flat on a table with the Z-axis pointing up and measuring the actual voltage outputs. The X and Y axes should read approximately the same voltage (this is your zero-g bias point), while the Z-axis should read higher due to gravity (1g acceleration). The difference between Z-axis voltage and the zero-g bias point gives you the sensitivity in mV/g. This calibration accounts for variations in onboard regulators and manufacturing tolerances.*** + +### Edge Impulse Data Formatting + +The final step formats our acceleration data so it can be used with Edge Impulse data collection tools: + +```arduino + // Output CSV format + Serial.print(xAccel, 4); + Serial.print(","); + Serial.print(yAccel, 4); + Serial.print(","); + Serial.println(zAccel, 4); +``` + +In this code: + +- CSV format with four decimal places gives us the precision needed for machine learning training +- Single-line output per sample makes it easy to integrate with the Edge Impulse data forwarder +- Comma separation follows standard CSV format that most data processing tools expect + +After uploading the example sketch to the Nano R4 board, you should see this output in the Arduino IDE's Serial Monitor when data collection is active: + +![Example sketch output showing vibration data collection](assets/example-sketch-1.png) + +### Complete Example Sketch + +Download the complete data collection example sketch [here](assets/motor_vibration_collector.zip). + +[![ ](assets/download-button.png)](assets/motor_vibration_collector.zip) + +## Connecting the Vibration Monitor to Edge Impulse + +As vibration-based condition monitoring becomes more important for predictive maintenance, connecting our data collection system to Edge Impulse enables the development of intelligent anomaly detection models. Edge Impulse provides a complete platform for embedded machine learning, allowing us to transform raw vibration data into useful insights about motor health. + +In this section, we will connect the vibration monitor to Edge Impulse platform to collect training data, develop machine learning models and deploy intelligent anomaly detection directly to the Nano R4 board. This connection transforms our simple vibration monitor into an intelligent system that can detect motor anomalies without needing cloud connectivity. + +***If you are new to Edge Impulse, please check out [this tutorial](https://docs.edgeimpulse.com/docs/tutorials/end-to-end-tutorials/time-series/continuous-motion-recognition/) for an introduction to the platform.*** + +### Setting up Edge Impulse Account and Project + +The first step involves creating an Edge Impulse account and setting up a new project for motor anomaly detection. These steps establish the foundation for machine learning model development: + +1. **Create Account**: Register for a free Edge Impulse account at [studio.edgeimpulse.com](https://studio.edgeimpulse.com/) +2. **New Project**: Create a new project with the following settings: + +- Enter a project name (for example, "`nano-r4-anomaly-detection`") +- Choose project type: Personal (free tier with 60 min job limit, 4 GB data limit) +- Choose project setting: Private (recommended for this application) + +![Creating a new project on Edge Impulse](assets/new-project.png) + +3. **Project Configuration**: Once created, the project will be ready for data collection. Sampling frequency and window settings will be configured later during impulse design. + +### Data Collection with Edge Impulse CLI + +The Edge Impulse CLI provides tools for streaming data directly from the Arduino to the Edge Impulse platform. This eliminates manual file transfers and enables efficient data collection. + +#### Installing Edge Impulse CLI + +Before you can collect data from the Arduino, you need to install the Edge Impulse CLI tools on your computer. The installation process varies depending on your operating system. + +Prerequisites: + +- Node.js 14 or higher +- Python 3 + +For detailed installation instructions specific to your operating system, follow the [official Edge Impulse CLI installation guide](https://docs.edgeimpulse.com/docs/tools/edge-impulse-cli/cli-installation). + +Verify the installation with the following command: + +```bash +edge-impulse-daemon --version +``` + +![Edge Impulse Daemon version](assets/daemon-version.png) + +#### Setting up Data Forwarding + +Now that you have the CLI installed, you can set up data forwarding to stream vibration data directly from your Nano R4 board to Edge Impulse. + +Connect your Nano R4 to your computer via USB-C cable and upload the data collection sketch. Then open a terminal and run the following command: + +```bash +edge-impulse-data-forwarder +``` + +The tool will guide you through the setup process: + +1. **Login**: Enter your Edge Impulse username/email and password when prompted +2. **Select Device**: Choose the correct serial port for your Arduino (for example, `COM5`) +3. **Data Detection**: The tool will automatically detect the data frequency (100 Hz) and number of sensor axes (3) +4. **Name Axes**: When asked "What do you want to call them?", enter: `X`,`Y`,`Z` +5. **Device Name**: Give your device a name (for example, `nano-r4`) +6. **Project Connection**: If you have multiple projects, the tool will ask which Edge Impulse project you want to connect the device to. Select your motor anomaly detection project. + +![Setting up the data forwarder tool](assets/data-forwarder-configuration.png) + +Once configured, the forwarder will stream data from your Nano R4 board to Edge Impulse. You can verify the device connection by checking the "Devices" tab in Edge Impulse Studio. You can then start collecting training data for your machine learning model. + +![Device connection verification to Edge Impulse Studio](assets/device-verification.png) + +#### Data Collection Process + +With the data forwarder running, you can now collect training data for your anomaly detection model. For effective anomaly detection, you need high-quality data representing normal motor operation in different states. + +Start by mounting the accelerometer securely to the motor housing. You will collect two types of normal operation data: + +1. **Idle data collection**: With the motor turned off, **collect 10 to 15 minutes of "idle" operation** data through multiple two second windows. This captures the baseline vibration environment without motor operation. Label all data as `idle` in Edge Impulse Studio. + +2. **Nominal data collection**: With the motor running under normal operating conditions, **collect 10 to 15 minutes of "nominal" operation** data through multiple two second windows. Vary motor load conditions slightly to capture different normal operating scenarios. Label all data as `nominal` in Edge Impulse Studio. + +Edge Impulse can automatically split your collected data into **training (80%) and testing (20%) sets**. The 20 to 30 minutes total of data ensures you have enough samples for both training the model and validating its performance on unseen data. + +![Data collection on Edge Impulse Studio](assets/data-collection.png) + +After data collection, review the collected samples in Edge Impulse Studio for consistency. Check for proper amplitude ranges and no clipping, verify sample rate consistency and timing accuracy and remove any corrupted or unusual samples from the training set. + +***__Important note__: The anomaly detection model learns what "normal" looks like from both idle and nominal data. Any future vibration patterns that significantly differ from these learned patterns will be flagged as anomalies. This approach allows the system to detect unknown fault conditions without needing examples of actual motor failures.*** + +### Training the Anomaly Detection Model + +Once you have collected sufficient `idle` and `nominal` operation data, the next step involves configuring and training the machine learning model for anomaly detection. + +#### Impulse Design Configuration + +Within Edge Impulse Studio, configure the impulse design with appropriate processing and learning blocks. Navigate to the "Impulse design" tab and set up the following blocks: + +1. **Input Block**: Configure time series data with window size of 2000 ms, window increase of 80 ms, and frequency of 100 Hz to match your data collection sampling rate. +2. **Processing Block**: Add "Spectral Analysis" block for frequency domain feature extraction +3. **Classification Learning Block**: Add "Classification (Keras)" to distinguish between `idle` and `nominal` operating states. +4. **Learning Block**: Select "Anomaly Detection (K-means)" for unsupervised learning approach + +![Impulse design on Edge Impulse Studio](assets/impulse-design.png) + +This dual approach provides a more robust monitoring system where the classifier identifies the current operating state (idle vs nominal) while the anomaly detector flags unusual patterns that don't fit either normal category. + +#### Feature Extraction Configuration + +The spectral analysis block extracts relevant features from the raw vibration signals. Configure the following parameters for optimal motor fault detection: + +- **Type**: Low-pass filter to focus on motor fault frequencies +- **Cut-off frequency**: 45 Hz to capture relevant motor vibration characteristics while staying below the Nyquist frequency +- **Order**: 6 for effective filtering +- **FFT length**: 256 points for sufficient frequency resolution +- **Take log of spectrum**: Enable this option to compress the dynamic range of the frequency data +- **Overlap FFT frames**: Enable this option to increase the number of features extracted from each window + +![Spectral features on Edge Impulse Studio](assets/spectral-features.png) + +***__Important note__: The spectral analysis converts time-domain vibration signals into frequency-domain features. This is crucial because motor faults often appear as specific frequency patterns (like bearing wear creating high-frequency components or imbalance showing up at rotational frequency). The K-means clustering algorithm groups similar frequency patterns together, creating a map of normal operation that can identify when new data doesn't fit the established patterns.*** + +#### Model Training Process + +Follow these steps to train the anomaly detection model using the collected idle and nominal operation data: + +1. **Generate Features**: Before clicking "Generate features", enable "Calculate feature importance" to identify which frequency bands are most relevant for distinguishing between idle and nominal states. Then click "Generate features" to extract spectral features from all training data. Edge Impulse will process your data and create the feature vectors needed for training. +2. **Feature Explorer**: Review the feature explorer visualization to verify data quality and feature separation between your idle and nominal classes. + +![Feature explorer on Edge Impulse Studio](assets/feature-explorer.png) + +3. **Train Classification Model**:Navigate to the "Classifier" tab and configure the neural network with the following settings: + +- Number of training cycles: 30 +- Learning rate: 0.0005 +- Neural network architecture: Configure dense layers with 32 neurons (first layer) and 16 neurons (second layer) to provide good pattern recognition capability for vibration data. Start training and monitor the accuracy metrics. + +![Classifier on Edge Impulse Studio](assets/classifier.png) + +1. **Train Anomaly Detection Model**: Navigate to the "Anomaly detection" tab and configure K-means clustering with 32 clusters for pattern recognition. Use "Select suggested axes" to automatically choose the most relevant spectral features based on the calculated feature importance, then start training. + +![Anomaly detection on Edge Impulse Studio](assets/anomaly-detection.png) + +5. **Model Validation**: Test both models using the validation data to ensure the classifier accurately distinguishes between idle and nominal states, and the anomaly detector properly identifies normal operation patterns. + +***__Important note__: The feature explorer shows how well your idle and nominal data separate in the feature space. Good separation means the model can clearly distinguish between different operating states. If the data points overlap significantly, you may need to collect more diverse data or adjust your sensor mounting.*** + +The classification model learns to distinguish between known operating states, while the anomaly detection model creates clusters representing all normal operation patterns. This combination allows the system to both identify the current operating mode and detect unusual conditions that don't fit any normal pattern. + +![Anomaly explorer on Edge Impulse Studio](assets/anomaly-explorer.png) + +***__Important note__: The 32 clusters create a detailed map of normal operation patterns. Each cluster represents a different "type" of normal vibration signature. When new data doesn't fit well into any existing cluster, it's flagged as an anomaly. More clusters provide finer detail but require more training data.*** + +#### Model Validation and Testing + +After training completion, validate both model performances using the following methods: + +- **Live Classification**: Use the "Live classification" feature of Edge Impulse to test both the classifier and anomaly detector with new motor data to verify their detection capabilities +- **Classification Performance**: Review the confusion matrix and accuracy metrics for the neural network classifier to ensure it properly distinguishes between idle and nominal states +- **Anomaly Detection Analysis**: Review the clustering visualization and anomaly scores to understand how well the model separates normal patterns +- **Threshold Adjustment**: During deployment and real-world testing, you may need to adjust the anomaly detection threshold based on observed false alarm rates and detection sensitivity +- **Validation Testing**: Test both models with known normal conditions to reduce false positives and ensure reliable operation + +![Model validation on Edge Impulse Studio](assets/model-validation.png) + +***__Important note__: The anomaly threshold is critical for system performance. A lower threshold makes the system more sensitive and catches subtle problems but may trigger false alarms. A higher threshold reduces false alarms but might miss early-stage faults.*** + +### Model Deployment + +After successful training and validation of both models, deploy them as an Arduino library for embedded inference: + +1. **Deployment Section**: Navigate to the "Deployment" tab in Edge Impulse Studio +2. **Arduino Library**: Select "Arduino library" as the deployment target +3. **Optimization Settings**: Choose `int8` quantization for memory efficiency on the Nano R4 board +4. **Model Analysis**:Review memory usage and inference timing estimates +5. **Download Library**: Download the generated Arduino library ZIP file +6. **Library Installation**: Install in the Arduino IDE using "Sketch > Include Library > Add .ZIP Library" + +![Model deployment on Edge Impulse Studio](assets/model-deployment.png) + +The generated library includes optimized inference code for both the neural network classifier and K-means anomaly detector, specifically compiled for the Nano R4's Arm® Cortex®-M4 processor. This enables efficient real-time classification of operating states (idle/nominal) and detection of anomalous conditions with low computational overhead. + +## Improving the Vibration Monitor with Machine Learning + +Now that we have trained our machine learning models, we can create a smart vibration monitor that automatically detects motor problems in real-time. + +The enhanced system does two things: it identifies whether the motor is running (nominal) or stopped (idle), and it alerts you when it detects unusual vibration patterns that might indicate a problem. This all happens directly on the Nano R4 board without needing an internet connection. + +The smart monitoring system can do the following: + +- Tell if the motor is running or stopped +- Detect unusual vibrations that might indicate problems +- Flash an LED and show alerts when something seems wrong +- Work continuously without needing internet or cloud services + +The complete enhanced example sketch is shown below: + +```arduino +/** + Intelligent Motor Anomaly Detection System + Name: motor_anomaly_detection.ino + Purpose: This sketch implements real-time motor anomaly detection using + an ADXL335 accelerometer and Edge Impulse machine learning model deployed + on Arduino Nano R4 for predictive maintenance applications. + + @version 1.0 01/06/25 + @author Arduino Product Experience Team +*/ + +// Include the Edge Impulse library (name will match your project) +#include + +// Pin definitions for ADXL335 accelerometer +const int xPin = A0; +const int yPin = A1; +const int zPin = A2; + +// Arduino ADC specifications +const int ADCMaxVal = 16383; // 14-bit ADC max value +const float mVMaxVal = 5000.0; // ADC reference voltage in mV + +// ADXL335 specifications (calibrated values for this specific breakout board) +const float supplyMidPointmV = 1237.0; // Measured 0g bias point +const float mVperg = 303.0; // Measured sensitivity (mV/g) + +// Conversion factor from ADC to mV +const float mVPerADC = mVMaxVal / ADCMaxVal; + +// Edge Impulse model parameters +const int samplingFreq = EI_CLASSIFIER_FREQUENCY; +const int sampleLength = EI_CLASSIFIER_RAW_SAMPLE_COUNT; + +// Data buffer for model inference +float features[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE]; +int featureIndex = 0; + +// Detection parameters - AJUSTADOS +const float anomalyThreshold = 0.6; // Increased from 0.3 to reduce false alarms +const float confidenceThreshold = 0.7; // Minimum confidence for classification +const int alertPin = LED_BUILTIN; +const int alertDuration = 2000; // Increased to 2 seconds + +// System status variables +unsigned long lastInference = 0; +unsigned long lastAlert = 0; +bool systemReady = false; + +// Performance tracking - NUEVO +int totalInferences = 0; +int anomalyCount = 0; + +/** + Initializes the accelerometer, LED, and machine learning system. + Configures the Arduino Nano R4 for optimal performance with the + Edge Impulse model and prepares for real-time anomaly detection. +*/ +void setup() { + // Initialize serial communication + Serial.begin(115200); + while (!Serial); + + // Configure hardware + analogReadResolution(14); // Maximum ADC resolution + pinMode(alertPin, OUTPUT); // Configure alert LED + digitalWrite(alertPin, LOW); // Ensure LED starts off + + // System initialization message + ei_printf("Motor Anomaly Detection System\n"); + ei_printf("Initializing Edge Impulse model...\n"); + + // Display model information + ei_printf("Model: %s\n", EI_CLASSIFIER_PROJECT_NAME); + ei_printf("Sampling frequency: %d Hz\n", samplingFreq); + ei_printf("Sample window: %.1f seconds\n", (float)sampleLength / samplingFreq); + ei_printf("Anomaly threshold: %.2f\n", anomalyThreshold); + ei_printf("Confidence threshold: %.2f\n", confidenceThreshold); + + // Allow sensor stabilization + delay(2000); + systemReady = true; + + ei_printf("System ready - Starting motor monitoring...\n"); + ei_printf("Classifications, Anomaly Score, Status, Timing\n"); +} + +/** + Main loop that continuously monitors motor vibrations and performs + real-time classification and anomaly detection using the embedded machine learning models. +*/ +void loop() { + if (systemReady) { + // Collect vibration data for inference + collectVibrationWindow(); + + // Perform classification and anomaly detection + performInference(); + + // Brief delay between inference cycles + delay(500); // Increased delay to reduce processing load + } +} + +/** + Collects a complete window of vibration data for machine learning inference. + OPTIMIZED VERSION - faster and more reliable timing. +*/ +void collectVibrationWindow() { + featureIndex = 0; + unsigned long sampleInterval = 1000000 / samplingFreq; // Microseconds per sample + + // Collect samples according to model requirements + for (int sample = 0; sample < (sampleLength / 3); sample++) { + unsigned long sampleStart = micros(); + + // Read raw ADC values + int xRaw = analogRead(xPin); + int yRaw = analogRead(yPin); + int zRaw = analogRead(zPin); + + // Convert ADC values to millivolts + float xVoltmV = xRaw * mVPerADC; + float yVoltmV = yRaw * mVPerADC; + float zVoltmV = zRaw * mVPerADC; + + // Convert to acceleration in g units + float xAccel = (xVoltmV - supplyMidPointmV) / mVperg; + float yAccel = (yVoltmV - supplyMidPointmV) / mVperg; + float zAccel = (zVoltmV - supplyMidPointmV) / mVperg; + + // Store in feature buffer for inference + features[featureIndex++] = xAccel; + features[featureIndex++] = yAccel; + features[featureIndex++] = zAccel; + + // Wait for next sample time + while (micros() - sampleStart < sampleInterval) { + // Precise timing wait + } + } +} + +/** + Performs classification and anomaly detection with improved confidence handling + and better false alarm reduction. +*/ +void performInference() { + ei_impulse_result_t result = { 0 }; + + // Create signal structure for Edge Impulse + signal_t features_signal; + features_signal.total_length = sampleLength; + features_signal.get_data = &getFeatureData; + + // Run the Edge Impulse classifier + EI_IMPULSE_ERROR inferenceResult = run_classifier(&features_signal, &result, false); + + if (inferenceResult == EI_IMPULSE_OK) { + totalInferences++; + + // Find the classification with highest confidence + String motorState = "uncertain"; + float maxConfidence = 0.0; + String bestClass = "unknown"; + + for (uint16_t i = 0; i < EI_CLASSIFIER_LABEL_COUNT; i++) { + if (result.classification[i].value > maxConfidence) { + maxConfidence = result.classification[i].value; + bestClass = ei_classifier_inferencing_categories[i]; + } + } + + // Apply confidence threshold + if (maxConfidence >= confidenceThreshold) { + motorState = bestClass; + } + + // Simplified multiline output + ei_printf("\n--- Motor Status ---\n"); + ei_printf("State: %s (%.1f%% confidence)\n", motorState.c_str(), maxConfidence * 100); + +#if EI_CLASSIFIER_HAS_ANOMALY + bool isAnomaly = false; + + if (result.anomaly > anomalyThreshold) { + isAnomaly = true; + anomalyCount++; + ei_printf("Alert: ANOMALY DETECTED (%.2f)\n", result.anomaly); + } else { + ei_printf("Status: Normal (%.2f)\n", result.anomaly); + } + + if (isAnomaly) { + triggerAnomalyAlert(); + } +#else + ei_printf("Status: %s\n", motorState.c_str()); +#endif + + ei_printf("Processing time: %dms\n", result.timing.dsp + result.timing.classification); + + // Show performance statistics every 10 inferences + if (totalInferences % 10 == 0) { + float anomalyRate = (float)anomalyCount / totalInferences * 100.0; + ei_printf("Stats: %.1f%% anomalies detected (%d/%d)\n", anomalyRate, anomalyCount, totalInferences); + } + + // Update timing + lastInference = millis(); + + } else { + // Handle inference errors + ei_printf("Inference error: %d\n", inferenceResult); + + // Flash LED to indicate system error + digitalWrite(alertPin, HIGH); + delay(100); + digitalWrite(alertPin, LOW); + } +} + +/** + Enhanced anomaly alert with rate limiting and better feedback. +*/ +void triggerAnomalyAlert() { + unsigned long currentTime = millis(); + + // Rate limit alerts to prevent excessive notifications + if (currentTime - lastAlert > alertDuration) { + // More distinctive visual alert pattern + for (int i = 0; i < 3; i++) { + digitalWrite(alertPin, HIGH); + delay(150); + digitalWrite(alertPin, LOW); + delay(150); + } + + // Log anomaly event with timestamp + ei_printf("*** ANOMALY DETECTED at %lu ms - CHECK EQUIPMENT ***\n", currentTime); + + lastAlert = currentTime; + } +} + +/** + Callback function for Edge Impulse library to access feature data. + Provides the machine learning model with vibration data in the + required format for inference processing. +*/ +int getFeatureData(size_t offset, size_t length, float *out_ptr) { + memcpy(out_ptr, features + offset, length * sizeof(float)); + return 0; +} +``` + +The following sections will help you understand the main components of the enhanced example sketch, which can be divided into the following areas: + +- Edge Impulse library integration +- Real-time data collection and buffering +- Machine learning inference execution +- Anomaly detection and alert system + +### Edge Impulse Library Integration + +The enhanced sketch starts by including the Edge Impulse library and setting up the necessary constants. + +```arduino +// Include the Edge Impulse library (name will match your project) +#include + +// ADXL335 specifications (calibrated for this specific breakout board) +const float supplyMidPointmV = 1237.0; // Measured 0g bias point +const float mVperg = 303.0; // Measured sensitivity (mV/g) + +// Detection parameters +const float anomalyThreshold = 0.6; // Reduced false alarms +const float confidenceThreshold = 0.7; // Minimum confidence for classification + +// Data buffer for the models +float features[EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE]; +``` + +The library contains both the classification model (to identify if the motor is idle or running) and the anomaly detection model (to spot unusual vibrations). The ADXL335 constants use measured values from the actual sensor rather than theoretical values for better accuracy. + +### Real-Time Data Collection And Buffering + +The system collects vibration data for the machine learning models to analyze. + +```arduino +void collectVibrationWindow() { + featureIndex = 0; + unsigned long sampleInterval = 1000000 / samplingFreq; // Microseconds per sample + + // Collect samples according to model requirements + for (int sample = 0; sample < (sampleLength / 3); sample++) { + unsigned long sampleStart = micros(); + + // Read raw ADC values + int xRaw = analogRead(xPin); + int yRaw = analogRead(yPin); + int zRaw = analogRead(zPin); + + // Convert ADC values to millivolts + float xVoltmV = xRaw * mVPerADC; + float yVoltmV = yRaw * mVPerADC; + float zVoltmV = zRaw * mVPerADC; + + // Convert to acceleration in g units + float xAccel = (xVoltmV - supplyMidPointmV) / mVperg; + float yAccel = (yVoltmV - supplyMidPointmV) / mVperg; + float zAccel = (zVoltmV - supplyMidPointmV) / mVperg; + + // Store in feature buffer for inference + features[featureIndex++] = xAccel; + features[featureIndex++] = yAccel; + features[featureIndex++] = zAccel; + + // Wait for next sample time + while (micros() - sampleStart < sampleInterval) { + // Precise timing wait + } + } +} +``` + +This function reads vibration data from the accelerometer and converts it to the format needed by the machine learning models. It collects exactly 200 samples (two seconds of data) and maintains precise timing to match the training data. + +### Machine Learning Inference Execution + +The system analyzes the collected vibration data using both machine learning models to determine motor state and detect anomalies. + +```arduino +void performInference() { + ei_impulse_result_t result = { 0 }; + + signal_t features_signal; + features_signal.total_length = sampleLength; + features_signal.get_data = &getFeatureData; + + EI_IMPULSE_ERROR inferenceResult = run_classifier(&features_signal, &result, false); + + if (inferenceResult == EI_IMPULSE_OK) { + // Find the best classification + String motorState = "uncertain"; + float maxConfidence = 0.0; + + for (uint16_t i = 0; i < EI_CLASSIFIER_LABEL_COUNT; i++) { + if (result.classification[i].value > maxConfidence) { + maxConfidence = result.classification[i].value; + motorState = ei_classifier_inferencing_categories[i]; + } + } + + // Check if we're confident enough + if (maxConfidence < confidenceThreshold) { + motorState = "uncertain"; + } + + // Check for anomalies + bool isAnomaly = (result.anomaly > anomalyThreshold); + + // Display results + // ... output code ... + } +} +``` + +This function runs both models on the collected data. The classification model determines if the motor is idle or running, while the anomaly detection model checks if the vibration patterns look unusual. The system only makes a classification if it's confident enough in the result. + +### Anomaly Detection and Alert System + +The system provides feedback when it detects problems with the motor. + +```arduino +void triggerAnomalyAlert() { + unsigned long currentTime = millis(); + + if (currentTime - lastAlert > alertDuration) { + // Flash LED three times + for (int i = 0; i < 3; i++) { + digitalWrite(alertPin, HIGH); + delay(150); + digitalWrite(alertPin, LOW); + delay(150); + } + + // Log the event + ei_printf("*** ANOMALY DETECTED at %lu ms - CHECK EQUIPMENT ***\n", currentTime); + + lastAlert = currentTime; + } +} +``` + +When the system detects unusual vibration patterns, it flashes the built-in LED three times and prints a warning message. The alert system prevents spam by waiting at least 2 seconds between alerts, even if multiple anomalies are detected. + +After uploading the enhanced sketch to the Nano R4 board, you should see the following output in the Arduino IDE's Serial Monitor during normal operation: + +![Enhanced example sketch output showing real-time anomaly detection](assets/ml-monitor-output.png) + +When an anomaly is detected, the built-in LED will flash twice and the serial output will display the anomaly score above the configured threshold along with a warning message. + +### Complete Enhanced Example Sketch + +The complete intelligent motor anomaly detection sketch can be downloaded [here](assets/motor_anomaly_detection.zip). + +[![ ](assets/download-button.png)](assets/motor_anomaly_detection.zip) + + +### System Integration Considerations + +When deploying the intelligent anomaly detection system in industrial environments, consider the following factors: + +- **Environmental Protection**: Protect the Nano R4 board and accelerometer from dust, moisture and temperature extremes using appropriate enclosures rated for the operating environment. +- **Mounting Stability**: Ensure secure mechanical mounting of both the accelerometer sensor and the Nano R4 enclosure to prevent sensor movement that could affect measurement accuracy. +- **Power Management**: Implement appropriate power supply filtering and protection circuits, especially in electrically noisy industrial environments with motor drives and switching equipment. +- **Calibration Procedures**: Establish baseline measurements for each motor installation to account for mounting variations and motor-specific characteristics that may affect anomaly thresholds. +- **Maintenance Integration**: Plan integration with existing maintenance management systems through data logging interfaces or communication protocols for complete predictive maintenance programs. + +## Conclusions + +This application note demonstrates how to implement motor anomaly detection using the Nano R4 board, ADXL335 accelerometer and Edge Impulse machine learning platform for industrial predictive maintenance applications. + +The solution combines the Nano R4's 32-bit processing power with Edge Impulse's machine learning tools to enable real-time anomaly detection directly on the embedded device. This eliminates the need for cloud connectivity and provides immediate response to potential equipment issues with inference times under 20 milliseconds. + +The unsupervised anomaly detection approach using K-means clustering requires only normal operation data for training, making it practical for industrial deployment where fault data may be difficult to obtain. This approach can detect previously unseen fault conditions that differ from established normal patterns. + +## Next Steps + +Building upon this foundation, several enhancements can further improve the motor anomaly detection system: + +- **Multi-Sensor Fusion**: Integrate additional sensors such as temperature, current or acoustic sensors to provide a more complete view of motor health and improve detection accuracy. +- **Wireless Communication**: Add wireless connectivity using LoRaWAN, Wi-Fi or other modules to enable remote monitoring and integration with existing plant systems. +- **Advanced Analysis**: Implement data logging for trend analysis, industrial protocol integration for SCADA systems or multi-class fault classification to distinguish between different types of motor problems. + +The foundation provided in this application note enables rapid development of custom motor monitoring solutions tailored to specific industrial requirements. \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy