Skip to content

Commit f9898d9

Browse files
committed
samples: Added serial_event sample
Add a sample to demonstrate how to use Serial APIs
1 parent d23ca8f commit f9898d9

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

samples/serial_event/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay)
6+
7+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
8+
project(serial_event)
9+
10+
target_sources(app PRIVATE src/app.cpp)
11+
12+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)

samples/serial_event/README.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _serial_event:
2+
3+
Serial Event
4+
############
5+
6+
Overview
7+
********
8+
9+
The serial_event sample echo back serial input data.
10+
11+
Building and Running
12+
********************
13+
14+
Build and flash serial_event sample as follows,
15+
16+
```sh
17+
$> west build -p -b arduino_nano_33_ble sample/serial_event/
18+
19+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
20+
```

samples/serial_event/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ARDUINO_API=y

samples/serial_event/src/app.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2022 TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <Arduino.h>
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
}
12+
13+
void loop() {
14+
}
15+
16+
void serialEvent() {
17+
while(Serial.available()) {
18+
Serial.print((char)Serial.read());
19+
}
20+
}

0 commit comments

Comments
 (0)