Hello there, I am working on an interfacing project for a control board, and used a duemilanove chip to beta test my separate functions and and everthing on it worked, but when i uploaded the project to the mega 2560 board, the same functions did not work.
for the duemilanove, i used the midi shield, and a serial 16x2 lcd module, my application requires bi-directional midi communication thus i jumped the midi read pins 5,4 to midi outpins 3,1 , respectively (as per manufacturer's design).
I uploaded the following program to the duemilanove, and it worked perfectly:
#include <MIDI.h>
#include <LiquidCrystal.h>
// LCD Pins (4, 5,10,11,12,13)
LiquidCrystal lcd(6, 5, 10, 11, 12, 13);
char * Notes[12] = {
"A ","Bb","B ","C ","Db","D ","Eb","E ","F ","Gb","G ","Ab"};
byte index1[8] = {
B11111,B01110,B00100,B00000,B00100,B01110,B11111}; //custom index character
byte index2[8] = {
B00000,B00100,B01110,B11111,B01110,B00100,B00000}; //custom index character
int SwitchState = HIGH;
int SwitchState2 = HIGH;
byte RQSTNAME[5] = {
0x00,0x01,0x74,0x01,0x0f};
byte *RFN = RQSTNAME;
void setup(){
lcd.createChar(0,index1);
lcd.createChar(1,index2);
lcd.begin(16,2);
pinMode(2,INPUT); //tuner button
digitalWrite(2,HIGH);
pinMode(3,INPUT); //present name request button
digitalWrite(3,HIGH);
MIDI.begin();
}
void loop(){
int sizear;
if(digitalRead(2) == LOW && SwitchState ==HIGH){ //if tuner button is pressed
MIDI.send(ControlChange, 15,127,1);
delay(250);
Tune();
lcd.clear();
}
digitalWrite(2,HIGH);
/*
MIDI.read(); //read the midi
MIDI.getSysExArray();
sizear = MIDI.getData1();
if((MIDI.getSysExArray())[5] ==0x0d && sizear ==10){ //if tuner message is recieved
Tune();
}
*/
if(digitalRead(3) ==LOW &&SwitchState2 ==HIGH){
ReName();
}
}
void Tune(){
int note;
int tune;
int tunepos;
int oct;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Note: ");
while (digitalRead(2) != LOW && SwitchState == HIGH){
MIDI.read();
int index = 0;
note = MIDI.getSysExArray()[6];
oct = MIDI.getSysExArray()[7];
tune = MIDI.getSysExArray()[8];
lcd.setCursor(7,0);
lcd.print(Notes[note]);
lcd.setCursor(0,1);
lcd.print(" "); //clear bottom row
if(0 <=tune && tune<15){
tunepos=1;
}
if(15<=tune && tune<30){
tunepos=2;
}
if(30<=tune&& tune <45){
tunepos=3;
}
if(45<=tune&& tune<55){
tunepos=4;
}
if(55<=tune&& tune<60){
tunepos=5;
}
if(60<=tune&& tune<63){
tunepos=6;
}
if(63<=tune&& tune<65){
tunepos=7;
index = 1;
}
if(65<=tune&& tune<68){
tunepos=8;
}
if(68<=tune&& tune<73){
tunepos=9;
}
if(73<=tune&& tune<83){
tunepos=10;
}
if(83<=tune&& tune<98){
tunepos=11;
}
if(98<=tune&& tune<113){
tunepos=12;
}
if(113<=tune&& tune<128){
tunepos=13;
}
lcd.setCursor(tunepos,1);
lcd.write(index); //prints custom index charater
delay(15);
}
digitalWrite(2,HIGH);
MIDI.send(ControlChange, 15,0,1);
delay(250);
lcd.clear();
}
void ReName(){
int sizear;
int nmbrchar;
byte chars;
MIDI.sendSysEx(5,RFN); //length is either 5 or 7 with sysex markers
MIDI.read();
MIDI.getSysExArray(); //need to make sure arduino recieves the sysex msg for present name in time, may need a delay or waiting loop...
sizear = MIDI.getData1();
if((MIDI.getSysExArray())[5] ==0x0f && sizear>10){
lcd.clear();
lcd.setCursor(0,0);
for(int i=6;i<(sizear-8);i++){ //option 1
chars = (MIDI.getSysExArray())[i];
if(MIDI.getSysExArray()[i] !=0x00){
lcd.print(chars); }
}
}
}
then, i made a MIDI interface using TOM SCRAFFS MIDI LAYOUT with a 6N139 chip, with everything hooked up properly as it seems, and using 1k for R3 & R2. I checked my midi out works, and even the midi in works (the program can read program change and control change messages), but for some reason the SysExArray does not seem to working when i use this code, where the button pins are changed and working, but the actual SysEx doesnt seem to be working.
#include <MIDI.h>
#include <LiquidCrystal.h>
// LCD Pins (4, 5,10,11,12,13)
LiquidCrystal lcd(7,6,3,2,5,4);
char * Notes[12] = {
"A ","Bb","B ","C ","Db","D ","Eb","E ","F ","Gb","G ","Ab"};
byte index1[8] = {
B11111,B01110,B00100,B00000,B00100,B01110,B11111}; //custom index character
byte index2[8] = {
B00000,B00100,B01110,B11111,B01110,B00100,B00000}; //custom index character
int SwitchState = HIGH;
int SwitchState2 = HIGH;
byte RQSTNAME[5] = {
0x00,0x01,0x74,0x01,0x0f};
byte *RFN = RQSTNAME;
void setup(){
lcd.createChar(0,index1);
lcd.createChar(1,index2);
lcd.begin(20,2);
pinMode(52,INPUT); //tuner button
digitalWrite(52,HIGH);
pinMode(53,INPUT); //present name request button
digitalWrite(53,HIGH);
MIDI.begin();
}
void loop(){
int sizear;
if(digitalRead(52) == LOW && SwitchState ==HIGH){ //if tuner button is pressed
MIDI.send(ControlChange, 15,127,1);
delay(250);
Tune();
lcd.clear();
}
digitalWrite(2,HIGH);
/*
MIDI.read(); //read the midi
MIDI.getSysExArray();
sizear = MIDI.getData1();
if((MIDI.getSysExArray())[5] ==0x0d && sizear ==10){ //if tuner message is recieved
Tune();
}
*/
if(digitalRead(53) ==LOW &&SwitchState2 ==HIGH){
ReName();
}
}
void Tune(){
int note;
int tune;
int tunepos;
int oct;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Note: ");
while (digitalRead(52) != LOW && SwitchState == HIGH){
MIDI.read();
int index = 0;
note = MIDI.getSysExArray()[6];
oct = MIDI.getSysExArray()[7];
tune = MIDI.getSysExArray()[8];
lcd.setCursor(7,0);
lcd.print(Notes[note]);
lcd.setCursor(0,1);
lcd.print(" "); //clear bottom row
if(0 <=tune && tune<15){
tunepos=1;
}
if(15<=tune && tune<30){
tunepos=2;
}
if(30<=tune&& tune <45){
tunepos=3;
}
if(45<=tune&& tune<55){
tunepos=4;
}
if(55<=tune&& tune<60){
tunepos=5;
}
if(60<=tune&& tune<63){
tunepos=6;
}
if(63<=tune&& tune<65){
tunepos=7;
index = 1;
}
if(65<=tune&& tune<68){
tunepos=8;
}
if(68<=tune&& tune<73){
tunepos=9;
}
if(73<=tune&& tune<83){
tunepos=10;
}
if(83<=tune&& tune<98){
tunepos=11;
}
if(98<=tune&& tune<113){
tunepos=12;
}
if(113<=tune&& tune<128){
tunepos=13;
}
lcd.setCursor(tunepos,1);
lcd.write(index); //prints custom index charater
delay(15);
}
digitalWrite(52,HIGH);
MIDI.send(ControlChange, 15,0,1);
delay(250);
lcd.clear();
}
void Tune2(){
int tune;
int tuneold;
while(digitalRead(52) != LOW && SwitchState == HIGH){
if(MIDI.getSysExArray()[5] > 0){
tune = MIDI.getSysExArray()[8];
lcd.clear();
lcd.print("MIDI IN ");
lcd.print(MIDI.getSysExArray()[5]);
if(tune != tuneold){
lcd.print(tune);
}
}
tuneold=tune;
}
digitalWrite(52,HIGH);
MIDI.send(ControlChange, 15,0,1);
delay(250);
lcd.clear();
}
void ReName(){
int sizear;
int nmbrchar;
byte chars;
MIDI.sendSysEx(5,RFN); //length is either 5 or 7 with sysex markers
MIDI.read();
MIDI.getSysExArray(); //need to make sure arduino recieves the sysex msg for present name in time, may need a delay or waiting loop...
sizear = MIDI.getData1();
if((MIDI.getSysExArray())[5] ==0x0f && sizear>10){
lcd.clear();
lcd.setCursor(0,0);
for(int i=6;i<(sizear-8);i++){ //option 1
chars = (MIDI.getSysExArray())[i];
if(MIDI.getSysExArray()[i] !=0x00){
lcd.print(chars); }
}
}
}
I am using Arduino-0021 and Midi library 3.1 for both projects.
any ideas????
Thanks!
This is tom scarffs layout: