Skip to content

Commit fa44ab3

Browse files
committed
arduino_core_samples
1 parent c53a577 commit fa44ab3

File tree

40 files changed

+900
-0
lines changed

40 files changed

+900
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
# get value of NORMALIZED_BOARD_TARGET early
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS yaml boards)
7+
8+
set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}.overlay)
9+
10+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
11+
project(analog_input)
12+
13+
target_sources(app PRIVATE src/main.cpp)
14+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _analog_input:
2+
3+
Analog Input
4+
############
5+
6+
Overview
7+
********
8+
9+
The analog_input sample blinks the LED with control of the period
10+
by the voltage of the input pin.
11+
Inputting high voltage to blink the LED slowly.
12+
Blink the LED fast on input voltage is low.
13+
When the input is 0V, LED light.
14+
15+
Building and Running
16+
********************
17+
18+
Build and flash analog_input sample as follows,
19+
20+
```sh
21+
$> west build -p -b arduino_nano_33_ble sample/analog_input/
22+
23+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
24+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ADC=y
2+
CONFIG_ARDUINO_API=y
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <Arduino.h>
8+
9+
const int analog_input = A0; // select the input pin for the potentiometer
10+
const int ledPin = LED_BUILTIN; // select the pin for the LED
11+
const float wait_factor = 1.f;
12+
13+
void setup() {
14+
pinMode(ledPin, OUTPUT);
15+
}
16+
17+
void loop() {
18+
int value = 0;
19+
20+
value = analogRead(analog_input);
21+
22+
/* Blinks slowly when the input voltage is high */
23+
24+
digitalWrite(ledPin, HIGH);
25+
delay(value * wait_factor);
26+
27+
digitalWrite(ledPin, LOW);
28+
delay(value * wait_factor);
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
# get value of NORMALIZED_BOARD_TARGET early
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS yaml boards)
7+
8+
set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}.overlay)
9+
10+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
11+
project(attach_interrupt)
12+
13+
target_sources(app PRIVATE src/main.cpp)
14+
15+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. _attach_interrupt-sample:
2+
3+
AttachInterrupt
4+
######
5+
6+
Overview
7+
********
8+
9+
This sample demonstrates how to use attachInterrupt API.
10+
11+
Building and Running
12+
********************
13+
14+
Build and flash attachInterrupt sample as follows,
15+
16+
```sh
17+
$> west build -p -b arduino_nano_33_ble samples/basic/attach_interrupt/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr
18+
19+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
20+
```
21+
22+
Turn on the LED by detecting interrupts. And Turn off the next interrupt.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ARDUINO_API=y
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2022 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <Arduino.h>
8+
9+
const pin_size_t ledPin = LED_BUILTIN;
10+
const pin_size_t interruptPin = 2;
11+
PinStatus state = LOW;
12+
13+
void blink() {
14+
state = (state == LOW) ? HIGH : LOW;
15+
digitalWrite(ledPin, state);
16+
}
17+
18+
void setup() {
19+
pinMode(ledPin, OUTPUT);
20+
pinMode(interruptPin, INPUT_PULLUP);
21+
attachInterrupt(interruptPin, blink, CHANGE);
22+
}
23+
24+
void loop() {
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
# get value of NORMALIZED_BOARD_TARGET early
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS yaml boards)
7+
8+
set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}.overlay)
9+
10+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
11+
project(blinky)
12+
13+
target_sources(app PRIVATE src/main.cpp)
14+
15+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.. _blinky-sample:
2+
3+
Blinky
4+
######
5+
6+
Overview
7+
********
8+
9+
This Arduino Blinky sample blinks an LED forever using the `ArduinoAPI`.
10+
11+
Requirements
12+
************
13+
14+
Your board must:
15+
16+
#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of
17+
Zephyr's :ref:`boards`).
18+
#. Have the LED configured using the ``led0`` devicetree alias.
19+
20+
Building and Running
21+
********************
22+
23+
Build and flash Blinky as follows,
24+
25+
```sh
26+
$> west build -p -b arduino_nano_33_ble samples/basic/arduino-blinky/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr
27+
28+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
29+
```
30+
31+
After flashing, the LED starts to blink. If a runtime error occurs, the sample
32+
exits without printing to the console.
33+
34+
Adding board support
35+
********************
36+
37+
To add support for your board, add something like this to your devicetree:
38+
39+
.. code-block:: DTS
40+
41+
/ {
42+
aliases {
43+
led0 = &myled0;
44+
};
45+
46+
leds {
47+
compatible = "gpio-leds";
48+
myled0: led_0 {
49+
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>;
50+
};
51+
};
52+
};
53+
54+
The above sets your board's ``led0`` alias to use pin 13 on GPIO controller
55+
``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when
56+
the pin is set to its high state, and off when the pin is in its low state.
57+
58+
Tips:
59+
60+
- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs
61+
in devicetree.
62+
63+
- If you're not sure what to do, check the devicetrees for supported boards which
64+
use the same SoC as your target. See :ref:`get-devicetree-outputs` for details.
65+
66+
- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use
67+
in devicetree.
68+
69+
- If the LED is built in to your board hardware, the alias should be defined in
70+
your :ref:`BOARD.dts file <devicetree-in-out-files>`. Otherwise, you can
71+
define one in a :ref:`devicetree overlay <set-devicetree-overlays>`.

0 commit comments

Comments
 (0)