Skip to content

Commit e43b494

Browse files
committed
doc: develop: manifests: external: add arduino core
Add documentation for the Arduino Core API for zephyr which sits as an external module as of today. Signed-off-by: Dhruva Gole <[email protected]>
1 parent 282e2c7 commit e43b494

File tree

1 file changed

+193
-0
lines changed

1 file changed

+193
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
.. _external_module_arduino_core_api:
2+
3+
Arduino Core API
4+
################
5+
6+
Introduction
7+
************
8+
9+
The Arduino-Core-Zephyr module started as a `Google Summer of Code 2022 project`_
10+
to provide Arduino-style APIs for Zephyr RTOS applications. This module acts as an abstraction
11+
layer, allowing developers familiar with Arduino programming to leverage Zephyr's capabilities
12+
without having to learn entirely new APIs and libraries.
13+
14+
Understanding the Components
15+
============================
16+
17+
This module consists of two key components that work together:
18+
19+
**1. ArduinoCore-API (Common Arduino API Definition)**
20+
21+
The `ArduinoCore-API <https://github.com/arduino/ArduinoCore-API>`_ is Arduino's official
22+
hardware abstraction layer that defines the common Arduino API. It contains the abstract API
23+
definitions **and** implementations for hardware-independent functionality.
24+
25+
Key characteristics:
26+
27+
* Contains both API definitions (headers) and hardware-agnostic implementations
28+
* Provides classes like ``String``, ``Print``, ``Stream``, ``IPAddress`` with full implementations
29+
* Defines interfaces for hardware-specific classes (e.g., ``HardwareSerial``, ``HardwareSPI``)
30+
* Shared across all modern Arduino platforms for consistency
31+
* See the `ArduinoCore-API README <https://github.com/arduino/ArduinoCore-API#arduinocore-api>`_ for implementation details
32+
33+
**2. Arduino-Core-Zephyr (Zephyr-Specific Implementation)**
34+
35+
The `Arduino-Core-Zephyr <https://github.com/zephyrproject-rtos/arduino-core-zephyr>`_ module
36+
provides the **Zephyr-specific implementation** of the Arduino API. This is where hardware-dependent
37+
Arduino functions are implemented using Zephyr's native APIs and drivers.
38+
39+
Key characteristics:
40+
41+
* Contains the ``cores/arduino`` directory with Zephyr implementations (``zephyrCommon.cpp``, ``zephyrSerial.cpp``, etc.)
42+
* Provides board-specific variants with pin mappings and Device Tree overlays
43+
* Includes Zephyr build system integration (CMake, Kconfig, west.yml)
44+
* Links to ArduinoCore-API to inherit the common implementations
45+
* See the `project documentation <https://github.com/zephyrproject-rtos/arduino-core-zephyr/tree/main/documentation>`_ for implementation details
46+
47+
Features Provided
48+
=================
49+
50+
Together, these components provide:
51+
52+
* Standard Arduino API functions like ``pinMode()``, ``digitalWrite()``, ``analogRead()``, etc.
53+
* Support for Arduino-style ``setup()`` and ``loop()`` functions
54+
* Pin mapping between Arduino pin numbers and Zephyr's GPIO definitions
55+
* Support for common Arduino communication protocols (Serial, I2C, SPI)
56+
* Compatibility with existing Arduino libraries
57+
* Board variant support for various hardware platforms already present in Zephyr
58+
59+
By bringing Arduino-style programming to Zephyr, this module provides a gentler learning curve
60+
for those transitioning from Arduino to Zephyr while still benefiting from Zephyr's advanced
61+
features, scalability, and broad hardware support.
62+
63+
Usage with Zephyr
64+
*****************
65+
66+
Adding the Arduino Core API to a Zephyr Project
67+
===============================================
68+
69+
#. To include the Arduino Core API in your Zephyr project, add the following
70+
entry to the ``manifest/projects`` subtree in your ``west.yml`` file:
71+
72+
.. code-block:: yaml
73+
74+
# Arduino API repository
75+
- name: Arduino-Core-Zephyr
76+
path: modules/lib/arduinocore-zephyr
77+
revision: main
78+
url: https://github.com/zephyrproject-rtos/arduino-core-zephyr
79+
80+
#. Run the following command to update your project:
81+
82+
.. code-block:: bash
83+
84+
west update
85+
86+
#. For Linux users, there's an ``install.sh`` script in the module that will automatically
87+
link the ArduinoCore-API. If you can't use this script, follow the manual steps below.
88+
89+
#. Complete the core setup by linking the API folder from the ArduinoCore-API repository into
90+
the arduinocore-zephyr folder:
91+
92+
.. code-block:: bash
93+
94+
git clone https://github.com/arduino/ArduinoCore-API # Any location
95+
cd /<path>/<to>/<zephyrproject>/modules/lib/arduinocore-zephyr
96+
ln -s /<your>/<location>/arduinocore-zephyr/api cores/arduino/.
97+
98+
The ``cores`` folder is located inside ``<zephyr-project-path>/modules/lib/arduinocore-zephyr/cores``.
99+
100+
Using Arduino Core API in Your Application
101+
==========================================
102+
103+
#. In your application's ``prj.conf`` file, enable the Arduino API:
104+
105+
.. code-block:: cfg
106+
107+
CONFIG_GPIO=y
108+
CONFIG_ARDUINO_API=y
109+
110+
#. Create your application using Arduino-style code:
111+
112+
.. code-block:: cpp
113+
114+
#include <Arduino.h>
115+
116+
void setup() {
117+
pinMode(LED_BUILTIN, OUTPUT);
118+
}
119+
120+
void loop() {
121+
digitalWrite(LED_BUILTIN, HIGH);
122+
delay(1000);
123+
digitalWrite(LED_BUILTIN, LOW);
124+
delay(1000);
125+
}
126+
127+
#. Build your application with the target board:
128+
129+
.. code-block:: bash
130+
131+
west build -b <board_name> path/to/your/app
132+
133+
Supported Boards
134+
================
135+
136+
The Arduino Core API module currently has variants for these boards:
137+
138+
* :zephyr:board:`arduino_mkrzero`
139+
* :zephyr:board:`arduino_nano_33_ble` (including Sense variant)
140+
* :zephyr:board:`arduino_nano_33_iot`
141+
* :zephyr:board:`beagleconnect_freedom`
142+
* :zephyr:board:`cc3220sf_launchxl`
143+
* :zephyr:board:`nrf52840dk`
144+
* :zephyr:board:`nrf9160dk`
145+
* :zephyr:board:`rpi_pico`
146+
147+
Adding Custom Board Support
148+
===========================
149+
150+
To add support for a custom board:
151+
152+
#. Create a new folder in the ``variants/`` directory with your board's name
153+
#. Add an overlay file and a pinmap header file that match the board name
154+
#. Add your new headerfile to an ``#ifdef`` statement in the ``variant.h`` file
155+
156+
For detailed instructions on adding board variants, refer to the `board variants documentation`_.
157+
158+
Using External Arduino Libraries
159+
================================
160+
161+
To use external Arduino libraries with your Zephyr project:
162+
163+
#. Add your library's source files (e.g., ``MyLibrary.h`` and ``MyLibrary.cpp``) to your project's ``src`` folder
164+
#. Update your application's ``CMakeLists.txt`` to include these files:
165+
166+
.. code-block:: cmake
167+
168+
target_sources(app PRIVATE src/MyLibrary.cpp)
169+
170+
#. Include the library in your source code:
171+
172+
.. code-block:: cpp
173+
174+
#include "MyLibrary.h"
175+
176+
For more details on using external libraries, see the `Arduino libraries documentation`_.
177+
178+
References
179+
**********
180+
181+
#. `Arduino-Core-Zephyr GitHub Repository`_
182+
#. `ArduinoCore-API Repository`_
183+
#. `Golioth Article: Zephyr + Arduino: a Google Summer of Code story`_
184+
185+
.. target-notes::
186+
187+
.. _Arduino Core API: https://github.com/zephyrproject-rtos/arduino-core-zephyr
188+
.. _board variants documentation: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/main/documentation/variants.md
189+
.. _Arduino libraries documentation: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/main/documentation/arduino_libs.md
190+
.. _Arduino-Core-Zephyr GitHub Repository: https://github.com/zephyrproject-rtos/arduino-core-zephyr
191+
.. _ArduinoCore-API Repository: https://github.com/arduino/ArduinoCore-API
192+
.. _Google Summer of Code 2022 project: https://dhruvag2000.github.io/Blog-GSoC22/
193+
.. _Golioth Article\: Zephyr + Arduino\: a Google Summer of Code story: https://blog.golioth.io/zephyr-arduino-a-google-summer-of-code-story/

0 commit comments

Comments
 (0)