add wired(serial) support

This commit is contained in:
Dooho Yi 2023-05-23 15:53:24 +09:00
parent 0b399861dc
commit 4a384dc801
3 changed files with 144 additions and 32 deletions

View file

@ -1,14 +1,17 @@
//
// ringringrain - WIFI part. (esp8266)
// configurablefirmata_esp8266
//
// D. Yi @ 2023 5 5
// D. Yi @ 2023 5 23
//
#define WIRELESS
#if defined(WIRELESS)
//wi-fi
#include <ESP8266WiFi.h>
////network!
const char* ssid = "esp0";
//network!
const char* ssid = "esp1";
const char* password = "1111100000";
const int NETWORK_PORT = 27016;
// IPAddress local_IP(192, 168, 137, 111);
@ -32,15 +35,18 @@ void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
WiFi.begin(ssid, password);
digitalWrite(2, LOW);
}
#endif
//firmata over wi-fi
#include <ConfigurableFirmata.h>
#if defined(WIRELESS)
#include "utility/WiFiClientStream.h"
#include "utility/WiFiServerStream.h"
WiFiServerStream serverStream(NETWORK_PORT);
//firmware update over the air
#include <ArduinoOTA.h>
#endif
//handle digitalWrite
byte previousPORT[TOTAL_PORTS];
@ -75,16 +81,21 @@ void setup()
//digital outputs
pinMode(D4, OUTPUT); //build-in LED && also used as wifi indicator!
#if defined(WIRELESS)
digitalWrite(D4, LOW); //LOW ==> LED ON ==> 'wifi. disconnected.'
#else
digitalWrite(D4, HIGH); //HIGH ==> LED OFF
#endif
//serial (for debug & info)
Serial.begin(115200);
Serial.begin(57600);
#if defined(WIRELESS)
//wifi
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
WiFi.mode(WIFI_STA);
// Connect to WiFi network
//Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
@ -98,12 +109,18 @@ void setup()
delay(500);
}
Serial.println("");
#endif
//firmata
Firmata.disableBlinkVersion();
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
#if defined(WIRELESS)
Firmata.begin(serverStream);
#else
Firmata.begin(Serial);
#endif
#if defined(WIRELESS)
//ota
ArduinoOTA.onStart([]() {
Serial.println("Start");
@ -123,6 +140,7 @@ void setup()
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
#endif
}
void loop()
@ -172,11 +190,13 @@ void loop()
Firmata.processInput();
}
#if defined(WIRELESS)
//firmata over wi-fi
serverStream.maintain();
//
ArduinoOTA.handle();
#endif
//for wdt
yield();

92
pd/arduino-serial-test.pd Normal file
View file

