From 447ab20af628d1faca8de065e901df7bf98b5cb9 Mon Sep 17 00:00:00 2001 From: Dooho Yi Date: Sat, 8 Apr 2023 13:01:47 +0900 Subject: [PATCH] platformio --- .gitignore | 2 + arduino/rainboard/.gitignore | 1 + arduino/rainboard/.python-version | 1 + arduino/rainboard/include/README | 39 ++++++++++ arduino/rainboard/lib/README | 46 +++++++++++ arduino/rainboard/platformio.ini | 18 +++++ arduino/rainboard/src/rainboard.ino | 116 ++++++++++++++++++++++++++++ arduino/rainboard/test/README | 11 +++ 8 files changed, 234 insertions(+) create mode 100644 .gitignore create mode 100644 arduino/rainboard/.gitignore create mode 100644 arduino/rainboard/.python-version create mode 100644 arduino/rainboard/include/README create mode 100644 arduino/rainboard/lib/README create mode 100644 arduino/rainboard/platformio.ini create mode 100644 arduino/rainboard/src/rainboard.ino create mode 100644 arduino/rainboard/test/README diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f0fed7e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +*/.DS_Store diff --git a/arduino/rainboard/.gitignore b/arduino/rainboard/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/arduino/rainboard/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/arduino/rainboard/.python-version b/arduino/rainboard/.python-version new file mode 100644 index 0000000..7ce6d68 --- /dev/null +++ b/arduino/rainboard/.python-version @@ -0,0 +1 @@ +pio diff --git a/arduino/rainboard/include/README b/arduino/rainboard/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/arduino/rainboard/include/README @@ -0,0 +1,39 @@ + +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 usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +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/rainboard/lib/README b/arduino/rainboard/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/arduino/rainboard/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 executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, 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 + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/arduino/rainboard/platformio.ini b/arduino/rainboard/platformio.ini new file mode 100644 index 0000000..ee865d8 --- /dev/null +++ b/arduino/rainboard/platformio.ini @@ -0,0 +1,18 @@ +; 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:esp32-s2-saola-1] +platform = espressif32 +board = esp32-s2-saola-1 +framework = arduino +upload_speed = 460800 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 +lib_deps = + firmata/ConfigurableFirmata@^3.0.0 + Wire diff --git a/arduino/rainboard/src/rainboard.ino b/arduino/rainboard/src/rainboard.ino new file mode 100644 index 0000000..e86467e --- /dev/null +++ b/arduino/rainboard/src/rainboard.ino @@ -0,0 +1,116 @@ +#include +#include + +const char* ssid = "TEEPOT"; +const char* password = "3333388888"; +const int NETWORK_PORT = 27016; + +//// A UDP instance to let us send and receive packets over UDP +//WiFiUDP Udp; +//const IPAddress outIp(192,168,43,13); // remote IP (not needed for receive) +//const unsigned int outPort = 9999; // remote port (not needed for receive) +//const unsigned int localPort = 8888; // local port to listen for UDP packets (here's where we send the packets) + + +#include +#include "utility/WiFiClientStream.h" +#include "utility/WiFiServerStream.h" +WiFiServerStream serverStream(NETWORK_PORT); + +std::vector pins = {16, 15, 17, 18, 20, 19, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33}; //16 +//2 ==> flipping autonomously 1/0 without grounding! (maybe grounded by something else???) +//1, 3, 4, 5, 6, 7, 8, ==> flipping 1/0 ... while grounded manually. + +//i have a feeling ... this relates to 'touch sensing'... this precise flipping might be from cap. charge/discharge cycles? + +void setup() +{ + //pinmodes + for (int idx = 0; idx < pins.size(); idx++) { + pinMode(pins[idx], INPUT_PULLUP); + } + + //serial + Serial.begin(115200); + + //wifi + WiFi.mode(WIFI_STA); + // Connect to WiFi network + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + Serial.println(""); + + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + //firmata + Firmata.disableBlinkVersion(); + Firmata.begin(serverStream); + +// Firmata.begin(115200); +// Firmata.setFirmwareNameAndVersion("ConfigurableFirmata", FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); +} + +void loop() +{ + for (int idx = 0; idx < pins.size(); idx++) { + Firmata.sendAnalog(idx, digitalRead(pins[idx])*1023); + } + + serverStream.maintain(); +} + + +// [NOTE] +// because firmata analog way has limits of max. channels <= 16. you can use digital way.. like below. +// but this not yet confirmed whether it is working or not. +// + +// #include + +// int pins_port0[8] = {17, 18, 2, 3, 4, 5, 6, 7}; +// int pins_port1[8] = {8, 9, 10, 11, 12, 24, 25, 26}; +// int pins_port2[8] = {27, 28, 29, 30, 31, 32, 33, 33}; + +// void setup() +// { +// for (int idx = 0; idx < 8; idx++) pinMode(pins_port0[idx], INPUT_PULLUP); +// for (int idx = 0; idx < 8; idx++) pinMode(pins_port1[idx], INPUT_PULLUP); +// for (int idx = 0; idx < 8; idx++) pinMode(pins_port2[idx], INPUT_PULLUP); + +// Firmata.setFirmwareNameAndVersion("ConfigurableFirmata", FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); +// Firmata.begin(115200); +// } + +// void loop() +// { +// byte port = 0; + +// static byte port0_prev = 0; +// port = 0x00; +// for (int idx = 0; idx < 8; idx++) port |= (digitalRead(pins_port0[idx]) ? 0x01<