Go Down

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


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
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
// 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
  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);
  digitalWrite(resetMIDI, HIGH);

  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]);
  if (buttonState[i] != lastButtonState[i]) {       
    if (buttonState[i] == HIGH) {                     

  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) {

  //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)


It seems difficult but welcomes any suggestions.


Code: [Select]

  if (buttonState[i] != lastButtonState[i]) {       
    if (buttonState[i] == HIGH) {                     

Spot the difference.

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

Duane B
Read this
then watch this



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?


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:


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


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!



Dear Plankton
 I will be please to get your final code for the musical instrument with keyboard working +the Touch pad shield from Sparkfun.

All the best,


Go Up