@sampler revised. preserve I2C i/f + esp now enabled
This commit is contained in:
parent
774865b639
commit
86432d1cc4
7 changed files with 1085 additions and 544 deletions
45
@postman/platformio.ini
Normal file
45
@postman/platformio.ini
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
; < NOTE >
|
||||
|
||||
; to enable verbose output add option -->
|
||||
; $ platformio run --verbose
|
||||
|
||||
; to make this permanent for the proj. -->
|
||||
; $ platformio settings set force_verbose Yes
|
||||
|
||||
; then confirm the change -->
|
||||
; $ platformio settings get
|
||||
|
||||
|
||||
; // pio v 4.0 'Build options'
|
||||
; - build_type
|
||||
; - build_flags
|
||||
; - src_build_flags
|
||||
; - build_unflags
|
||||
; - src_filter
|
||||
; - targets
|
||||
|
||||
|
||||
[platformio]
|
||||
default_envs = d1_mini_pro
|
||||
|
||||
[env]
|
||||
framework = arduino
|
||||
upload_port = /dev/ttyUSB0
|
||||
lib_deps =
|
||||
; SPI
|
||||
; Wire
|
||||
721 ; TaskScheduler
|
||||
|
||||
[env:nodemcuv2]
|
||||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
upload_speed = 921600 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
|
||||
|
||||
[env:d1_mini_pro]
|
||||
platform = espressif8266
|
||||
board = d1_mini_pro
|
||||
lib_deps =
|
||||
${env.lib_deps}
|
||||
upload_speed = 460800 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
|
||||
400
@postman/src/main.cpp
Normal file
400
@postman/src/main.cpp
Normal file
|
|
@ -0,0 +1,400 @@
|
|||
//
|
||||
// wirelessly connected cloud (based on ESP-NOW, a kind of LPWAN?)
|
||||
//
|
||||
|
||||
//
|
||||
// Conversation about the ROOT @ SEMA warehouses, Seoul
|
||||
//
|
||||
|
||||
//
|
||||
// 2021 02 15
|
||||
//
|
||||
// (part-1) esp8266 : 'postman' (the esp-now network nodes)
|
||||
//
|
||||
// this module will be an esp-now node in a group.
|
||||
// like, a bird in a group of birds.
|
||||
//
|
||||
// esp-now @ esp8266 DO support broadcast address (FF:FF:FF:FF:FF:FF)
|
||||
// w/ NONOS-SDK of espressif
|
||||
// and you can enable that w/ Platformio, applying some special build flags.
|
||||
// --> https://github.com/esp8266/Arduino/issues/6174#issuecomment-509115454
|
||||
// (yet, w/ Arduino, this is not available yet.)
|
||||
//
|
||||
// so, at first, we will simply/stably go w/o broadcasting.
|
||||
// and, if broadcast is really needed we can activate (@Platformio)
|
||||
//
|
||||
|
||||
|
||||
// then, let is save a value in EEPROM (object with memory)
|
||||
// no broadcast for now. if needed we can achieve that too.
|
||||
|
||||
|
||||
|
||||
//==========<configurations>===========
|
||||
//
|
||||
// 'HAVE_CLIENT'
|
||||
// --> i have a client. enable the client task.
|
||||
//
|
||||
// 'SERIAL_SWAP'
|
||||
// --> UART pin swapped.
|
||||
// you want this, when you want a bi-directional comm. to external client boards (e.g. teensy).
|
||||
//
|
||||
// 'DISABLE_AP'
|
||||
// --> (questioning)...
|
||||
//
|
||||
// 'HAVE_CLIENT_I2C'
|
||||
// --> i have a client w/ I2C i/f. enable the I2C client task.
|
||||
//
|
||||
//==========</configurations>==========
|
||||
|
||||
//==========<preset>===========
|
||||
//
|
||||
// (1) standalone
|
||||
#if 0
|
||||
// (2) osc client (the ROOT)
|
||||
#elif 0
|
||||
#define SERIAL_SWAP
|
||||
#define HAVE_CLIENT
|
||||
// (3) sampler client
|
||||
#elif 1
|
||||
#define HAVE_CLIENT_I2C
|
||||
#define DISABLE_AP
|
||||
//
|
||||
#endif
|
||||
//
|
||||
//==========</preset>==========
|
||||
|
||||
//============<parameters>============
|
||||
//
|
||||
#define MY_BOOK ("root")
|
||||
// #define MY_BOOK ("friend")
|
||||
// #define MY_BOOK ("sampler")
|
||||
//
|
||||
#define PEER_COUNT_MAX (20)
|
||||
//
|
||||
#define LED_PERIOD (11111)
|
||||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
// --> sometimes, the 'Serial' is in use (for example, 'osc' node)
|
||||
// then, use 'Serial1' - D4/GPIO2/TDX1 @ nodemcu (this is TX only.)
|
||||
//
|
||||
// --> otherwise, MONITORING_SERIAL == Serial.
|
||||
//
|
||||
#if defined(SERIAL_SWAP)
|
||||
#define MONITORING_SERIAL (Serial1)
|
||||
#else
|
||||
#define MONITORING_SERIAL (Serial)
|
||||
#endif
|
||||
//
|
||||
//============</parameters>===========
|
||||
|
||||
//============<board-specifics>============
|
||||
#if defined(ARDUINO_FEATHER_ESP32) // featheresp32
|
||||
#define LED_PIN 13
|
||||
#else
|
||||
#define LED_PIN 2
|
||||
#endif
|
||||
//============</board-specifics>===========
|
||||
|
||||
//arduino
|
||||
#include <Arduino.h>
|
||||
|
||||
//i2c
|
||||
#include <Wire.h>
|
||||
|
||||
//post & addresses
|
||||
#include "../../post.h"
|
||||
AddressLibrary library;
|
||||
|
||||
//espnow
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <espnow.h>
|
||||
|
||||
// on 'sent'
|
||||
void onDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||
if (sendStatus != 0) MONITORING_SERIAL.println("Delivery failed!");
|
||||
}
|
||||
|
||||
// on 'receive'
|
||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||
|
||||
//
|
||||
//MONITORING_SERIAL.write(incomingData, len);
|
||||
|
||||
//
|
||||
#if defined(HAVE_CLIENT)
|
||||
Serial.write(incomingData, len); // we pass it over to the client.
|
||||
#endif
|
||||
|
||||
// open => identify => use.
|
||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||
Note note;
|
||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||
//
|
||||
MONITORING_SERIAL.println(note.to_string());
|
||||
//
|
||||
|
||||
#if defined(HAVE_CLIENT_I2C)
|
||||
|
||||
// (struct --> obsolete I2C format.)
|
||||
// --> we want to open & re-construct the msg.
|
||||
|
||||
// letter frame ( '[' + 30 bytes + ']' )
|
||||
// : [123456789012345678901234567890]
|
||||
|
||||
// 'MIDI' letter frame
|
||||
// : [123456789012345678901234567890]
|
||||
// : [KKKVVVG.......................]
|
||||
// : KKK - Key
|
||||
// .substring(1, 4);
|
||||
// : VVV - Velocity (volume/amp.)
|
||||
// .substring(4, 7);
|
||||
// : G - Gate (note on/off)
|
||||
// .substring(7, 8);
|
||||
|
||||
char letter_outro[POST_BUFF_LEN] = "................................";
|
||||
sprintf(letter_outro, "[%03d%03d%01d.......................]",
|
||||
(int32_t)note.pitch,
|
||||
(int32_t)note.velocity,
|
||||
(int32_t)note.onoff);
|
||||
String msg = String(letter_outro);
|
||||
|
||||
// truncate any extra. letters.
|
||||
msg = msg.substring(0, POST_LENGTH); // (0) ~ (POST_LENGTH-1)
|
||||
|
||||
// send out
|
||||
Wire.beginTransmission(I2C_ADDR);
|
||||
Wire.write(msg.c_str(), POST_LENGTH);
|
||||
Wire.endTransmission();
|
||||
|
||||
#endif
|
||||
|
||||
//-*-*-*-*-*-*-*-*-*-
|
||||
// use 'note' here...
|
||||
// ==> N.B.: "callback function runs from a high-priority Wi-Fi task.
|
||||
// So, do not do lengthy operations in the callback function.
|
||||
// Instead, post the necessary data to a queue and handle it from a lower priority task."
|
||||
//-*-*-*-*-*-*-*-*-*-
|
||||
}
|
||||
}
|
||||
|
||||
//task
|
||||
#include <TaskScheduler.h>
|
||||
Scheduler runner;
|
||||
|
||||
//task #0 : blink led
|
||||
extern Task blink_task;
|
||||
void blink() {
|
||||
//
|
||||
static int count = 0;
|
||||
count++;
|
||||
//
|
||||
switch (count % 4) {
|
||||
case 0:
|
||||
digitalWrite(LED_PIN, LOW); // first ON
|
||||
blink_task.delay(LED_ONTIME);
|
||||
break;
|
||||
case 1:
|
||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||
blink_task.delay(LED_GAPTIME);
|
||||
break;
|
||||
case 2:
|
||||
digitalWrite(LED_PIN, LOW); // second ON
|
||||
blink_task.delay(LED_ONTIME);
|
||||
break;
|
||||
case 3:
|
||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
||||
|
||||
//task #1 : regular post collection
|
||||
#if defined(HAVE_CLIENT)
|
||||
void collect_post() {
|
||||
//
|
||||
//postman (serial comm.)
|
||||
static bool insync = false;
|
||||
if (insync == false) {
|
||||
while (Serial.available() > 0) {
|
||||
// search the last byte
|
||||
char last = Serial.read();
|
||||
// expectable last of the messages
|
||||
if (last == ']' || last == '}') {
|
||||
insync = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//
|
||||
if (Serial.available() > 0) {
|
||||
//
|
||||
char type = Serial.peek();
|
||||
//
|
||||
if (type == '[') {
|
||||
//expecting a Note message.
|
||||
uint8_t frm_size = sizeof(Note) + 2;
|
||||
//
|
||||
if (Serial.available() >= frm_size) {
|
||||
//
|
||||
uint8_t frm[frm_size];
|
||||
//
|
||||
Serial.readBytes(frm, frm_size);
|
||||
char first = frm[0];
|
||||
char last = frm[frm_size - 1];
|
||||
if (first == '[' && last == ']') {
|
||||
//
|
||||
//good. ==> ok, post it.
|
||||
//
|
||||
//pseudo-broadcast using peer-list!
|
||||
//
|
||||
esp_now_send(NULL, frm, frm_size);
|
||||
//
|
||||
MONITORING_SERIAL.write(frm, frm_size);
|
||||
MONITORING_SERIAL.print(" ==(esp_now_send/0)==> ");
|
||||
//
|
||||
} else {
|
||||
insync = false; //error!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Task collect_post_task(1, TASK_FOREVER, &collect_post, &runner, true); // by default, ENABLED
|
||||
#endif
|
||||
|
||||
//
|
||||
void setup() {
|
||||
|
||||
//led
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
//serial
|
||||
Serial.begin(115200);
|
||||
delay(100);
|
||||
|
||||
//info
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
Serial.println("\"hi, i m your postman.\"");
|
||||
Serial.println("-");
|
||||
Serial.println("- * info >>>");
|
||||
Serial.println("- mac address: " + WiFi.macAddress());
|
||||
Serial.println("- wifi channel: " + String(WIFI_CHANNEL));
|
||||
Serial.println("-");
|
||||
Serial.println("- * conf >>>");
|
||||
#if defined(HAVE_CLIENT)
|
||||
Serial.println("- ======== 'HAVE_CLIENT' ========");
|
||||
#endif
|
||||
#if defined(SERIAL_SWAP)
|
||||
Serial.println("- ======== 'SERIAL_SWAP' ========");
|
||||
#endif
|
||||
#if defined(DISABLE_AP)
|
||||
Serial.println("- ======== 'DISABLE_AP' ========");
|
||||
#endif
|
||||
#if defined(HAVE_CLIENT_I2C)
|
||||
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
|
||||
#endif
|
||||
Serial.println("-");
|
||||
Serial.println("- * address library >>>");
|
||||
for (uint32_t j = 0; j < library.lib.size(); j++) {
|
||||
Serial.println("-");
|
||||
Serial.println("- * (" + String(j + 1) + ") - \"" + library.lib[j].title + "\" >>>");
|
||||
Serial.println("-");
|
||||
for (uint32_t i = 0; i < library.lib[j].list.size(); i++) {
|
||||
Serial.println("- " + library.lib[j].list[i].to_string());
|
||||
}
|
||||
}
|
||||
Serial.println("-");
|
||||
Serial.println("\".-.-.-. :)\"");
|
||||
Serial.println();
|
||||
|
||||
//wifi
|
||||
WiFiMode_t node_type = WIFI_AP_STA;
|
||||
#if defined(DISABLE_AP)
|
||||
system_phy_set_max_tpw(0);
|
||||
node_type = WIFI_STA;
|
||||
#endif
|
||||
WiFi.mode(node_type);
|
||||
|
||||
//esp-now
|
||||
if (esp_now_init() != 0) {
|
||||
Serial.println("Error initializing ESP-NOW");
|
||||
return;
|
||||
}
|
||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||
esp_now_register_send_cb(onDataSent);
|
||||
esp_now_register_recv_cb(onDataReceive);
|
||||
|
||||
//
|
||||
AddressBook* members = library.getBookByTitle(MY_BOOK);
|
||||
Serial.println("! registering peers in the book titled: \"" + String(MY_BOOK) + "\"");
|
||||
|
||||
//
|
||||
if (members == NULL) {
|
||||
//oh, no such book!
|
||||
Serial.println("---- :( oh, no such book! ===> " + String(MY_BOOK));
|
||||
Serial.println(" .... no peer will be registered. come back with different 'title' !");
|
||||
} else {
|
||||
Serial.println("---- :) oki-doki, found it!");
|
||||
Serial.println();
|
||||
//
|
||||
for (uint32_t i = 0; i < members->list.size(); i++) {
|
||||
if (i >= PEER_COUNT_MAX) {
|
||||
Serial.println("(!) @@@@ Hey, no more free-slot. @@@@ ==> " + members->list[i].to_string() + " ==> IGNORED :(");
|
||||
} else {
|
||||
//some decoration?
|
||||
Serial.print("" + String((i + 1)%10) + "_ ");
|
||||
for (uint32_t k = 0; k < i; k++) Serial.print(" ");
|
||||
//
|
||||
Serial.println("~~>> 'esp_now_add_peer' with ... " + members->list[i].to_string());
|
||||
esp_now_add_peer(members->list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a
|
||||
//
|
||||
// int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len)
|
||||
// - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf
|
||||
//
|
||||
// "Channel does not affect any function, but only stores the channel information
|
||||
// for the application layer. The value is defined by the application layer. For
|
||||
// example, 0 means that the channel is not defined; 1 ~ 14 mean valid
|
||||
// channels; all the rest values can be assigned functions that are specified
|
||||
// by the application layer."
|
||||
// - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf
|
||||
}
|
||||
}
|
||||
}
|
||||
Serial.println("-");
|
||||
Serial.println("\".-.-.-. :)\"");
|
||||
Serial.println();
|
||||
|
||||
#if defined(SERIAL_SWAP)
|
||||
Serial.println("- ======== 'SERIAL_SWAP' ========");
|
||||
// a proper say goodbye.
|
||||
Serial.println("\"bye, i will do 'swap' in 1 second. find me on alternative pins!\"");
|
||||
Serial.println("\" hint: osc wiring ==> esp8266(serial.swap) <-> teensy(serial3)\"");
|
||||
Serial.println("-");
|
||||
Serial.println("\".-.-.-. :)\"");
|
||||
delay(1000); // flush out unsent serial messages.
|
||||
|
||||
// moving...
|
||||
Serial.swap(); // use RXD2/TXD2 pins, afterwards.
|
||||
delay(100); // wait re-initialization of the 'Serial'
|
||||
#endif
|
||||
|
||||
//
|
||||
#if defined(HAVE_CLIENT_I2C)
|
||||
//i2c master
|
||||
Wire.begin();
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
//
|
||||
runner.execute();
|
||||
//
|
||||
}
|
||||
|
|
@ -14,8 +14,9 @@ default_envs = teensy35
|
|||
[common]
|
||||
lib_ignore = Audio, SD
|
||||
lib_deps =
|
||||
721@3.0.2 ; TaskScheduler
|
||||
322@1.0.7 ; SdFat
|
||||
721 ; TaskScheduler
|
||||
SPI
|
||||
; 322@1.0.7 ; SdFat
|
||||
|
||||
[env:teensy35]
|
||||
platform = teensy@3.6.0
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
//
|
||||
// wirelessly connected cloud (Wireless Mesh Networking)
|
||||
// MIDI-like
|
||||
// spacial
|
||||
// sampler keyboard
|
||||
// wirelessly connected cloud (based on ESP-NOW, a kind of LPWAN?)
|
||||
//
|
||||
|
||||
//
|
||||
// Forest all/around @ MMCA, Seoul
|
||||
// Conversation about the ROOT @ SEMA warehouses, Seoul
|
||||
//
|
||||
|
||||
//
|
||||
// 2019 12 11
|
||||
// 2021 02 15
|
||||
//
|
||||
// (part-3) teensy35 : 'client:sampler' (mesh post --> play sounds)
|
||||
//
|
||||
|
|
|
|||
12
puredata/limitcnt-help.pd
Normal file
12
puredata/limitcnt-help.pd
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#N canvas 1 89 450 300 12;
|
||||
#X obj 82 72 bng 15 250 50 0 empty empty -(dec) 17 7 0 10 -262144 -1
|
||||
-1;
|
||||
#X obj 163 72 bng 15 250 50 0 empty empty +(inc) 17 7 0 10 -262144
|
||||
-1 -1;
|
||||
#X floatatom 82 137 5 0 0 0 - - -;
|
||||
#X obj 82 104 limitcnt 0 8;
|
||||
#X text 195 102 count from 0 to 8;
|
||||
#X text 195 122 always stay in the range;
|
||||
#X connect 0 0 3 0;
|
||||
#X connect 1 0 3 1;
|
||||
#X connect 3 0 2 0;
|
||||
53
puredata/limitcnt.pd
Normal file
53
puredata/limitcnt.pd
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#N canvas 414 282 439 376 12;
|
||||
#X obj 141 161 f;
|
||||
#X obj 171 161 +;
|
||||
#X obj 49 49 t b b;
|
||||
#X obj 231 51 t b b;
|
||||
#X floatatom 171 196 5 0 0 0 - - -;
|
||||
#X floatatom 263 304 5 0 0 0 - - -;
|
||||
#X msg 28 216 0;
|
||||
#X obj 352 140 f \$2;
|
||||
#X msg 352 190 set \$1;
|
||||
#X obj 263 273 moses;
|
||||
#X obj 352 109 loadbang;
|
||||
#X msg 352 247 8;
|
||||
#X obj 263 328 outlet;
|
||||
#X obj 49 18 inlet;
|
||||
#X obj 231 20 inlet;
|
||||
#X obj 28 115 loadbang;
|
||||
#X obj 28 146 f \$1;
|
||||
#X obj 171 242 moses;
|
||||
#X msg 28 171 set \$1;
|
||||
#X text 27 292 bangged counter from \$1 to \$2;
|
||||
#X text 27 312 limited at each edges;
|
||||
#X obj 295 199 + 1;
|
||||
#X msg 117 69 -1;
|
||||
#X msg 263 141 1;
|
||||
#X connect 0 0 1 0;
|
||||
#X connect 1 0 0 1;
|
||||
#X connect 1 0 4 0;
|
||||
#X connect 2 0 0 0;
|
||||
#X connect 2 1 22 0;
|
||||
#X connect 3 0 0 0;
|
||||
#X connect 3 1 23 0;
|
||||
#X connect 4 0 17 0;
|
||||
#X connect 5 0 12 0;
|
||||
#X connect 6 0 0 1;
|
||||
#X connect 7 0 21 0;
|
||||
#X connect 7 0 8 0;
|
||||
#X connect 8 0 11 0;
|
||||
#X connect 9 0 5 0;
|
||||
#X connect 9 1 11 0;
|
||||
#X connect 10 0 7 0;
|
||||
#X connect 11 0 0 1;
|
||||
#X connect 13 0 2 0;
|
||||
#X connect 14 0 3 0;
|
||||
#X connect 15 0 16 0;
|
||||
#X connect 16 0 18 0;
|
||||
#X connect 16 0 17 1;
|
||||
#X connect 17 0 6 0;
|
||||
#X connect 17 1 9 0;
|
||||
#X connect 18 0 6 0;
|
||||
#X connect 21 0 9 1;
|
||||
#X connect 22 0 1 1;
|
||||
#X connect 23 0 1 1;
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue