Go Down

Topic: Arduino Mega MIDI LCD (Read 56 times) previous topic - next topic

Wallty

Hello,

I am converting keyboards from an church organ, using 3 Arduino Mega (one for each keyboard) and it's working very well so far. I use it for the software sampler Hauptwerk.
I am using loopMidi and Hairless MIDI for creating virtual MIDI ports.
Well, I wanted to add some LCDs for displaying informations about the current instrument, settings etc and I have some troubles how to write the program.

I want to use at least 3 - better 4 - displays as MIDI OUT, but I receive only MIDI IN signals.
I try to implement the SysEx from Hauptwerk.
I am sure that my code is wrong, perhaps you know what to change?

Here is my code so far:

#include <LiquidCrystal_I2C.h>
#include <WireData.h>
#include <MIDI.h>

#if defined(USBCON)
#include <midi_UsbTransport.h>

#define BACKLIGHT_PIN   13

static const unsigned sUsbTransportBufferSize = 16;
typedef midi::UsbTransport<sUsbTransportBufferSize> UsbTransport;

UsbTransport sUsbTransport;

MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, MIDI);

#else // No USB available, fallback to Serial
MIDI_CREATE_DEFAULT_INSTANCE();
#endif

LiquidCrystal_I2C lcd(0x26, 16, 2);
LiquidCrystal_I2C lcd2(0x27, 16, 2);


const byte MIDI_SYSEX=7; //code for SysEx
const byte ID_HAUPTWERK=0x7D; //ID for the Hauptwerk program

int midiType=0;
int data1=0;
int data2=0;

String hwline1="";
String hwline2="";
void setup() {

  lcdinit();
  lcdclear();
  lcdbacklight(125);
  updateDisplay();
}

void lcdinit(){
  Serial.begin(9600);
  delay(800);

  // Set display 16x2
  Serial.write(5);
  Serial.write(2);
  Serial.write(16);
  Serial.write(0x26);   
}

void lcdpos(byte row,byte column) {
  Serial.write(2);
  Serial.write(row);
  Serial.write(column);
  Serial.write(0x26);


void lcdclear(){
  // Clear Display
  Serial.write(4);
  Serial.write(0x26);
}

void lcdbacklight(byte brightness) {
  // Set backlight on
  Serial.write(7);
  Serial.write(brightness);
  Serial.write(0x26);
}

void lcdstring(String what){
  Serial.write(1);
  Serial.print(what);
  Serial.write(0x26);   
}

void lcdchar(byte what){
  Serial.write(10);
  Serial.write(what);
  Serial.write(0x26);   
}

void loop(){
  if (MIDI.read()) {
    midiType=MIDI.getType();
    data1=MIDI.getData1();
    data2=MIDI.getData2();
    //we are interested in SysEx messages
    if ((midiType == MIDI_SYSEX) && (data1 < 80)) {     
    //this is a SysEx message and will fit in our array   
    byte * sysexmessage=MIDI.getSysExArray();
    hwline1="";
    hwline2="";
    if ((sysexmessage[1]==ID_HAUPTWERK) && (data1 > 24)) {
        //this is from Hauptwerk

        for (int x=6; x<(22); x++){
          //step through sysex message
          byte c=sysexmessage
  • ;

          hwline1 = hwline1 + char(c);
        }
        for (int x=22; x<(37); x++){
          //step through sysex message
          byte c=sysexmessage
  • ;

          hwline2 = hwline2 + char(c);
        }
        updateDisplay();
      }

    }
  }
}

void updateDisplay() {
  lcdpos(1,1);
  lcdstring(hwline1);
  lcdpos(2,1);
  lcdstring(hwline2);
}

groundFungus

#1
Jul 20, 2019, 01:28 pm Last Edit: Jul 20, 2019, 01:39 pm by groundFungus
Code: [Select]
void lcdinit(){
  Serial.begin(9600);
  delay(800);
  // Set display 16x2
  Serial.write(5);
  Serial.write(2);
  Serial.write(16);
  Serial.write(0x26);   
}


Look at the examples that come with the LiquidCrystal_I2C library.  Do the examples use Serial for the displays?

I suggest that you get one display working by itself with no Midi stuff using the HelloWorld example.  Then set the I2C address jumpers for the second display and get it working by itself.  Then, once that you understand how they work, you can incorporate the displays into your code.

Why didn't you read the how to use this forum-please read stickies before posting?

Go Up