# Self build Midi Controller

**URL:** <https://forum.djtechtools.com/t/self-build-midi-controller/21722>\
**Category:** Hardware: Controllers, Mods and Gear\
**Created:** [March 27, 2011, 4:03pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722 "2011-03-27T16:03:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 4:03pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/1 "2011-03-27T16:03:55Z")

</div>

**Self build Midi Controller**

Hi Guys,

I’m about building a Midicontroller. I programmed my AVR to send Midinotes. But I’m still wondering how to programm the microcontroller to send a Midinote by pressing a button a send one if I release it, such as a Cue - Button.

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 6:32pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/2 "2011-03-27T18:32:59Z")

</div>

What AVR/mcu are you using?

How many buttons do you want?

How are they connected (matrix/direct/through a shift register)?

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 6:39pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/3 "2011-03-27T18:39:29Z")

</div>

Hi Necro. Iam using a Atmega8 but I’m planing to use a 32, because I want to use the A&H 4 way eq, and the Atmega32 has 8 ADC’s for my potentiometers.  
I would love all the buttons that are used in tractor, connected to the controller. Also the rotary controlls.

But for the first time, it would be nice to use the 4 way eq.

---

<div class="post-metadata">

**Author:** ![Steve\_Zorilow](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.djtechtools.com/steve_zorilow/32/14747_2.png) [@Steve\_Zorilow](https://forum.djtechtools.com/u/Steve_Zorilow)\
**Post date:** [March 27, 2011, 6:45pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/4 "2011-03-27T18:45:41Z")

</div>

MidiFighter use Atmel and it’s open source. The source code is also really well documented. That should be more than enough to keep yourself busy for few hours 😉

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 6:53pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/5 "2011-03-27T18:53:43Z")

</div>

I don’t know where to find it 😞

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 7:01pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/6 "2011-03-27T19:01:17Z")

</div>

Yep… the MF source is AMAZINGLY well commented… I’ve hacked it apart for one of my own projects that incorporates a custom MF layout… The only thing is that it uses quite a bit of bitmath (and’s/or’s/not’s/xor’s etc), so it can be a little tough to understand if you arent well versed in boolean logic 🙂

You won’t be able to replicate all the buttons in traktor with only an atmega8 (or even a 32). As there aren’t enough inputs. There are many ways of multiplexing button inputs, shift registers (cd4021be) and matrices are the most common.

Feel free to post your ongoing questions, there’s plenty of hardcore mod’ers and hackers around here to help 🙂

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 7:02pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/7 "2011-03-27T19:02:13Z")

</div>

> [@DANrulz81](#):
>
> I don’t know where to find it 😞

Here ya go!

> **[Midifighter - Browse /Midifighter Firmware/midifighter-20110204 at...](https://sourceforge.net/projects/midifighter/files/Midifighter%20Firmware/midifighter-20110204/)**
>
> Open source firmware for the original kit set DJTechTools Midifighter. 
> 
> This is NOT compatible with Midi Fighter Classic MK2, Midi Fighter 3D,…

Download the zip file, not the compiled hex file…

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 7:09pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/8 "2011-03-27T19:09:10Z")

</div>

Hi Necro,

I’ve already simulated the play button via switch and the high eq via poti. I’ve problems with my cue button. I would like to use a 1 µC for the eq, one for the FX and so on…

I also get problems with the sourcecode: I don’t know C.

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 7:17pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/9 "2011-03-27T19:17:25Z")

</div>

what do you mean? electrically there is no difference between a play or a cue button… they’re both just buttons..

The difference comes inside traktor (or whatever midi software you’re using)…

Could you post a schematic (even if crudely drawn)? What exactly is or is not happening?

My edit to your edit: You should be able to get away with a single mcu for the whole thing… I am running a 30+ controls off a single atmega328 (that includes midi thru for 2 other controllers)

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 7:19pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/10 "2011-03-27T19:19:04Z")

</div>

When I hit the Play button, it toggles the value. When I hit the cue button, it toggles then value also. Cue stays highlighted until i press the button again.

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 7:23pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/11 "2011-03-27T19:23:27Z")

</div>

inside traktor, change the ‘Interaction Mode’ to Hold, not toggle.

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 7:39pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/12 "2011-03-27T19:39:11Z")

</div>

I tried, but it didn’t work. May be the midi note ist the wrong one, which i send via the Atmel. I’m sending Ch3 CC70.

Btw.: How do you use more than 8 Potis at the µC. It only contains 8 adcs.

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 7:48pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/13 "2011-03-27T19:48:49Z")

</div>

> [@DANrulz81](#):
>
> I tried, but it didn’t work. May be the midi note ist the wrong one, which i send via the Atmel. I’m sending Ch3 CC70.

You should be sending note-on and note-off midi messages for buttons, and CC’s for pots and faders..

> [@DANrulz81](#):
>
> Btw.: How do you use more than 8 Potis at the µC. It only contains 8 adcs.

Through the use of multiplexer ic’s! Do a search for CD4051 and its variants.

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 7:56pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/14 "2011-03-27T19:56:35Z")

</div>

Let me sum up:

If i press the button (and holding it), I should send a 0x90 00 7F. And if I release the button, I should send a 0x80 00 7F?

I’m sorry asking such silly questions, but I am a beginner in terms of midi 😞

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 8:48pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/15 "2011-03-27T20:48:09Z")

