Pages: [1]   Go Down
Author Topic: MIDI to relay help... (glockenspiel pde)  (Read 1608 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm an uber-beginner, so please bear with me. I'm trying to convert MIDI to serial to control a set of four relays for a guitar amp switcher. The goal is to make the circuit as compact as possible, and eventually burning the bootloader onto a separate atmega chip, so I can use the Arduino (Uno rev3) for other projects.

Anyway, after a few days of getting my feet wet, checking out various peoples' projects, and ordering some parts, I've come to a brick wall.

Long story short, I'm using the MIDI glockenspiel as the main concept (sketch and MIDI input). Although I'm using a 6N138, instead of 6N139.
http://www.thebox.myzen.co.uk/Hardware/Glockenspiel.html

This is the relay:
http://www.sainsmart.com/4-channel-5v-relay-module-for-pic-arm-avr-dsp-arduino-msp430-ttl-logic.html

When power is applied, the relay is on at all times (using output any of pins 2-9 to input 1-4 on the relay), and no MIDI appears to be getting transferred. The wiring appears to be correct, after numerous checks, and I've tested the MIDI_Basic_IO and MIDI_Input sketches - both display MIDI activity on the TX led.

Any pieces of advice or changes to that glockenspiel sketch to get this going? Thanks.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My guess is that you need to start with just one relay at a time. Hook up your ins ground Vcc and in1 should be your midi output signal, to create that signal you will need your code to signal a message to turn on in1. Showing your code would definitely help. but usually in midi the basic is that an input trigger with a 10k resister to an analog input will send a message. but this is all very general info, you can also use the digital inputs it all depends on your code, also notice the the 3 outputs of each relay one is always closed and one is always open and closed only when activated. so post your code you should get more help and your schematic if you can, if you haven't found it already there's a free product called fritzing easily found on Google to help you build circuits using actual parts, and then creates a schematic for you, and will even allow you to pay them to make you a pcb board, which i here is pretty good quality, but its a nice program, if you don't have it, I believe its cross platform and its opensource. Hope I may have helped a little, and with some more info, im sure some one with more experience will help, good luck!
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the heads up on Fritzing - I was wondering how people were making their diagrams.  smiley

Here's what's going on:
https://dl.dropbox.com/u/324863/ArduinoMidi01.jpg

And the sketch I'm messing around with. Here's the un-altered original:
Code:
/* Midi Glock - Mike Cook April 2008
 *  based on code by kuki
 * -----------------
 * listen for MIDI serial data, and fire solenoids for individual notes
 
#####################################################################################################################################################

HARDWARE NOTE:
The MIDI Socket is connected to arduino RX through an opto-isolator to invert the MIDI signal and seperate the circuits of individual instruments.
Connect the 8 solenoids to pin2 to pin9 on your arduino and pin 13 to the drive enabling monostable.

####################################################################################################################################################
*/

//variables setup

  byte incomingByte;
  byte note;
  byte velocity;
  int noteDown = LOW;
  int state=0;  // state machine variable 0 = command waiting : 1 = note waitin : 2 = velocity waiting
  int baseNote = 60;  // lowest note
  // use different values of baseNote to select the MIDI octiave
  // 24 for octiave 1 -- 36 for octiave 2 -- 48 for octiave 3 -- 60 for octiave 4 -- 72 for octiave 5
  // 84 for octiave 6 -- 96 for octiave 7
 
// play only notes in the key of C (that is no sharps or flats) define pin numbers:-
  byte playArray[] =    { 2,  0,  3,  0,  4,  5,  0,  6,  0,  7,  0,  8,  9 };
// corrisponding to note 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48 - for base note = 36 or C2
int strobe = 13;   // select the pin for the monostable
int channel = 1; // MIDI channel to respond to (in this case channel 2) chnage this to change the channel number
                 // MIDI channel = the value in 'channel' + 1

//setup: declaring iputs and outputs and begin serial
void setup() {
  pinMode(strobe,OUTPUT);   // declare the strobe pin as output
  pinMode(2,OUTPUT);        // declare the solenoid's pins as outputs
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  state = 0;  // initilise state machine variable
  //start serial with MIDI baudrate 31250 or 38400 for debugging
  Serial.begin(31250);       
  digitalWrite(strobe,LOW); 
}

//loop: wait for serial data, and interpret the message
void loop () {

  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
     digitalWrite(strobe,LOW);    // clear any previous strobe
   switch (state){
      case 0:
    // look for as status-byte, our channel, note on
    if (incomingByte== (144 | channel)){
         noteDown = HIGH;
         state=1;
        }
    // look for as status-byte, our channel, note off
    if (incomingByte== (128 | channel)){
         noteDown = LOW;
         state=1;
        }
       
       case 1:
       // get the note to play or stop
       if(incomingByte < 128) {
          note=incomingByte;
          state=2;
       }
       else{
       state = 0;  // reset state machine as this should be a note number
       }
       break;
       
       case 2:
       // get the velocity
       if(incomingByte < 128) {
         playNote(note, incomingByte, noteDown); // fire off the solenoid
       }
         state = 0;  // reset state machine to start           
     }
  }
}

