Shop OBEX P1 Docs P2 Docs Learn Events
Midi drums — Parallax Forums

Midi drums

garylakegarylake Posts: 41
edited 2010-12-08 04:27 in Propeller 1
I want to make midi drums with the Propeller. Could anyone convert this Arduino code to Spin?

// Variables:
byte note = 0; // The MIDI note value to be played

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}

void loop() {
// play notes from F#-0 (30) to F#-5 (90):
for (note = 30; note < 90; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}

// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(byte cmd, byte data1, byte data2) {
Serial.print(cmd, BYTE);
Serial.print(data1, BYTE);
Serial.print(data2, BYTE);
}

Comments

  • hover1hover1 Posts: 1,929
    edited 2010-12-05 17:52
    garylake wrote: »
    I want to make midi drums with the Propeller. Could anyone convert this Arduino code to Spin?

    // Variables:
    byte note = 0; // The MIDI note value to be played

    void setup() {
    // Set MIDI baud rate:
    Serial.begin(31250);
    }

    void loop() {
    // play notes from F#-0 (30) to F#-5 (90):
    for (note = 30; note < 90; note ++) {
    //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
    noteOn(0x90, note, 0x45);
    delay(100);
    //Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
    noteOn(0x90, note, 0x00);
    delay(100);
    }
    }

    // plays a MIDI note. Doesn't check to see that
    // cmd is greater than 127, or that data values are less than 127:
    void noteOn(byte cmd, byte data1, byte data2) {
    Serial.print(cmd, BYTE);
    Serial.print(data1, BYTE);
    Serial.print(data2, BYTE);
    }

    Could you possibly keep the MIDI out questions to one thread? You have three threads going with the same question, and a 4th with Bob's excellent list of helpful threads:

    http://forums.parallax.com/showthread.php?127635-MIDI-Examples&highlight=MIDI

    It's hard to hit a moving target.

    Jim
  • AribaAriba Posts: 2,690
    edited 2010-12-06 03:37
    Here is the Arduino code converted to Spin. You see how similar this is, just change the syntax a bit.
    {{ MIDI Test }}
    
    CON
      _clkmode  = xtal1 + pll16x
      _xinfreq  = 5_000_000
    
      CHANNEL   = 10 - 1    'channel 10 is normally for drums
      TX_PIN    = 30
      
    VAR
      long note           'The MIDI note value to be played
    
    OBJ
      midi: "FullDuplexSerial"
      
    PUB miditest
      midi.start(31, TX_PIN, 0, 31250)   'Set MIDI baud rate and pins
    
      repeat      'play notes from F#-0 (30) to F#-5 (90):
        repeat note from 30 to 90
          'Note on channel , some note value (note), high velocity (120):
          noteOn($90+CHANNEL, note, 120)
          delay(100)
          'Note off channel, some note value (note), velocity 0 = noteOff
          noteOn($90+CHANNEL, note, 0)
          delay(100)
    
        delay(1500)
        
    ' plays a MIDI note. Doesn't check to see that
    ' cmd is greater than 127, or that data values are less than 127:
    PUB noteOn(cmd, data1, data2)
      midi.tx(cmd)
      midi.tx(data1)
      midi.tx(data2)
    
    PUB delay(ms)
      waitcnt(clkfreq/1000 * ms + cnt)
    

    This expects a board with a 5MHz crystal.
    If your synth knows the general midi standard, then the drumscan be played on channel 10, so I set this as default. I've also changed some comments and velocity values.
    If this not works, then you need to show your MIDI out circuit shematic. Depending on the Out-Pin, you need also to set the right value in the CON section.

    Andy
  • garylakegarylake Posts: 41
    edited 2010-12-06 05:31
    First I want to apologize to hover1 for putting this subject in more than one thread. I will keep it on this one.
    Next I want thank Bob and Ariba for their time and help.

    I have tried both Bob and Ariba code and it still doesn't work. Now I know the keyboard (sound module) works because I connected another keyboards midi out to midi in of the keyboard I'm using to test this. As far as the midi out circuit on the Prop goes I have it wired like this. Looking at the back of the Din 5 from left to right. Pin 1 not used, Pin 4 to a 220 ohm resistor to +5v, Pin 2 not used, Pin 5 to a 220 ohm resistor to Pin 17 on the Prop.

    I am using the Propeller Education Kit.
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2010-12-06 06:49
    You should follow the schematic that Ariba posted. It's in the info posted in the MIDI examples thread. For a start the Voltage should be 3.3 v. The only resistor required is the 100 ohm from the connector pin 4 to the prop pin. The view for his connections is looking from the front of the connector.

    (Go down to the 12-06-2009 09:28 PM #4 Ariba)


    http://forums.parallax.com/showthread.php?118144-MIDI-Output-%28Via-USB-or-MIDI%29&highlight=Midi+Schematic
  • AribaAriba Posts: 2,690
    edited 2010-12-06 07:22
    The circuit you describe is for 5V logic levels. Theoretically it may also work because the LED in the Optocoupler consumes 1.7V, but it is not for shure. The Pin numbering for this Connectors is strange (1-4-2-5-3), so a picture may help.

    MIDI is a 5mA current loop. In the original implementation with 5V levels there are 3 x 220 Ohm resistors (2 in the MIDI OUT and 1 in the MIDI IN circuit). The LED in the Optocoupler needs 1.7V when lighting, so the current is: (5V -1.7V) / 660 = 5mA.

    To adapt it to 3.3V we can only change the MIDI OUT circuit, so the LED and the 220R in the MIDI IN are given. With one 100R the current is:
    (3.3V-1.7V) / 320 = 5mA

    Andy
  • garylakegarylake Posts: 41
    edited 2010-12-08 04:27
    It works. Yes.
    It was the midi out circuit. I took Bobs advice and looked at Aribas schematic. It didn't even occur to me that the circuits I have been looking at on the internet are all for 5V microcontrollers. So that means I have to make a lot of circuit changes.

    You guys have been a big help. Thanks so much.

    Gary
Sign In or Register to comment.