Go Down

Topic: ARDUINO + musical instrument shield to make a Keyboard (Read 7804 times) previous topic - next topic

tea-time

MusicIntrument_Keyboard Errors

Thank you very much for your comments.

Your suggestion such as declaration of "byte note[ ]" seemed reasonable.
However, there still exist errors.



The line
  noteOn(0,note,100);
is still highlighted and there are messages as
"  invalid conversion from 'byte' to 'byte'   "
"  initializing argument 2 of void 'noteOn(byte,byte,byte)'   "


The full code is as follows.

Code: [Select]
//Music Instrument Shield_Keyboard  renew
//MusicIntrument_Keyboard
// Music Instrument Shield_Keyboard

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //Soft TX on 3, we don't use RX in this code

byte inputPins[] = {5,6,7,8,9,10,11,12,13};
byte note[]={72,74,76,77,79,81,83,84,86};
int pinCount = 9;

int buttonState[9];
int lastButtonState[9]; 

byte resetMIDI = 4; //Tied to VS1053 Reset line
int instrument = 13;

void setup() {

  //Setup soft serial for MIDI control
  mySerial.begin(31250);
 
  for(int i=0; i<pinCount; i++){
  pinMode(inputPins[i], OUTPUT);//pinMode(outputPins, OUTPUT);
  digitalWrite(inputPins[i], LOW);// this enables the pull up resistors to reduce noise
  pinMode(inputPins[i], INPUT);
  }


  //Reset the VS1053
  digitalWrite(resetMIDI, LOW);
  delay(100);
  digitalWrite(resetMIDI, HIGH);
  delay(100);

  talkMIDI(0xB0, 0x07, 126); //0xB0 is channel message, set channel volume to near max (127)
  talkMIDI(0xB0, 0, 0x79); //Default bank GM1
  talkMIDI(0xC0, instrument, 0); //Set instrument number. 0xC0 is a 1 data byte command

}

void loop() {
 
for (int i=0; i<pinCount; i++){

  buttonState[i] = digitalRead(inputPins[i]);
  delay(1);
 
  if (buttonState[i] != lastButtonState[i]) {       
   
    if (buttonState[i] == HIGH) {                     
    noteOn(0,note,100);                     
    }
   
  }

  lastButtonState[i] = buttonState[i];
 
  }
}

//Send a MIDI note-on message.  Like Pressing a piano key
void noteOn(byte channel, byte note, byte attack_velocity) {
  talkMIDI( (0x90 | channel), note, attack_velocity);
}

//Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte release_velocity) {
  talkMIDI( (0x80 | channel), note, release_velocity);
}

//Plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that data values are less than 127
void talkMIDI(byte cmd, byte data1, byte data2) {
  mySerial.write(cmd);
  mySerial.write(data1);

  //Some commands only have one data byte. All cmds less than 0xBn have 2 data bytes
  //(sort of: http://253.ccarh.org/handout/midiprotocol/)
  if( (cmd & 0xF0) <= 0xB0)
    mySerial.write(data2);

}





It seems difficult but welcomes any suggestions.

DuaneB

Code: [Select]

  if (buttonState[i] != lastButtonState[i]) {       
   
    if (buttonState[i] == HIGH) {                     
    noteOn(0,note[i],100);                     
    }
   
  }


Spot the difference.

It compiles for me with this change - if you can spot it.

Duane B
Read this
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

tea-time

MusicInstrument_Keyboard --   No more Errors

Wow! Thank you very much for all of your suggestions.
The program is finally verified and the program is running with  beautiful sounds.

As "note" is also an array, there should has been a suffix.
I did not notice it.
Once again, thank you very much.

Now I'm trying to make an infrared keyboards.
About 6 Infrared beams(38KHz) are emitted and if a peson blocks a beam, the receiver gives a 5V voltage.
This is the signal for the "inputPins" of this "ARDUINO + musical instrument shield."

I'll post within a few days.

Thank you.

DuaneB was correct... your note is an array of integers so you must identify the index... that is, which note you want to generate...

To play: 79 use: note[4]....

You've probably already worked that out... ;)

Congratulations Plankton,
  I have a very similar project and I am eager to follow your footsteps. Thank you for posting your results!
Besides being able to generate sounds directly with sparkfun MI interface, or alternatively to it, I want my keyboard to send MIDI data to the computer (PC) with the help of the MIDI library.
I am not quite sure though how to receive the data on the PC side.
In particular, I need to find a program (possibly free, for the time being, while I am experimenting) that receive the MIDI data from the Arduino and plays them right away (with the WIndows GM synth table or something else). So far, no luck.
Do you have any hint or advice to point me the right way?

Thanks

Luca
There are three kind of people in the world: Those who can count, and those who can't

I found the answer to my own question:
I've been able to use Serial to MIDI converter, which receives midi data from the arduino and sends them directly to the Microsoft GM wawetable synthesizer (or other soft synths), without any additional hardware or software:

http://spikenzielabs.com/SpikenzieLabs/Serial_MIDI.html

Thanks Thot :)
There are three kind of people in the world: Those who can count, and those who can't

cooper_hu

Hey man,

I just picked up the MS shield from Sparkfun for a project I'm working on. After going through this thread I was able to get the sketch working without error and uploaded to my Arduino. Though I am having difficulty with the hardware setup. I know this is a somewhat old post, so I'm not sure if you or anyone will see this! but I was wondering if you could post a simple hardware set up to get this working. I watched your video but because of the low-quality I was not able to see what was plugged into what. Thanks!

Coop

Go Up