Added I2C-LCD.

Added SoftwareSerial for 2nd MIDI port.
Added MIDI merge.
master
Holger Wirtz 4 years ago
parent 140de71583
commit a4affe1daf
  1. 186
      OSC2MidiGateway.ino

@ -1,14 +1,3 @@
// .../Arduino/hardware/espressif/esp32/cores/esp32/HardwareSerial.cpp:
/*
#ifndef RX1
#define RX1 35
#endif
#ifndef TX1
#define TX1 34
#endif
*/
#if !(defined(ESP32) ) #if !(defined(ESP32) )
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting. #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif #endif
@ -16,11 +5,36 @@
// Use from 0 to 4. Higher number, more debugging messages and memory usage. // Use from 0 to 4. Higher number, more debugging messages and memory usage.
#define _WIFIMGR_LOGLEVEL_ 3 #define _WIFIMGR_LOGLEVEL_ 3
#define DEBUG 1 #define DEBUG 1
#define AP_TRIGGER_PIN 15 #define MDNS_NAME "osc2midi"
#define AP_SSID_NAME "OSC2MIDI"
#define AP_SSID_CONFIG_NAME "OSC2MIDI-Config"
#define AP_PASSWORD "osc2midi"
#define MDNS_NAME "osc2midi"
#define SOFT_SERIAL_RX 18
#define SOFT_SERIAL_TX 19
#define AP_TIMEOUT 120 #define AP_TIMEOUT 120
#define AP_NAME "OSC2MidiBridge" #define AP_TRIGGER_PIN 15
#define AP_DATA_RESET_PIN 15
#define AP_MODE 23
#define LCD_I2C_ADDR 0x27
#define LCD_COL 16
#define LCD_ROW 2
#define FileFS SPIFFS
#define FS_Name "SPIFFS"
#define MIN_AP_PASSWORD_SIZE 8
#define SSID_MAX_LEN 32
#define PASS_MAX_LEN 64
#define NUM_WIFI_CREDENTIALS 2
#define CONFIG_FILENAME F("/wifi_cred.dat")
// You only need to format the filesystem once
//#define FORMAT_FILESYSTEM
//#define RESET_AP_DATA
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 100
#define WIFI_MULTI_CONNECT_WAITING_MS 200
#define WIFICHECK_INTERVAL 1000
#define HEARTBEAT_INTERVAL 10000
#include <esp_wifi.h> #include <esp_wifi.h>
#include <WiFi.h> #include <WiFi.h>
@ -49,23 +63,7 @@
#include "OSC2Midi.h" #include "OSC2Midi.h"
#include <HardwareSerial.h> #include <HardwareSerial.h>
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#define FileFS SPIFFS
#define FS_Name "SPIFFS"
#define MIN_AP_PASSWORD_SIZE 8
#define SSID_MAX_LEN 32
#define PASS_MAX_LEN 64
#define NUM_WIFI_CREDENTIALS 2
#define CONFIG_FILENAME F("/wifi_cred.dat")
// You only need to format the filesystem once
//#define FORMAT_FILESYSTEM
//#define RESET_AP_DATA
#define WIFI_MULTI_1ST_CONNECT_WAITING_MS 100
#define WIFI_MULTI_CONNECT_WAITING_MS 200
#define WIFICHECK_INTERVAL 1000
#define HEARTBEAT_INTERVAL 10000
#define AP_DATA_RESET_PIN 15
#define AP_MODE 23
typedef struct typedef struct
{ {
@ -101,6 +99,7 @@ String AP_PASS;
IPAddress stationIP = IPAddress(0, 0, 0, 0); IPAddress stationIP = IPAddress(0, 0, 0, 0);
IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress gatewayIP = IPAddress(192, 168, 2, 1);
IPAddress netMask = IPAddress(255, 255, 255, 0); IPAddress netMask = IPAddress(255, 255, 255, 0);
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_COL, LCD_ROW);
/* /*
UART RX IO TX IO CTS RTS UART RX IO TX IO CTS RTS
@ -110,30 +109,54 @@ IPAddress netMask = IPAddress(255, 255, 255, 0);
*/ */
HardwareSerial midi1(2); // RX: 16, TX: 17 HardwareSerial midi1(2); // RX: 16, TX: 17
//HardwareSerial midi2(1); // RX: 35, TX: 34 (changed in .../Arduino/hardware/espressif/esp32/cores/esp32/HardwareSerial.cpp!) #ifndef D5
#define D5 (18) #define D5 (SOFT_SERIAL_RX)
#define D6 (19) #define D6 (SOFT_SERIAL_TX)
//#define D7 (23)
//#define D8 (5)
//#define TX (1)
#endif
SoftwareSerial midi2; SoftwareSerial midi2;
MIDI_CREATE_INSTANCE(HardwareSerial, midi1, MIDI1); MIDI_CREATE_INSTANCE(HardwareSerial, midi1, MIDI1);
MIDI_CREATE_INSTANCE(SoftwareSerial, midi2, MIDI2);
void setup() void setup()
{ {
pinMode(AP_TRIGGER_PIN, INPUT_PULLUP);
pinMode(AP_DATA_RESET_PIN, INPUT_PULLUP);
pinMode(AP_MODE, INPUT_PULLUP);
Serial.begin(115200);
Serial.setDebugOutput(true);
DEBUG_MSG("<start>\nOSC2Midi\n");
lcd.init();
lcd.backlight();
lcd.clear();
lcd.noCursor();
lcd.setCursor(0, 0);
lcd.print("OSC2MIDI");
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
Serial.print("\nStarting AutoConnectWithFeedBack using " + String(FS_Name)); Serial.print("\nStarting AutoConnectWithFeedBack using " + String(FS_Name));
Serial.println(" on " + String(ARDUINO_BOARD)); Serial.println(" on " + String(ARDUINO_BOARD));
pinMode(AP_DATA_RESET_PIN, INPUT_PULLUP);
pinMode(AP_MODE, INPUT_PULLUP);
if (digitalRead(AP_MODE) == LOW) if (digitalRead(AP_MODE) == LOW)
{ {
Serial.println("Mode: AP"); Serial.println("Mode AccessPoint");
WiFi.softAP(AP_SSID_NAME, AP_PASSWORD);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mode AP");
} }
else else
{ {
Serial.println("Mode: Client");
lcd.clear();
#if defined(FORMAT_FILESYSTEM) #if defined(FORMAT_FILESYSTEM)
FileFS.format(); FileFS.format();
#endif #endif
@ -192,8 +215,8 @@ void setup()
} }
// SSID and PW for Config Portal // SSID and PW for Config Portal
AP_SSID = "OSC2MIDI"; AP_SSID = AP_SSID_CONFIG_NAME;
AP_PASS = "osc2midi"; AP_PASS = AP_PASSWORD;
// From v1.1.0, Don't permit NULL password // From v1.1.0, Don't permit NULL password
if ( (Router_SSID == "") || (Router_Pass == "") ) if ( (Router_SSID == "") || (Router_Pass == "") )
@ -205,9 +228,17 @@ void setup()
// Starts an access point // Starts an access point
//if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), password)) //if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), password))
if ( !ESP_wifiManager.startConfigPortal(AP_SSID.c_str(), AP_PASS.c_str()) ) if ( !ESP_wifiManager.startConfigPortal(AP_SSID.c_str(), AP_PASS.c_str()) )
{
Serial.println("Not connected to WiFi but continuing anyway."); Serial.println("Not connected to WiFi but continuing anyway.");
lcd.setCursor(0, 0);
lcd.print("Mode WiFi Cfg-AP");
lcd.setCursor(0, 1);
lcd.print("192.168.100.1");
}
else else
{
Serial.println("WiFi connected...yeey :)"); Serial.println("WiFi connected...yeey :)");
}
memset(&WM_config, 0, sizeof(WM_config)); memset(&WM_config, 0, sizeof(WM_config));
@ -279,7 +310,7 @@ void setup()
else else
Serial.println(ESP_wifiManager.getStatus(WiFi.status())); Serial.println(ESP_wifiManager.getStatus(WiFi.status()));
if (!MDNS.begin("osc2midi")) { if (!MDNS.begin(MDNS_NAME)) {
Serial.println("Error setting up MDNS responder!"); Serial.println("Error setting up MDNS responder!");
while (1) { while (1) {
delay(1000); delay(1000);
@ -289,6 +320,12 @@ void setup()
{ {
Serial.println("mDNS started."); Serial.println("mDNS started.");
} }
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mode WiFi client");
lcd.setCursor(0, 1);
lcd.print(WiFi.localIP());
} }
/* /*
@ -297,29 +334,20 @@ void setup()
*/ */
midi1.begin(31250); midi1.begin(31250);
midi2.begin(31250, SWSERIAL_8N1, D5, D6, false, 95, 11); midi2.begin(31250, SWSERIAL_8N1, D5, D6, false, 95, 11);
midi2.enableIntTx(false);
Serial.begin(115200);
Serial.setDebugOutput(true);
DEBUG_MSG("<start>\nOSC2Midi\n");
pinMode(AP_TRIGGER_PIN, INPUT_PULLUP);
//WiFi.softAP("OSC2Midi", "1357924680");
udp.begin(8000); udp.begin(8000);
MIDI1.begin(MIDI_CHANNEL_OMNI); MIDI1.begin(MIDI_CHANNEL_OMNI);
MIDI1.setHandleControlChange(MidiCCToOSC); MIDI1.setHandleControlChange(MidiCCToOSC);
MIDI1.turnThruOff(); MIDI1.turnThruOff();
MIDI2.begin(MIDI_CHANNEL_OMNI);
MIDI2.setHandleControlChange(MidiCCToOSC);
MIDI2.turnThruOff();
} }
void loop() void loop()
{ {
if (digitalRead(AP_MODE) != LOW)
check_status();
// check if we need to configure a AP // check if we need to configure a AP
if (digitalRead(AP_TRIGGER_PIN) == LOW) if (digitalRead(AP_TRIGGER_PIN) == LOW)
{ {
@ -330,7 +358,7 @@ void loop()
wm.setConfigPortalTimeout(AP_TIMEOUT); wm.setConfigPortalTimeout(AP_TIMEOUT);
if (!wm.startConfigPortal(AP_NAME)) if (!wm.startConfigPortal(AP_SSID_NAME))
{ {
DEBUG_MSG("Failed to connect and hit timeout - restarting!\n"); DEBUG_MSG("Failed to connect and hit timeout - restarting!\n");
delay(3000); delay(3000);
@ -375,36 +403,28 @@ void loop()
//MIDI1.read(); //MIDI1.read();
if (MIDI1.read()) if (MIDI1.read())
{ {
Serial.print("MIDI-IN[1] Type: "); DEBUG_MSG("MIDI-IN[1] Type: ");
Serial.print(MIDI1.getType(), DEC); DEBUG_MSG("%3d", MIDI1.getType());
Serial.print(" Data1: "); DEBUG_MSG(" Data1: ");
Serial.print(MIDI1.getData1(), DEC); DEBUG_MSG("%3d", MIDI1.getData1());
Serial.print(" Data2: "); DEBUG_MSG(" Data2: ");
Serial.print(MIDI1.getData2(), DEC); DEBUG_MSG("%3d", MIDI1.getData2());
Serial.print(" Channel: "); DEBUG_MSG(" Channel: ");
Serial.print(MIDI1.getChannel(), DEC); DEBUG_MSG("%0d", MIDI1.getChannel());
Serial.println(" Channel: "); DEBUG_MSG("\n");
} }
// MIDI-Merger from MIDI2 to MIDI1 // MIDI-Merger from (Soft-)MIDI2 to MIDI1
if (MIDI2.read()) if (midi2.available() > 0)
{ {
MIDI1.send(MIDI2.getType(), while (midi2.available() > 0)
MIDI2.getData1(), {
MIDI2.getData2(), Serial.print("->M:");
MIDI2.getChannel()); Serial.println(midi2.peek(), DEC);
Serial.print("MIDI-IN[2] Type: "); midi1.write(midi2.read());
Serial.print(MIDI2.getType(), DEC); }
Serial.print(" Data1: ");
Serial.print(MIDI2.getData1(), DEC);
Serial.print(" Data2: ");
Serial.print(MIDI2.getData2(), DEC);
Serial.print(" Channel: ");
Serial.print(MIDI2.getChannel(), DEC);
Serial.println(" Channel: ");
} }
} }
check_status();
} }
void OSCToMidiCC(OSCMessage & msg, int offset) void OSCToMidiCC(OSCMessage & msg, int offset)

Loading…
Cancel
Save