</div>

I am not used to sending direct midi messages.. I am using a midi library which makes it simple: midi.sendNoteOn(channel, note, velocity); midi.sendControlChange(channel, CC, value); etc…

A small excerpt of my code is below:

```auto
void midiStreamNote(const uint8_t pitch, const bool onoff) {
#ifdef DEBUG
uint8_t command = ((onoff)? 0x90 : 0x80);
Serial.print("cmd:");Serial.print(command >> 4,HEX); // command type 0..15
Serial.print(" ch:");Serial.print((MIDI_CHANNEL & 0x0f),DEC); // channel 0..15
Serial.print(" note:");Serial.print(pitch & 0x7f,DEC); // note 0..127
Serial.print(" vel:");Serial.println(MIDI_VELOCITY,HEX); // velocity 0..127
#else
if (onoff) {
midi.sendNoteOn(MIDI_CHANNEL, pitch & 0x7f, 0x7f);
} else {
midi.sendNoteOff(MIDI_CHANNEL, pitch & 0x7f, 0x7f);
}
#endif
}

void midiStreamCC(const uint8_t cc, const uint8_t val) {
#ifdef DEBUG
Serial.print("cmd:");Serial.print(cc,DEC); // command type 0..15
Serial.print(" ch:");Serial.print(MIDI_CHANNEL,DEC); // channel 0..15
Serial.print(" val:");Serial.print(val & 0x7f,DEC); // note 0..127
Serial.print(" vel:");Serial.println(MIDI_VELOCITY,DEC); // velocity 0..127
#else
midi.sendControlChange(MIDI_CHANNEL, cc, val);
#endif
}

```

Midi Library: [http://timothytwillman.com/itp\_blog/?page\_id=240](http://timothytwillman.com/itp_blog/?page_id=240)

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 8:52pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/16 "2011-03-27T20:52:42Z")

</div>

Hi,

i figuered it out. It works fine by pressing the button sending note on, releasing sends note off. C is a language i don’t understand, I write my software in Bascom, cause I grew up with Basic.

Thanks any way, you saved my day 😉

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 9:36pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/17 "2011-03-27T21:36:43Z")

</div>

Glad I could help 🙂

I can certainly say that I’ve never heard of Bascom… but the thought of using a basic like language for avr programming is kind of neat… Please tell me they don’t have GOTO 😉

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 27, 2011, 10:36pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/18 "2011-03-27T22:36:35Z")

</div>

Of course Bascom has GOTO, also Gosub, … 😉 All of the happy Basic stuff. Now I have to figure out, how can I mux the Potis.

---

<div class="post-metadata">

**Author:** ![DjNecro](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DjNecro](https://forum.djtechtools.com/u/DjNecro)\
**Post date:** [March 27, 2011, 11:16pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/19 "2011-03-27T23:16:20Z")

</div>

With using basic? I have no clue… are you able to do your own serial comms? most multiplexers use spi or in some cases i2c.. The 4051 should work for you.. set its 3 input select pins to select which input to read, then read the analog value from a single analog input… Here’s the code I’m using… it is C, and it’s using plenty of bitmath to be warned 😉

```auto
for(int i = 0; i < NUM_POTS; i++) {
PORTD = (NUM_POTS > 8 && i >= 8) ? (i % 8) << 2 : i << 2; // set pins 2, 3 and 4 to value between 0 (00000) and 7 (11100) to select the pot
if (i > 0 && (i % 8 == 0)) chipSelect++; // increase chip select index every 8 pots
potValues[i] = analogRead(potReadPins[chipSelect]);
if (abs(potValues[i] - prevPotValues[i]) > SMOOTHING) {
prevPotValues[i] = potValues[i];
midiStreamCC(i, map(potValues[i],5,1020,0,127));
}
}

```

---

<div class="post-metadata">

**Author:** ![DANrulz81](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DANrulz81](https://forum.djtechtools.com/u/DANrulz81)\
**Post date:** [March 28, 2011, 3:45pm UTC](https://forum.djtechtools.com/t/self-build-midi-controller/21722/20 "2011-03-28T15:45:26Z")

</div>

OMG, C is so cryptic. I got special SPI and I2C commands in bascom, for e.g.:

```auto
SPI:
portb.7 = SCL
portb.6 = MISO
portb.5= MOSI
portb.4 = SS
spiout = 11010010

```

```auto
i2c:
I2cstart
I2cwbyte &H40
I2cwbyte &HAA
I2cstop

```

I will try it as soon as possible. I got to buy some more potis and the other stuff like a 4051. Thanks anyway.

[Next page](https://forum.djtechtools.com/t/self-build-midi-controller/21722.md?page=2)