@ -0,0 +1,92 @@
#N canvas 492 30 602 584 12;
#X obj 25 349 route digital analog;
#X obj 25 63 tgl 20 0 empty empty LED\ ON/OFF 0 -10 0 12 #7c7c7c #ffffff #000000 0 1;
#X msg 25 137 digital 2 \$1;
#X obj 356 389 vsl 20 170 0 1 0 0 empty empty analog0 10 -9 0 12 #e3c6ff #000000 #000000 0 1;
#X floatatom 356 338 5 0 0 0 - - - 0;
#X obj 356 313 route 0;
#X obj 25 88 == 0;
#X floatatom 25 113 5 0 0 0 - - - 0;
#X text 97 112 D4 == GPIO2;
#X obj 25 470 route 1 2 3 5 6 7, f 25;
#X obj 25 508 tgl 20 0 empty empty D1 0 30 0 12 #ffc7c6 #000000 #000000 0 1;
#X obj 53 508 tgl 20 0 empty empty D2 0 30 0 12 #ffe3c6 #000000 #000000 0 1;
#X obj 82 508 tgl 20 0 empty empty D3 0 30 0 12 #feffc6 #000000 #000000 0 1;
#X obj 111 508 tgl 20 0 empty empty D5 0 30 0 12 #c6ffc7 #000000 #000000 0 1;
#X obj 139 508 tgl 20 0 empty empty D6 0 30 0 12 #c6feff #000000 #000000 0 1;
#X obj 168 508 tgl 20 0 empty empty D7 0 30 0 12 #c7c6ff #000000 #000000 0 1;
#X text 74 15 ==== digital OUTPUT ===;
#X text 74 415 ==== digital INPUT ===;
#X text 305 287 ==== analog INPUT ===;
#N canvas 836 419 450 201 scope 0;
#N canvas 0 50 450 250 (subpatch) 0;
#X array scope 200 float 0;
#X coords 0 1.5 200 -0.5 200 140 1 0 0;
#X restore 26 29 graph;
#X obj 367 76 f;
#X obj 403 76 + 1;
#X obj 272 56 t a b;
#X floatatom 367 126 5 0 0 0 - - - 0;
#X obj 272 150 tabwrite scope;
#X obj 367 101 mod 200;
#X obj 272 31 inlet;
#X connect 1 0 2 0;
#X connect 1 0 6 0;
#X connect 2 0 1 1;
#X connect 3 0 5 0;
#X connect 3 1 1 0;
#X connect 4 0 5 1;
#X connect 6 0 4 0;
#X connect 7 0 3 0;
#X restore 435 439 pd scope;
#N canvas 0 0 361 269 net 0;
#X obj 28 88 route 1;
#X floatatom 28 138 5 0 0 0 - - - 0;
#X obj 28 113 * 1023;
#X obj 28 162 bng 20 250 50 0 empty empty live! 0 30 0 12 #fcfcfc #000000 #000000;
#X text 84 20 ==== network STATUS ===;
#X obj 28 58 inlet;
#X obj 101 138 del;
#X msg 101 113 stop \, 2000;
#X obj 28 217 outlet;
#X obj 101 217 outlet;
#X connect 0 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 1 0;
#X connect 3 0 7 0;
#X connect 3 0 8 0;
#X connect 5 0 0 0;
#X connect 6 0 9 0;
#X connect 7 0 6 0;
#X restore 381 190 pd net;
#X obj 381 215 bng 20 250 50 0 empty empty (online) 0 30 0 12 #fcfcfc #000000 #000000;
#X text 380 169 connection monitoring;
#X obj 460 215 bng 20 250 50 0 empty empty disconnected! 0 30 0 12 #fcfcfc #000000 #000000;
#X obj 510 206 print X!;
#X obj 25 238 arduino;
#X msg 48 196 devices;
#X msg 38 172 devicename COM4;
#X msg 124 202 close;
#X connect 0 0 9 0;
#X connect 0 1 5 0;
#X connect 0 1 20 0;
#X connect 1 0 6 0;
#X connect 2 0 25 0;
#X connect 3 0 19 0;
#X connect 4 0 3 0;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X connect 9 0 10 0;
#X connect 9 1 11 0;
#X connect 9 2 12 0;
#X connect 9 3 13 0;
#X connect 9 4 14 0;
#X connect 9 5 15 0;
#X connect 20 0 21 0;
#X connect 20 1 23 0;
#X connect 23 0 24 0;
#X connect 25 0 0 0;
#X connect 26 0 25 0;
#X connect 27 0 25 0;
#X connect 28 0 25 0;

View file

@ -1,7 +1,6 @@
#N canvas 221 33 602 588 12;
#X msg 154 238 disconnect;
#X obj 381 39 bng 20 250 50 0 empty empty search\ &&\ connect 0 -10 0 12 #fcfcfc #000000 #000000;
#X msg 106 193 connect 192.168.43.250 27016;
#N canvas 0 0 489 532 arduino 0;
#X obj 19 77 zconf.browse;
#X obj 19 290 zconf.resolve;
@ -122,29 +121,30 @@
#X text 380 169 connection monitoring;
#X obj 460 215 bng 20 250 50 0 empty empty disconnected! 0 30 0 12 #fcfcfc #000000 #000000;
#X obj 510 206 print X!;
#X connect 0 0 4 1;
#X connect 1 0 3 0;
#X connect 2 0 4 1;
#X connect 3 0 2 0;
#X connect 4 0 7 0;
#X connect 4 1 5 0;
#X connect 5 0 6 0;
#X connect 7 0 16 0;
#X connect 7 1 12 0;
#X connect 7 1 27 0;
#X connect 8 0 13 0;
#X connect 9 0 4 0;
#X connect 10 0 26 0;
#X msg 106 193 connect 192.168.137.52 27016;
#X connect 0 0 3 1;
#X connect 1 0 2 0;
#X connect 2 0 31 0;
#X connect 3 0 6 0;
#X connect 3 1 4 0;
#X connect 4 0 5 0;
#X connect 6 0 15 0;
#X connect 6 1 11 0;
#X connect 6 1 26 0;
#X connect 7 0 12 0;
#X connect 8 0 3 0;
#X connect 9 0 25 0;
#X connect 10 0 9 0;
#X connect 11 0 10 0;
#X connect 12 0 11 0;
#X connect 13 0 14 0;
#X connect 14 0 9 0;
#X connect 16 0 17 0;
#X connect 16 1 18 0;
#X connect 16 2 19 0;
#X connect 16 3 20 0;
#X connect 16 4 21 0;
#X connect 16 5 22 0;
#X connect 27 0 28 0;
#X connect 27 1 30 0;
#X connect 30 0 31 0;
#X connect 12 0 13 0;
#X connect 13 0 8 0;
#X connect 15 0 16 0;
#X connect 15 1 17 0;
#X connect 15 2 18 0;
#X connect 15 3 19 0;
#X connect 15 4 20 0;
#X connect 15 5 21 0;
#X connect 26 0 27 0;
#X connect 26 1 29 0;
#X connect 29 0 30 0;
#X connect 31 0 3 1;