`Hey all, I'm having some issues using Serial1 (2 and 3) instead of Serial for Midi messages using MIDI.h. Everything works fine, but I must be missing something for Serial1 to finally work. I#m working in a Midi-Pedal Switcher and I have seen some comments of other DIYers, but they didn't fix my issue.
Posted all my code, just in case it can be helpful to someone like me. Thanks for any help.
```cpp
#include <hd44780.h>
#include <MIDI.h>
#include <Wire.h> // not surte I really needf it, but meh...
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
#include <serialMIDI.h> // not sure I need it
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI); // works flawlessly. Just a pain to disconnect TX0 when uploading every time
//MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI); // wont send MIDI out. I'v tried a lot, too, no success
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
const int LCD_COLS = 20;
const int LCD_ROWS = 4;
// LEDs
const int led1(22);
const int led2(23);
const int led3(24);
const int led4(25);
const int led5(26);
const int led6(27);
const int led7(28);
const int led8(29);
const int led9(30);
const int led10(31);
// Switches
const int sw1(41);
const int sw2(42);
const int sw3(43);
const int sw4(44);
const int sw5(45);
const int sw6(46);
const int sw7(47);
const int sw8(48);
const int sw9(49);
const int sw10(50);
const int boostSw(32);
int stateLed1 = LOW;
int stateLed2 = LOW;
int stateLed3 = LOW;
int stateLed4 = LOW;
int stateLed5 = LOW;
int stateLed6 = LOW;
int stateLed7 = LOW;
int stateLed8 = LOW;
int stateLed9 = LOW;
int stateLed10 = LOW;
int stateSw1 = true; // true because INPUT_PULLUP
int stateSw2 = true;
int stateSw3 = true;
int stateSw4 = true;
int stateSw5 = true;
int stateSw6 = true;
int stateSw7 = true;
int stateSw8 = true;
int stateSw9 = true;
int stateSw10 = true;
int lastStateSw1 = false;
int lastStateSw2 = false;
int lastStateSw3 = false;
int lastStateSw4 = false;
int lastStateSw5 = false;
int lastStateSw6 = false;
int lastStateSw7 = false;
int lastStateSw8 = false;
int lastStateSw9 = false;
int lastStateSw10 = false;
int statePg1 = false;
int statePg2 = false;
int statePg3 = false;
int statePg4 = false;
int statePg5 = false;
int statePg6 = false;
int statePg7 = false;
int statePg8 = false;
int statePg9 = false;
int statePg10 = false;
int name = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int sendValue1 = 0; // the actual send value is off by 1 ("45" sent, "46" rcvd) so I deduct 1 in the switch code below)
int sendValue2 = 0;
int tap = 0;
int tap2 = 0;
bool midBoost = 0;
int boostMsg = 0;
int boostLevel = 127;
int normLevel = 70;
// PRESET 1 VALUES
byte pg1ch1 = 0; // Timeline - delay
byte pg1ch2 = 0; // SPACE - reverb
byte pg1ch3 = 1; // Heavy Channel
// PRESET 2 VALUES
byte pg2ch1 = 29;
byte pg2ch2 = 22;
byte pg2ch3 = 2;
// PRESET 3 VALUES
byte pg3ch1 = 22;
byte pg3ch2 = 9;
byte pg3ch3 = 2;
// PRESET 4 VALUES
byte pg4ch1 = 0;
byte pg4ch2 = 5;
byte pg4ch3 = 2;
// PRESET 5 VALUES
byte pg5ch1 = 0;
byte pg5ch2 = 19;
byte pg5ch3 = 3;
// PRESET 6 VALUES
byte pg6ch1 = 1;
byte pg6ch2 = 11;
byte pg6ch3 = 3;
// PRESET 7 VALUES
byte pg7ch1 = 10;
byte pg7ch2 = 21;
byte pg7ch3 = 3;
// PRESET 8 VALUES
byte pg8ch1 = 0;
byte pg8ch2 = 5;
byte pg8ch3 = 3;
void setup() {
int status;
// initialize LCD with number of columns and rows:
// hd44780 returns a status from begin() that can be used
// to determine if initalization failed.
// the actual status codes are defined in <hd44780.h>
// See the values RV_XXXX
//
// looking at the return status from begin() is optional
// it is being done here to provide feedback should there be an issue
//
// note:
// begin() will automatically turn on the backlight
//
status = lcd.begin(LCD_COLS, LCD_ROWS);
if (status) // non zero status means it was unsuccesful
{
// hd44780 has a fatalError() routine that blinks an led if possible
// begin() failed so blink error code using the onboard LED if possible
hd44780::fatalError(status); // does not return
}
pinMode (18, OUTPUT);
pinMode (19, INPUT);
MIDI.begin(31250);
MIDI.begin(MIDI_CHANNEL_OMNI); // I nbeed it to listen to all MIDI Chs
// pinMode (17, INPUT_PULLUP); tried declaring RX2 as an input to make it work (it was the fix for DFRobot MP3 player at Serial2)
// pinMode (16, OUTPUT); tried declaring TX2 as an output (it was the fix for DFRobot MP3 player at Serial2)
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
pinMode(sw3, INPUT_PULLUP);
pinMode(sw4, INPUT_PULLUP);
pinMode(sw5, INPUT_PULLUP);
pinMode(sw6, INPUT_PULLUP);
pinMode(sw7, INPUT_PULLUP);
pinMode(sw8, INPUT_PULLUP);
pinMode(sw9, INPUT_PULLUP);
pinMode(sw10, INPUT_PULLUP);
pinMode(boostSw, INPUT_PULLUP);
// LED FUNCTION CHECK ON STARTUP - Check LEDs
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
lcd.setCursor(0, 0);
lcd.print(" MIDI-MONSTER ");
lcd.setCursor(0, 2);
lcd.print("setting Amp to DEATH");
MIDI.sendProgramChange (1,4); // activating Death-Metal Preset
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
lcd.clear();
}
void loop() {
lcd.setCursor(0, 1);
lcd.print("Tml1-");
lcd.setCursor(5, 1);
lcd.print(val1);
lcd.setCursor(0, 2);
lcd.print("Spc2-");
lcd.setCursor(5, 2);
lcd.print(val2);
lcd.setCursor(0, 3);
lcd.print("Hvy3-");
lcd.setCursor(5, 3);
lcd.print(val3);
lcd.setCursor(8,1);
lcd.print("Bst-");
lcd.setCursor(12,1);
lcd.print(midBoost);
lcd.setCursor(8,2);
lcd.print("Mid-");
lcd.setCursor(12,2);
lcd.print(boostMsg);
stateSw1 = digitalRead(sw1);
stateSw2 = digitalRead(sw2);
stateSw3 = digitalRead(sw3);
stateSw4 = digitalRead(sw4);
stateSw5 = digitalRead(sw5);
stateSw6 = digitalRead(sw6);
stateSw7 = digitalRead(sw7);
stateSw8 = digitalRead(sw8);
stateSw9 = digitalRead(sw9);
stateSw10 = digitalRead(sw10);
digitalWrite(led1, stateLed1);
digitalWrite(led2, stateLed2);
digitalWrite(led3, stateLed3);
digitalWrite(led4, stateLed4);
digitalWrite(led5, stateLed5);
digitalWrite(led6, stateLed6);
digitalWrite(led7, stateLed7);
digitalWrite(led8, stateLed8);
digitalWrite(led9, stateLed9);
digitalWrite(led10, stateLed10);
// SWITCH 1
if (!stateSw1) {
if (stateSw1 == LOW && stateLed1 == false) {
stateLed1 = 1;
stateLed2 = 0;
stateLed3 = 0;
stateLed4 = 0;
stateLed5 = 0;
stateLed6 = 0;
stateLed7 = 0;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("01: obZen");
val1 = pg1ch1; // The Value from above gets inserted here and also gets displayed correctly
val2 = pg1ch2;
val3 = pg1ch3;
sendValue2 = pg1ch2 - 1; // this is where I have to reduce the value by 1 so value 40 calls preset 40 ( otherwise preset would be 41 ) The FCB1010 does that too
sendValue1 = pg1ch1 - 1;
MIDI.sendProgramChange(val3, 3);
delay(10);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (normLevel), 4);
boostMsg = 0;
}
}
}
// SWITCH 2
if (!stateSw2) {
if (stateSw2 == LOW && stateLed2 == false) {
stateLed1 = 0;
stateLed2 = 1;
stateLed3 = 0;
stateLed4 = 0;
stateLed5 = 0;
stateLed6 = 0;
stateLed7 = 0;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("02: Psycho Shred");
val1 = pg2ch1;
val2 = pg2ch2;
val3 = pg2ch3;
sendValue2 = pg2ch2 - 1;
sendValue1 = pg2ch1 - 1;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (boostLevel), 4);
boostMsg = 1;
}
}
}
// SWITCH 3
if (!stateSw3) {
if (stateSw3 == LOW && stateLed3 == false) {
stateLed1 = 0;
stateLed2 = 0;
stateLed3 = 1;
stateLed4 = 0;
stateLed5 = 0;
stateLed6 = 0;
stateLed7 = 0;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("03: Hellfire Solo");
val1 = pg3ch1;
val2 = pg3ch2;
val3 = pg3ch3;
sendValue2 = pg3ch2 - 1;
sendValue1 = pg3ch1 - 1;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (boostLevel), 4);
boostMsg = 1;
}
}
}
// SWITCH 4
if (!stateSw4 && stateLed4 == false) {
if (stateSw4 == LOW) {
stateLed1 = 0;
stateLed2 = 0;
stateLed3 = 0;
stateLed4 = 1;
stateLed5 = 0;
stateLed6 = 0;
stateLed7 = 0;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("04: BLACKHOLE");
sendValue2 = pg4ch2 - 1;
sendValue1 = pg4ch1 - 1;
val1 = pg4ch1;
val2 = pg4ch2;
val3 = pg4ch3;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (boostLevel), 4);
boostMsg = 1;
}
}
}
// SWITCH 5
if (!stateSw5 && stateLed5 == false) {
if (stateSw5 == LOW) {
stateLed1 = 0;
stateLed2 = 0;
stateLed3 = 0;
stateLed4 = 0;
stateLed5 = 1;
stateLed6 = 0;
stateLed7 = 0;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("05: Master Reverb");
val1 = pg5ch1;
val2 = pg5ch2;
val3 = pg5ch3;
sendValue2 = pg5ch2 - 1;
sendValue1 = pg5ch1 - 1;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (normLevel), 4);
boostMsg = 0;
}
}
}
// SWITCH 6
if (!stateSw6 && stateLed6 == false) {
if (stateSw6 == LOW) {
stateLed1 = 0;
stateLed2 = 0;
stateLed3 = 0;
stateLed4 = 0;
stateLed5 = 0;
stateLed6 = 1;
stateLed7 = 0;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("06: STARGAZING");
val1 = pg6ch1;
val2 = pg6ch2;
val3 = pg6ch3;
sendValue2 = pg6ch2 - 1;
sendValue1 = pg6ch1 - 1;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (boostLevel), 4);
boostMsg = 1;
}
}
}
// SWITCH 7
if (!stateSw7 && stateLed7 == false) {
if (stateSw7 == LOW) {
stateLed1 = 0;
stateLed2 = 0;
stateLed3 = 0;
stateLed4 = 0;
stateLed5 = 0;
stateLed6 = 0;
stateLed7 = 1;
stateLed8 = 0;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("07: Tape Machine");
val1 = pg7ch1;
val2 = pg7ch2;
val3 = pg7ch3;
sendValue2 = pg7ch2 - 1;
sendValue1 = pg7ch1 - 1;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (boostLevel), 4);
boostMsg = 1;
}
}
}
// SWITCH 8
if (!stateSw8 && stateLed8 == false) {
if (stateSw8 == LOW) {
stateLed1 = 0;
stateLed2 = 0;
stateLed3 = 0;
stateLed4 = 0;
stateLed5 = 0;
stateLed6 = 0;
stateLed7 = 0;
stateLed8 = 1;
stateLed10 = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("08: BLACKHOLE");
val1 = pg8ch1;
val2 = pg8ch2;
val3 = pg8ch3;
sendValue2 = pg8ch2 - 1;
sendValue1 = pg8ch1 - 1;
MIDI.sendProgramChange (val3, 3);
if (val1 == 0){
MIDI.sendControlChange(102,0,1); //bypass Timeline if value is == 0
}
if (val2 == 0){
MIDI.sendControlChange(02, 127, 02); // bypass Space if value is == 0
}
if (val1 >= 1){
MIDI.sendProgramChange(sendValue1, 1); // load Preset sendValue1 Timeline
MIDI.sendControlChange(102, 127, 1); // activate Preset on Timeline
}
delay(10);
if (val2 >= 1){
MIDI.sendProgramChange(sendValue2, 2); // loadPreset sendValue2 on Timeline (loading different preset also activates it)
}
delay(10);
if (midBoost == true){
MIDI.sendControlChange(15, (boostLevel), 4);
boostMsg = 1;
}
}
}
// SWITCH 9 // TAP Footswitch
if (stateSw9 == LOW) {
stateLed9 = 1;
tap++; // increases value while button is pressed
}
else{
stateLed9 = 0;
tap = 0; // resets value if button is releases
}
if (tap == 1){
MIDI.sendControlChange(93, 127, 1); // TAP TEMPO TIMELINE
MIDI.sendControlChange(100, 127,2); // TAP TEMPO SPACE
}
// SWITCH 10 // HOT SW FOOTSWITCH
if (stateSw10 == LOW) {
tap2++; // increases value while button is pressed
}
else{
tap2 = 0; // resets value if button is releases
}
if (tap2 == 1){
MIDI.sendControlChange(101, 127,2); // send CC101 value 127 channel 3
delay(20);
stateLed10 = !stateLed10;
MIDI.sendControlChange(101,0,2); // send CC101 value 0 channel3
}
// MID BOOST SWITCH ACTIVE CODE
if (digitalRead (boostSw) == LOW){
midBoost = 1;
}
else {
midBoost = 0;
}
}