void playNote(byte note, byte velocity, int down){
  // if velocity = 0 on a 'Note ON' command, treat it as a note off
  if ((down == HIGH) && (velocity == 0)){
      down = LOW;
  }
 //since we can't play all notes we only action notes between 36 & 49
 if(note>=baseNote && note<(baseNote + 13)){
   byte myPin=playArray[note-baseNote]; // to get a pin number between 2 and 9
   if(myPin != 0) {
     digitalWrite(myPin, down); // play it if it is one of our notes
     if(down == HIGH) digitalWrite(strobe, HIGH); // strobe high to monostable for note on
   }
 }

}

It's a bit frustrating, because it seems as though there are a few people out there, who have been able to use that same sketch without changing anything.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well looks like you got the hang of fritzing! it a good tool, Now im just making sure that you do relize that where you have the D2 pin on the output of the arduino, you will need to hook each Dpin up to a relay IN so you have 4 relays you will need 4 more relays 8 in total if your going to use all 8 solenoids and all 8 Digital outputs D2~D9, right now you only have 1 active solenoid (D2 to IN1).
You may already know all this and just did a basic example on fritzing, but as you said you are new to this so you may not know? Ive been at it for about 6 months so im no guru but you will learn quickly. does that make sense to you so far you would use another wire to do from arduino D3 to IN2 on your relay board, and so on until you get to IN4 on your relay board, at witch point you will need more relays.

One other thing that makes me wonder is how much current the solenoids use, and if your powering them from a different power source, because you may be pushing the limits of a USB or even a 9 volt for that mater, depending on the power requirements of the solenoids.

Also if your just using one solenoid for now to try and get things running, looking at the code it says 2008, sometimes sketches work differently with different versions of the arduino IDE, if your using the newest version, V1.01 or even V1.0 I find V023 is a good stable version, and use it quite a bit, actually. you may even go back a little bit further and try V019 or so. If your using windows 7 some where around version 018~016 it stops working, I had some code I wanted to use, and it was based on V014 and would not load, so I downloaded every version up to about 017 I think b4 it would actually load up on windows 7 and the code was not compatible. I mention this because ive had programs compile with no errors, and not work in real life, then I would try it on a different version and it would work.

So their is some more ideas for you,and im sure others will chime in eventually with more help, I would look  to see what version of the IDE the code is working on for others sometimes the mention it in their posts.

Hope this may have helped. If not maybe you learned something?
Good luck
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the informative post.

Yes, I know the original sketch uses 8 solenoids, but I'm just firing off 4 relays.

I'll look into the IDE version stuff.

EDIT: Ok, using the versions that had the Uno as a selectable device (0020), I'm getting the same results (relay always activated, no MIDI activity).
« Last Edit: October 12, 2012, 07:39:10 pm by BenCJ » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just thought I'd chime in and report that there was an issue with the hardware.

This setup worked, which I found on instructables:
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad you figured ut out!, I am learning some midi stuff myself, and the theory of relays is interesting, glad I could help even if just a little.
Most important to me is that you got it figured out, and posted results. People forget that when you get your project fix, or figured out to post how you did it, just think of all the people your answer might help. To me nothing worse, then when Im reading a forum post, and i see all my similar issues, and the last post is, never mind i figured it out, no schematic like you posted, or any hint! It would be cool, if you ever end up putting it on you tube or anywhere to post a link, id be interested in your finished project. Or feel free to do an article or example on my site rduino.com I have been very slow at posting to it. mostly because I do not document man of my projects!
HANKENSTIEN
rduino.com
Logged

Pages: [1]   Go Up
Jump to: