Teensyduino

Teensyduino
Posted on: 29.03.2011 by Blair Turick
So here's the deal,

I had been running my midi controller on the arduino using code from http://www.instructables.com/id/Arca...DI-Controller/ and it was awesome. However, I had the arduino on the side and all ugly looking so i got a teensy++. With this there is more expandability and usb to midi instead of serial, but also a little confusion. I'm not new to arduino like programing but for some reason midi has got me stumped.

My big question is if anyone out there has used the teensyduino for usb midi, i'm not looking for someone to write the code for me just to help explain how to set it all up.

Here is what the makers of teensyduino give to run with:
http://pjrc.com/teensy/td_midi.html
with no examples.

This is what i have for reading one of the buttons, i still need that channel, but i'm not sure what that is lol.

Code:
if (digitalRead(PIN_D3)) {
    
  } else {
    usbMIDI.sendNoteOn(60, 127, 
  }
oh and the buttons are on pull-up resistors (low is pressed, high is released)

Thanks a lot of any help!
Arcelia Siebeneck
13.10.2011
Originally Posted by timcrawf88
do you have traktor? if so open traktor and try the midi mapping, that's how i would figure out if mine worked. Also try just straight uploading my code exactly how it is. see how that works.
Thanks Tim, that sorted it!

It seems that MIDIOX doesn't work properly if you select the Teensy as both the Midi Input and the Midi Output (I guess it gets confused - some sort of endless loop perhaps?). If you set MIDIOX so that Teensy Midi is just the Midi Input then it picks up the midi messages just fine.

Thanks for your help
Blair Turick
12.10.2011
do you have traktor? if so open traktor and try the midi mapping, that's how i would figure out if mine worked. Also try just straight uploading my code exactly how it is. see how that works.
Arcelia Siebeneck
12.10.2011
I really don't believe it's an issue with any of the sketches. I've tried at least 3 different sketches that should turn the teensy into a midi device. I've confirmed that my circuit is working okay via serial when I use the teensy as a serial usb type.

The problem seems to occur when I switch the usb type to midi. The teensy will appear as a midi device in midiox. When I reset the teensy, it will spit out loads of midi commands to midiox:



but no matter which analogue pin I attach the pot to, it simply won't output any midi in midiox! I'm totally confused about what I'm doing wrong because I seem to have eliminated every possible problem and it still doesn't work!!
Arcelia Siebeneck
12.10.2011
I just switched to your code again - the same problem

All the midi sketches cause the teensy to be recognised as a usb midi device, but midiox doesn't pick up ANY midi data when I turn the pot thats connected to A0.

This is how I've got it setup to test 1 digital and 1 analogue (using your sketch):

Code:
// Number of digital inputs. Can be anywhere from 0 to 18.
#define NUM_DI 1
// Number of analogue inputs. Can be anywhere from 0 to 6.
#define NUM_AI 1

// Number of digital inputs. Can be anywhere from 0 to 68.
//#define NUM_DI 52
// Number of analogue inputs. Can be anywhere from 0 to 16.
//#define NUM_AI 16

#ifdef MIDI_FIGHTER
  #define MIDI_CHANNEL 3
  // First note, starting from lower left button
  #define NOTE NOTE_C2
  // When mapping to a MIDI Fighter we need to skip a row of buttons. Set this from 0-3 to define which row to skip.
  // Rows are ordered from bottom to top (same as the MIDI Fighter's button layout).
  #define SKIP_ROW 2
  // This pin order corresponds to the bottom left button being zero, increasing by one as we move from left to right, bottom to top
  // 8  9 10 11
  // 4  5  6  7
  // 0  1  2  3
  // This array size must match NUM_DI above.
  //#define DIGITAL_PIN_ORDER 10, 11, 12, 13, 6, 7, 8, 9, 2, 3, 4, 5
  #define DIGITAL_PIN_ORDER 10
#else
  #define MIDI_CHANNEL 1
  // First note, starting from upper left button
  #define NOTE NOTE_C0
  // This pin order corresponds to the top left button being zero, increasing by one as we move from left to right, top to bottom
  // 0  1  2  3
  // 4  5  6  7
  // 8  9  10 11
  // This array size must match NUM_DI above.
  #define DIGITAL_PIN_ORDER PIN_D0
  //#define DIGITAL_PIN_ORDER PIN_D0, PIN_D1, PIN_D4, PIN_D5, PIN_D7, PIN_E0, PIN_E1, PIN_C0, PIN_C1, PIN_B3, PIN_B2, PIN_B1
//  #define DIGITAL_PIN_ORDER 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53
#endif

//#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5
#define ANALOGUE_PIN_ORDER A0
//#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15
#define MIDI_CC MIDI_CC_GENERAL1
Blair Turick
12.10.2011
one quick possibility is in my code i have the analog defined as so:

Code:
#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5
//#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15
#define MIDI_CC MIDI_CC_GENERAL1
and in the other one the analog is defined like this:

Code:
#elif defined(TEENSY_PLUS_PLUS)
  #define ANALOGUE_PIN_ORDER 0, 1, 2, 3, 4, 5, 6, 7
try changing the analog pin names
Blair Turick
12.10.2011
are you using the code that i modified or the code the original author put out with my changes?

Not a big deal but just giving me an idea of what code to read through.

I've never used the latter code so i'm not exactly sure how it runs, just out of curiosity if you are using the latter can you try using mine and see if you get the same error?
Arcelia Siebeneck
12.10.2011
okay, well the original author of the "Arcade Button MIDI controller" sketch has come back to me with a proper fix:

The compilation error is saying that the DIGITAL_PIN_ORDER hasn't been defined, and that the number of elements digitalInputMapping is being assigned to doesn't match the size of the array.

If you look at line 163, you'll find:
Code:
#elif defined(TEENSY_2)
#elif defined(TEENSY)
#elif defined(TEENSY_PLUS_PLUS)
Underneath #elif defined(TEENSY_2) add the following line:
Code:
#define DIGITAL_PIN_ORDER 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
So you'll now have something like:
Code:
#elif defined(TEENSY_2)
  #define DIGITAL_PIN_ORDER 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
#elif defined(TEENSY)
#elif defined(TEENSY_PLUS_PLUS)
The number of pins listed (0-12) needs to match the number of digital pins defined on line 121 (NUM_DI).

Hopefully this addresses both compilation errors.
I just tried the above and it fixed one error, but not the other.

To fix the too many initializers problem, go to line 174:
Code:
#elif defined(TEENSY_2)
#define ANALOGUE_PIN_ORDER 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
Delete the last pin from ANALOGUE_PIN_ORDER, so it now reads
Code:
#define ANALOGUE_PIN_ORDER 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
I'll update the sketch in the Instructable to reflect these changes when I have a chance.
The issue I'm having now is simply getting the Teensy to work as a midi controller! Take a look at this video which explains my problem:

http://www.youtube.com/watch?v=K0G1wCf1FRM
Arcelia Siebeneck
11.10.2011
well I've fiddled with the code a bit:

Code:
  // This array size must match NUM_DI above.
  #define DIGITAL_PIN_ORDER //PIN_D0, PIN_D1, PIN_D4, PIN_D5, PIN_D7, PIN_E0, PIN_E1, PIN_C0, PIN_C1, PIN_B3, PIN_B2, PIN_B1
//  #define DIGITAL_PIN_ORDER 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53
#endif

#define ANALOGUE_PIN_ORDER A0 //, A1, A2, A3, A4, A5
//#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15
#define MIDI_CC MIDI_CC_GENERAL1
and now it uploads okay... I presume because the array size has to match the number of pins in this section:

Code:
// Number of digital inputs. Can be anywhere from 0 to 18.
#define NUM_DI 0
// Number of analogue inputs. Can be anywhere from 0 to 6.
#define NUM_AI 1
but I'm not getting any midi data showing up in midiox when I twiddle the single pot I've got attached to A0

gonna keep fiddling...
Arcelia Siebeneck
11.10.2011
Originally Posted by timcrawf88
This is the exact code that i used (The inputs are a little screwy i believe pin 6 is the led pin on the teensy and i didn't feel like adding a pull down resistor, so i didn't use it)

http://dl.dropbox.com/u/1596228/midi...r_usb_midi.pde

after i wrote that code the original author took my changes and made a new version with the updates (a little easier to follow and customize)

http://www.instructables.com/files/o...FHGM9QL394.zip

if you need any help with the wiring lemmie know.
this is the error when I try to upload your code to a Teensy 2.0:

Code:
sketch_oct12a:156: error: 'PIN_E0' was not declared in this scope
sketch_oct12a:156: error: 'PIN_E1' was not declared in this scope
sketch_oct12a:156: error: 'PIN_C0' was not declared in this scope
sketch_oct12a:156: error: 'PIN_C1' was not declared in this scope
is it because I haven't attached any pots/buttons to my Teensy? Shouldn't the code upload okay without anything attached to the Teensy?
Arcelia Siebeneck
22.09.2011
Originally Posted by timcrawf88
This is the exact code that i used (The inputs are a little screwy i believe pin 6 is the led pin on the teensy and i didn't feel like adding a pull down resistor, so i didn't use it)

http://dl.dropbox.com/u/1596228/midi...r_usb_midi.pde

after i wrote that code the original author took my changes and made a new version with the updates (a little easier to follow and customize)

http://www.instructables.com/files/o...FHGM9QL394.zip

if you need any help with the wiring lemmie know.
does this code support 4 banks mode or any of the supercombos?

good work btw!
Blair Turick
21.04.2011
This is the exact code that i used (The inputs are a little screwy i believe pin 6 is the led pin on the teensy and i didn't feel like adding a pull down resistor, so i didn't use it)

http://dl.dropbox.com/u/1596228/midi...r_usb_midi.pde

after i wrote that code the original author took my changes and made a new version with the updates (a little easier to follow and customize)

http://www.instructables.com/files/o...FHGM9QL394.zip

if you need any help with the wiring lemmie know.
Arcelia Siebeneck
21.04.2011
Originally Posted by timcrawf88
Just put in the code for usb_midi. It works flawlessly. No plugins or other software need. Thank you, Thank you, Thank you.
would you care to show the code you used?
Irwin Ney
29.03.2011
Great way of doing it
Louisa Oberc
29.03.2011
I've taken quite a bit from various communities over the years... It's high time I give back
Joan Kollmorgen
29.03.2011
Really good to have people like you here on the community DjNecro. Always willing to share your knowledge and help others out.
Louisa Oberc
29.03.2011
WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!

HAH... I'm so happy you got it working Glad I could help!
Irwin Ney
30.03.2011
Great thread folks, nice Q&A
I'm a programmer but had never tried to build something.
Maybe I will try to program a max for live or some touch osc advanced templates in the future...

I really like when I can integrate my professional skills with my DJ hobbie
Blair Turick
30.03.2011
Just put in the code for usb_midi. It works flawlessly. No plugins or other software need. Thank you, Thank you, Thank you.
Blair Turick
29.03.2011
Hey, so i tried it all, i had to move some of the buttons around to different inputs cause it was being dumb but it works perfectly now. That is using serial. I'll have to try usb-midi when i get home.

Thanks so much for all your help

Here are some pics of the (almost) final product.

Top:


Bottom:


Just need to secure the teensy:


It's pretty snug in there but not enough.

Thanks again, ill post when i try the usb-midi
Louisa Oberc
29.03.2011
NN and good luck

Oh, and take a look at these: http://www.djranking s.com/community /sho...1&postcount=23 a great addition to any custom midi controller
Blair Turick
29.03.2011
Makes sense enough, I'll give it a shot when I get up.
Thanks
Louisa Oberc
29.03.2011
Change:
Code:
#define DIGITAL_PIN_ORDER 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
To:
Code:
#define DIGITAL_PIN_ORDER PIN_D0
PIN_D1, PIN_D2, PIN_D3, PIN_D4, PIN_D5, PIN_D6, PIN_D7, PIN_E0, PIN_E1, PIN_C0, PIN_C1, PIN_C2, PIN_C3, PIN_C4

Re: analog

Teensy seems to use the same method for pin-naming as the arduino, so you would use the pin numbers you wired them up to as per this pic:

Blair Turick
29.03.2011
Code:
// Number of digital inputs. Can be anywhere from 0 to 18.
#define NUM_DI 12
// Number of analogue inputs. Can be anywhere from 0 to 6.
#define NUM_AI 6

// Number of digital inputs. Can be anywhere from 0 to 68.
//#define NUM_DI 52
// Number of analogue inputs. Can be anywhere from 0 to 16.
//#define NUM_AI 16

#ifdef MIDI_FIGHTER
  #define MIDI_CHANNEL 3
  // First note, starting from lower left button
  #define NOTE NOTE_C2
  // When mapping to a MIDI Fighter we need to skip a row of buttons. Set this from 0-3 to define which row to skip.
  // Rows are ordered from bottom to top (same as the MIDI Fighter's button layout).
  #define SKIP_ROW 2
  // This pin order corresponds to the bottom left button being zero, increasing by one as we move from left to right, bottom to top
  // 8  9 10 11
  // 4  5  6  7
  // 0  1  2  3
  // This array size must match NUM_DI above.
  #define DIGITAL_PIN_ORDER 10, 11, 12, 13, 6, 7, 8, 9, 14, 3, 4, 5
#else
  #define MIDI_CHANNEL 1
  // First note, starting from upper left button
  #define NOTE NOTE_C0
  // This pin order corresponds to the top left button being zero, increasing by one as we move from left to right, top to bottom
  // 0  1  2  3
  // 4  5  6  7
  // 8  9  10 11
  // This array size must match NUM_DI above.
  #define DIGITAL_PIN_ORDER 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
//  #define DIGITAL_PIN_ORDER 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53
#endif

#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5
//#define ANALOGUE_PIN_ORDER A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15
#define MIDI_CC MIDI_CC_GENERAL1
This is the only section that i changed (it wouldn't let me post the entire thing)

not sure how to redefine the analog inputs in the code, but according to teensys website you can call the inputs PIN_D3 or pin 3 so theoretically it should work lol http://pjrc.com/teensy/teensyduino.html

however i just noticed that i may have analog wrong does it look like 28-35 is the analog, or 38-45 are the analog
Louisa Oberc
29.03.2011
From what I can see of the analog part... there doesn't seem to be any difference between arduino and teensy... so just make sure your pin assignments are correct and it should work... if not, try to explain what exactly is happening with the analog part...

But for now, leave them completely disconnected, focus on getting the buttons to work properly first..
Louisa Oberc
29.03.2011
Originally Posted by timcrawf88
Thanks for the code I'll have to give it a shot in the morning. Where would that go in the existing code?

I believe that all of my pin assignments are correct. I only found 2 spots where I had to change the pin numbers in the code. Is there somthing I should change for the analog?
You'd replace the existing code block with what I posted... or to learn what I did, just compare the differences... All I did was add one line, and remove 3...

Could you post a complete copy of YOUR code (make sure to use the # button to wrap it in [ code ] tags)
Louisa Oberc
29.03.2011
Ok... so... from what I can see, you need to refer to the teensy pins by their constants (PIN_D0, PIN_C1, etc...) arduino just uses the numbers, 2, 3, 4, 5, etc... so at the top of the code you will have to change the DIGITAL_PIN_ORDER define to the correct values...

Which you can find here: http://pjrc.com/teensy/td_digital.html

Pay attention to the midi fighter section, if you want to use it, make sure you wire the buttons right, OR specify the buttons in the correct order for the MF part to send the right notes (it should work regardless, it'll just be sending the wrong notes compared to a MF)

For the internal pullups, make sure you have the INPUT_PULLUP teensy extension is installed (no clue what the heck that is... never used a teensy before)..

As for analogue, I'm not sure... I haven't read the analogue section of the teensy docs yet...
Blair Turick
29.03.2011
I left that commeted I'm not using it in midi fighter mode
Blair Turick
29.03.2011
Thanks for the code I'll have to give it a shot in the morning. Where would that go in the existing code?

I believe that all of my pin assignments are correct. I only found 2 spots where I had to change the pin numbers in the code. Is there somthing I should change for the analog?
Louisa Oberc
29.03.2011
Important question: Are you using the code in midifighter mode? In other words, what is the current state of the following code

Code:
// Uncomment this line to enable outputs corresponding to the MIDI Fighter so MF mappings can be used in Traktor.
//#define MIDI_FIGHTER
Louisa Oberc
29.03.2011
Without knowing any of the potential differences between an arduino and a teensy, the following should be all you need to make the code work with the usbmidi of the teensy (side note, I am LOVING how he deals with the analog inputs... very clever, I'm certainly going to poke around to fully understand things)...

I cannot see any reason why the code wouldn't work as is with the teensy... did you make sure you have all the pin assignments correct?

Code:
void noteOn(int channel, int pitch, int velocity)
{
  // 0x90 is the first of 16 note on channels. Subtract one to go from MIDI's 1-16 channels to 0-15
  channel += 0x90 - 1;
  
  // Ensure we're between channels 1 and 16 for a note on message
  if (channel >= 0x90 && channel <= 0x9F)
  {
    #ifdef DEBUG
      Serial.print("Button pressed: ");
      Serial.println(pitch);
    #else
      usbMIDI.sendNoteOn(pitch, velocity, channel)
    #endif
  }
}

// Send a MIDI note off message
void noteOff(int channel, int pitch)
{
  // 0x80 is the first of 16 note off channels. Subtract one to go from MIDI's 1-16 channels to 0-15
  channel += 0x80 - 1;
  
  // Ensure we're between channels 1 and 16 for a note off message
  if (channel >= 0x80 && channel <= 0x8F)
  {
    #ifdef DEBUG
      Serial.print("Button released: ");
      Serial.println(pitch);
    #else 
      usbMIDI.sendNoteOff(pitch, 0x00, channel)
    #endif
  }
}

// Send a MIDI control change message
void controlChange(int channel, int control, int value)
{
  // 0xB0 is the first of 16 control change channels. Subtract one to go from MIDI's 1-16 channels to 0-15
  channel += 0xB0 - 1;
  
  // Ensure we're between channels 1 and 16 for a CC message
  if (channel >= 0xB0 && channel <= 0xBF)
  {
    #ifdef DEBUG
      Serial.print(control - MIDI_CC);
      Serial.print(": ");
      Serial.println(value);
    #else
      usbMIDI.sendControlChange(control, value, channel)      
    #endif
  }
}
Blair Turick
29.03.2011
Some of the pins are sending 2 different notes one when I press it down and a different when I release. While pin 6 isn't working at all, but I believe I just need to add an external pull down cause if the led. Also I'm having a hard time getting analog to work. If it helps I have the buttons hooked up to pins 3-14 for the digital inputs.
Louisa Oberc
29.03.2011
what problems are you facing exactly? It may be as simple as changing the pin assignments...
Blair Turick
29.03.2011
That it is, I've been trying to break it up so I can understand it and understand why the teensy is having trouble with it.
Louisa Oberc
29.03.2011
Upon first glance, that code is very well written... its certainly a good starting point...
Blair Turick
29.03.2011
thanks a lot.

any ideas why, some of the pins aren't working right?

and good luck getting that mix done!
Louisa Oberc
29.03.2011
I'll look in a bit... i'm currently recording (or attempting to record) a 10 min mix... but for now try getting your previous code to work as is on the teensy... assuming that is possible, then it should be a simple matter of swapping out the code that deals with sending midi messages.
Blair Turick
29.03.2011
honestly, the code i've been using confuses the hell out of me.

like i said i got it off instructables, so i've never really had to fiddle with it. However i did try just using the teensy as serial with this program and it still wouldn't work correctly. for example analog wouldn't work at all and pin 6 wouldn't work, i believe it has something to do with teensys led on that pin.

I wouldn't mind if i still had to use serial, as long as i can get it to work.

if you have any insight i would greatly appricate it.

http://www.instructables.com/id/Arca...7/Programming/

The code is a download on the link if you wouldn't mind looking.
Louisa Oberc
29.03.2011
If your code works on an arduino... it should work perfectly on the teensy... just substitute the old midi code with the new usbmidi code...
Blair Turick
29.03.2011
well don't i feel stupid lol.

Thanks, do you know about any of the things that need to be included in the setup, right now i just have defining all the inputs as pull-ups

Code:
void setup()
{
  pinMode(PIN_D3, INPUT_PULLUP);
  pinMode(PIN_D4, INPUT_PULLUP);
  pinMode(PIN_D5, INPUT_PULLUP);
  pinMode(PIN_D6, INPUT_PULLUP);
  pinMode(PIN_D7, INPUT_PULLUP);
  pinMode(PIN_E0, INPUT_PULLUP);
  pinMode(PIN_E1, INPUT_PULLUP);
  pinMode(PIN_C0, INPUT_PULLUP);
  pinMode(PIN_C1, INPUT_PULLUP);
  pinMode(PIN_C2, INPUT_PULLUP);
  pinMode(PIN_C3, INPUT_PULLUP);
  pinMode(PIN_C4, INPUT_PULLUP);
}
Louisa Oberc
29.03.2011
The channel is just the midi channel you want to send the message on... Channels 1-16 are available...

<< Back to Reviews of DJ equipment Reply

Copyright 2012-2023
DJRANKINGS.ORG n.g.o.
Chuo-ku, Osaka, Japan

Created by Ajaxel CMS

Terms & Privacy