platformio

This commit is contained in:
Dooho Yi 2023-04-08 13:01:47 +09:00
parent 633af1071f
commit 447ab20af6
8 changed files with 234 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.DS_Store
*/.DS_Store

1
arduino/rainboard/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.pio

View file

@ -0,0 +1 @@
pio

View file

@ -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

View file

@ -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 <Foo.h>
#include <Bar.h>
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

View file

@ -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

View file

@ -0,0 +1,116 @@
#include <ConfigurableFirmata.h>
#include <vector>
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 <WiFi.h>
#include "utility/WiFiClientStream.h"
#include "utility/WiFiServerStream.h"
WiFiServerStream serverStream(NETWORK_PORT);
std::vector<int> 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 <ConfigurableFirmata.h>
// 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<<idx : 0x00);
// if (port0_prev != port) Firmata.sendDigitalPort(0, port);
// port0_prev = port;
// static byte port1_prev = 0;
// port = 0x00;
// for (int idx = 0; idx < 8; idx++) port |= (digitalRead(pins_port1[idx]) ? 0x01<<idx : 0x00);
// if (port1_prev != port) Firmata.sendDigitalPort(1, port);
// port1_prev = port;
// static byte port2_prev = 0;
// port = 0x00;
// for (int idx = 0; idx < 8; idx++) port |= (digitalRead(pins_port2[idx]) ? 0x01<<idx : 0x00);
// if (port2_prev != port) Firmata.sendDigitalPort(2, port);
// port2_prev = port;
// delay(20);
// }

View file

@ -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