From 70c7d46305dc8fb6c28ef596ae8450f0f38567b8 Mon Sep 17 00:00:00 2001 From: strawmanbobi Date: Thu, 30 Oct 2025 20:58:20 +0800 Subject: [PATCH] added arduino example --- arduino-example/.gitignore | 23 +++ arduino-example/.idea/.gitignore | 8 + arduino-example/.idea/editor.xml | 248 +++++++++++++++++++++++++++++++ arduino-example/.idea/misc.xml | 17 +++ arduino-example/.idea/vcs.xml | 6 + arduino-example/include/README | 37 +++++ arduino-example/lib/README | 46 ++++++ arduino-example/platformio.ini | 17 +++ arduino-example/src/configure.h | 11 ++ arduino-example/src/main.cpp | 77 ++++++++++ arduino-example/test/README | 11 ++ 11 files changed, 501 insertions(+) create mode 100644 arduino-example/.gitignore create mode 100644 arduino-example/.idea/.gitignore create mode 100644 arduino-example/.idea/editor.xml create mode 100644 arduino-example/.idea/misc.xml create mode 100644 arduino-example/.idea/vcs.xml create mode 100644 arduino-example/include/README create mode 100644 arduino-example/lib/README create mode 100644 arduino-example/platformio.ini create mode 100644 arduino-example/src/configure.h create mode 100644 arduino-example/src/main.cpp create mode 100644 arduino-example/test/README diff --git a/arduino-example/.gitignore b/arduino-example/.gitignore new file mode 100644 index 0000000..97f1e3e --- /dev/null +++ b/arduino-example/.gitignore @@ -0,0 +1,23 @@ +# PlatformIO Build Environments +.pio/ +.pioenvs/ + +# PlatformIO Library Dependencies +.piolibdeps/ + +# Clang Complete files (if used for IntelliSense) +.clang_complete +gcc-flags.json + +# VS Code specific files (if using VS Code) +.vscode/ + +# Other common ignored files +*.o +*.elf +*.bin +*.hex +*.map +*.lst +.DS_Store # macOS specific +Thumb.db # Windows specific diff --git a/arduino-example/.idea/.gitignore b/arduino-example/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/arduino-example/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/arduino-example/.idea/editor.xml b/arduino-example/.idea/editor.xml new file mode 100644 index 0000000..ead1d8a --- /dev/null +++ b/arduino-example/.idea/editor.xml @@ -0,0 +1,248 @@ + + + + + \ No newline at end of file diff --git a/arduino-example/.idea/misc.xml b/arduino-example/.idea/misc.xml new file mode 100644 index 0000000..d858eb1 --- /dev/null +++ b/arduino-example/.idea/misc.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/arduino-example/.idea/vcs.xml b/arduino-example/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/arduino-example/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/arduino-example/include/README b/arduino-example/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/arduino-example/include/README @@ -0,0 +1,37 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the convention is to give header files names that end with `.h'. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/arduino-example/lib/README b/arduino-example/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/arduino-example/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into the executable file. + +The source code of each library should be placed in a separate directory +("lib/your_library_name/[Code]"). + +For example, see the structure of the following example libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +Example contents of `src/main.c` using Foo and Bar: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +The PlatformIO Library Dependency Finder will find automatically dependent +libraries by scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/arduino-example/platformio.ini b/arduino-example/platformio.ini new file mode 100644 index 0000000..a4c293f --- /dev/null +++ b/arduino-example/platformio.ini @@ -0,0 +1,17 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:uno_r4_minima] +platform = renesas-ra +board = uno_r4_wifi +framework = arduino +monitor_speed = 115200 +lib_deps = + WiFiS3 \ No newline at end of file diff --git a/arduino-example/src/configure.h b/arduino-example/src/configure.h new file mode 100644 index 0000000..114f879 --- /dev/null +++ b/arduino-example/src/configure.h @@ -0,0 +1,11 @@ +// +// Created by strawmanbobi on 10/14/25. +// + +#ifndef ARDUINO_EXAMPLE_CONFIGURE_H +#define ARDUINO_EXAMPLE_CONFIGURE_H + +#define SECRET_SSID "Strawmanbobi" +#define SECRET_PASS "ghostcicy" + +#endif //ARDUINO_EXAMPLE_CONFIGURE_H \ No newline at end of file diff --git a/arduino-example/src/main.cpp b/arduino-example/src/main.cpp new file mode 100644 index 0000000..08ad99a --- /dev/null +++ b/arduino-example/src/main.cpp @@ -0,0 +1,77 @@ +// +// Created by strawmanbobi on 10/14/25. +// + +#include +#include // Library for the UNO R4 WiFi connectivity +#include "configure.h" // Your secret credentials file + +// --- Global Variables --- +// Read credentials from the secrets file +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; + +int status = WL_IDLE_STATUS; + +// --- Function to print connection details --- +void printWiFiStatus() { + // Print the SSID of the network you're attached to + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // Print the UNO R4's IP address + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // Print the received signal strength (RSSI) + long rssi = WiFi.RSSI(); + Serial.print("Signal Strength (RSSI): "); + Serial.print(rssi); + Serial.println(" dBm"); +} + +// ---------------------------------------------------------------------- +void setup() { + Serial.begin(115200); + while (!Serial); // Wait for serial port to connect + + Serial.println("--- Arduino UNO R4 WiFi: Station Mode ---"); + + // Set the board to Wi-Fi Station (client) mode + // The WiFiS3 library handles this mode implicitly with WiFi.begin() + + // Attempt to connect to the Wi-Fi network + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + + // Connect to the Wi-Fi network + // This is a blocking call that retries until a connection is made or times out + status = WiFi.begin(ssid, pass); + + if (status == WL_CONNECTED) { + // If connected successfully + Serial.println("\n✅ Connection Successful!"); + printWiFiStatus(); + } else { + // If connection failed + Serial.print("\n❌ Connection Failed! Status: "); + Serial.println(status); + } +} + +// ---------------------------------------------------------------------- +void loop() { + // Check WiFi status and attempt to reconnect if disconnected + if (WiFi.status() != WL_CONNECTED) { + Serial.print("Connection lost. Reconnecting..."); + status = WiFi.begin(ssid, pass); + if (status == WL_CONNECTED) { + Serial.println("Reconnected!"); + printWiFiStatus(); + } + } + + // Your main application logic goes here + delay(5000); +} \ No newline at end of file diff --git a/arduino-example/test/README b/arduino-example/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/arduino-example/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html