Go Down

Topic: Real time MIDI w/ music shield (Read 5396 times) previous topic - next topic

bratan

Has anyone had any luck of getting real time MIDI to work with seedstudio music shield v1?  It's based on VC1053B.
Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, etc.

bratan

Ok I figured it out. MIDI works just fine...
Musicplayer.cpp (from Music_shield library) has function midiDemoPlayer() which can play notes, change banks, etc.
It was just a matter of moving midi functions from private to public in MusicPlayer.h file and then calling them from your sketch...
For example:
Code: [Select]
player.beginInMidiFmt();
player.midiWriteData(0xB0, 0x07, 120); // Set MIDI channel volume
player.midiWriteData(0xB0, 0, 0x00);  // Select bank GM1
player.midiWriteData(0xC0, 1, 0); // Select instrument (Piano)
player.midiNoteOn(0, 70, 127); // Play note (C4)
delay (1000);
player.midiNoteOff(0, 70, 127); // Stop playing note


Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, etc.

Pitchoilcan

Hi bratan, do you have a copy of your edited MusicPlayer.h? Can you share it with the group.
Thanks muchs
================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

bratan


Hi bratan, do you have a copy of your edited MusicPlayer.h? Can you share it with the group.
Thanks muchs

Sure here it is...
Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, etc.

Pitchoilcan

================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

Pitchoilcan

Does your mididemoplayer code look like this?
Code: [Select]
#include <SD.h>
#include <SPI.h>
#include <Arduino.h>
#include <MusicPlayer.h>

void setup(void)
{
 Serial.begin(9600);
 player.beginInMidiFmt();
}
void loop(void)
{
 player.midiDemoPlayer();
}
delay(500);
}

because even with the modified musicplayer.h I couldn't get this to work.
================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

Pitchoilcan

I can't get my vs1053 shield to work in Midi mode. I'm using arduino Arduino uno and mega (either one). Can you help me?
================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

bratan

I haven't played with it for a long time. I think this sketch should work if you connected all the pins correctly. It will just play middle C note.
Code: [Select]
#include <SD.h>
#include <SPI.h>
#include <MusicPlayer.h>

void setup()
{
  Serial.begin(115200);
  midiInit();

  //player.midiWriteData(0xC0, 1, 0); // Select instrument
  middleC();
  //triggerNotes();
// playMIDIMelody();
 
}
void loop()
{
  //player.play();

  //delay(500);
}

void triggerNotes() {
  for (int note = 30; note <87; note++) {
    player.midiNoteOn(0, note, 127);
    delay (50);
    player.midiNoteOff(0, note, 127);
    delay (50);
  }
 
}

// Play one note for all instruments in bank GM1
void middleC(){
  setMIDIBank (1);
  for (int i=0;i<127;i++) {
    Serial.print ("Playing instrument: ");
    Serial.println (i);
    player.midiWriteData(0xC0, i, 0); // Select instrument
    player.midiNoteOn(0, 60, 127); // Play C4
    delay (1000);
    player.midiNoteOff(0, 60, 127); // Stop playing C4
  }
}

void playMIDIMelody () {
  // Note numbers
  int C4=60,D4=62,E4=64,F4=65,G4=67,A4=69,B4=71,C5=72;
  int PP=0; //Pause
  int melody[] = {C4,C4,PP,G4,G4,PP,A4,A4,PP,G4,PP,PP,PP,PP,
                  F4,F4,PP,E4,E4,PP,D4,D4,PP,C4};
  // note durations: 4 = quarter note, 8 = eighth note, etc.:
  int noteDurations[] = { 8,8,8,8,8,4,
                        8,8,8,8,8,4,
                        8,8,8,8,8,4,
                        8,8,8,8,8,4,
                        8,8,8,8,8,4};
  player.midiWriteData(0xC0, 1, 0); // Select instrument
 
  for (int thisNote = 0; thisNote < 24; thisNote++) {
    if (melody[thisNote]==PP) // Pause
      delay (50);
   else {
      player.midiNoteOn(0, melody[thisNote], 127);
      delay (250);
      player.midiNoteOff(0, melody[thisNote], 127);
      Serial.println (melody[thisNote]);
    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
      delay (200);
    }
  }
 
 
}

// Initializes MIDI
void midiInit(){
  player.beginInMidiFmt();
  player.midiWriteData(0xB0, 0x07, 120); // Set MIDI channel volume
}

// Sets MIDI bank to GM1 or GM2. Takes values 1 or 2
void setMIDIBank(byte bank) {
if (bank==1) player.midiWriteData(0xB0, 0, 0x00);  // Select bank GM1
else player.midiWriteData(0xB0, 0, 0x78);  // Select bank GM2
}
Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, etc.

Pitchoilcan

I tried it, but didn't hear any tone.
Looking in Pin_config.h I see

Code: [Select]
//////////////////////for vs10xx///////////////////////////////////
#define VS_XRESET A0
#define VS_DREQ   A1
#define VS_XDCS   A2
#define VS_XCS    A3

which looks incorrect to me, my shield has

X_RESET  D8
DREQ  D2
XDCS  D7
XCS  D6
CS  D9

Should I go ahead and edit those defines?
================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

Pitchoilcan

Horray! Finally I hear some tones.  :D
Thanks much Braton
changes defines in pin_config.h to
Quote
//////////////////////for vs10xx///////////////////////////////////
#define VS_XRESET 8
#define VS_DREQ   2
#define VS_XDCS   7
#define VS_XCS    6

================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

bratan

Xronos Clock - A talking arduino based alarm clock is now available. Check out xronosclock.com for pictures, source code, schematics, etc.

Go Up