Trouble installing Teensyduino

Status
Not open for further replies.
Added two buttons and a pot.

I changed them and it's working but like one of those optical illusions that looks like an old woman and a young woman, I"m only seeing it one way. So thanks! I'm sure I'll get into trouble again very quickly.

Okay, next step is to add two buttons, program one of them to decrease the midi note value (defined as an integer, number 61, which corresponds to the note c# which is the note the wind instrument plays when no buttons are pushed. The two buttons I've added decrement this number by either 1 or 2. ButtonA is linked to digital pin 6, and ButtonB is linked to digital pin 9. The code compiles and acts like the buttons are always being pressed. That is, its starts on the note C# (midi note number 61), and decrements by three each time, because it thinks for some reason the buttons are being pressed. I read on an arduino page that the buttons need pullup resistors. I wasn't sure which ones to use, but read further that the code could emulate a resistor if you use "PULLUP" in the code. I also verified that the button is wired correctly, that is never straight across but diagonally. One side of button is linked to AGND, and the other , either 6 or 9.

So why does the teensy always return a pin state of HIGH whether button is pressed or not?
Here are some pictures: midi port with two buttons.jpgMidi Output with two buttons.png




#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
// constants won't change.
const int channel =1; // They're used here to set pin numbers:
const int buttonPinA = 6; // the number of the pushbutton pin
const int buttonPinB = 9; // the number of the pushbutton pin

// variables will change:
int buttonStateA = 0; // variable for reading the pushbuttonA status
int buttonStateB = 0; // variable for reading the pushbuttonB status

int note = 61; //C# (no fingers pressed.)

void setup() {

MIDI.begin(MIDI_CHANNEL_OFF);

pinMode(buttonPinA, INPUT_PULLUP); // initialize the pushbutton pins as an inputs:
pinMode(buttonPinB, INPUT_PULLUP);

}

void loop()
{

buttonStateA = digitalRead(buttonPinA);
if (buttonStateA == HIGH)
{ note = note -1; }

buttonStateB = digitalRead(buttonPinB);
if (buttonStateB == HIGH)
{note = note -2; }

MIDI.sendNoteOn(note, 100, channel);
delay(200);
MIDI.sendNoteOff(note, 100, channel);


delay(1000);
}
 

Attachments

  • Teensy 3.2 with midi out port.jpg
    Teensy 3.2 with midi out port.jpg
    200.5 KB · Views: 30
Last edited:
Please post your code as text in code tags. Copy the code as text, hit the # icon and then paste the text. The # icon generates the code tags for you.
A screen capture of code is impossible to work with.
In message #15 where I said there's nothing wrong with your code, I had typed in all your code from message #9. Most people wouldn't do that.
Make it easy for us to help you. Use code tags.

Pete
 
Okay, I copied and pasted. I am not sure if I did it correctly because I don't know what you meant by the "#" icon. It doesn't appear color coded this way. Sorry if it is not clear.
 
So why does the teensy always return a pin state of HIGH whether button is pressed or not?

Maybe those 2 pushbuttons aren't really connected to GND? (and you really should use GND, not AGND).

Some breadboards divide their power rails into 2 segments, where the power holes on the right hand side of the breadboard connect together, but they're separate from the power holes on the left hand side. Other breadboards connect all the power holes together across the entire length of the breadboard.

Usually the segmented power types have red & blue lines printed with a gap in the middle, or they have a larger space between holes in the middle where there is no connection. Your breadboard looks like it might be that type.

As a simple quick check, just plug a wire into the power holes to bridge the 2 sides together. It they really are connected all the way across your breadboard, that will be a redundant wire which changes nothing. But if you have the segmented power type, it will make those 2 buttons magically start working!
 
I don't know what you meant by the "#" icon.

This:
sc.png

Personally, it doesn't bother me if you use the code tags or just copy code right into your message. Either way, I just copy it into an Arduino window and press CTRL-T to reformat the indenting. But if you use the code tags the white space is preserved, so other people who read this forum and don't copy the code into Arduino can view it as you originally wrote. That small extra effort while posting your message can only help if more people read your code.
 
Last edited:
Maybe those 2 pushbuttons aren't really connected to GND? (and you really should use GND, not AGND).

Some breadboards divide their power rails into 2 segments, where the power holes on the right hand side of the breadboard connect together, but they're separate from the power holes on the left hand side. Other breadboards connect all the power holes together across the entire length of the breadboard.

Usually the segmented power types have red & blue lines printed with a gap in the middle, or they have a larger space between holes in the middle where there is no connection. Your breadboard looks like it might be that type.

As a simple quick check, just plug a wire into the power holes to bridge the 2 sides together. It they really are connected all the way across your breadboard, that will be a redundant wire which changes nothing. But if you have the segmented power type, it will make those 2 buttons magically start working!


Okay, I will try GND and test my breadboard. I was under the impressing the GND was the ground used while the teensy is powered from on outside source, like a wallwart or some batteries. I then reasoned that the other ground/3.3v pairs were for powering breakout boards.
 
Hey You are right, my breadboard power rails are split. So I added little bridges and switched to GND from AGND.
A most remarkable result: Now it reads the switches as LOW or as if they aren't being pressed. I'm including the midi monitor showing a constant note of C#. But it doesn't do anything when either button is pressed.

If buttons are now grounded, and the logic is there to decrement the note (as we saw the way it behaved before) why does it do nothing when the buttons are pushed now that we've grounded them and they should therefore now work?

Weird!Untitled.pngPXL_20211021_005516676.jpg
 
Now it reads the switches as LOW or as if they aren't being pressed.

Maybe rotate the buttons 90 degrees?

Difficult to see in the photo, but those look like the normal buttons which have 4 pins. But it is just 1 switch inside. Two pairs are permanently shorted together. When you press the button, all 4 short together. Maybe you've plugged it into the breadboard in such a way that the permanently connected pairs are always connecting the Teensy pins to GND?

Also, with keep in mind the pin is supposed to read HIGH when the button is not pressed and LOW when you press it. If you think of LOW as "off", this can take some mental adjustment.
 
The other problem you will face once you get the buttons working is mechanical contact chatter.

To reliably detect the high to low transition, use the Bounce library. Click File > Examples > Teensy > USB_MIDI > Buttons to see how.
 
The other problem you will face once you get the buttons working is mechanical contact chatter.

To reliably detect the high to low transition, use the Bounce library. Click File > Examples > Teensy > USB_MIDI > Buttons to see how.

I have made a lot of progress. The buttons are working and I've added a pot to A9. I was getting almost a full range out of the pot, but it doesn't go down to 0. The lowest it will go is 2. I want the code to only push data to the midi port when the breath pressure is above 0. I put in an "if" statement, but the problem is, I don't know how to express the logic with an "else" that will cause the program to not put out any data unless the pot is > 0. As you can see, I have an "if" statement: "if sensorvalue > 5", in an attempt to squelch the stream. But I include the midi stream snapshot here to show that it is putting out midi even though it can see that the sensorvalue is < 5 (it is 2). Why is it blowing right by that command?
midi stream.png

Code:
[code]

#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
                                  // constants won't change. 
const int channel =1;             // They're used here to set pin numbers:
const int buttonPinA = 6;         // the number of the pushbutton pin
const int buttonPinB = 9;         // the number of the pushbutton pin

                              // variables will change:
int buttonStateA = 0;         // variable for reading the pushbuttonA status
int buttonStateB = 0;         // variable for reading the pushbuttonB status

int note = 61;   //C# (no fingers pressed.)

void setup() {
  
   MIDI.begin(MIDI_CHANNEL_OFF);

   pinMode(buttonPinA, INPUT_PULLUP);   // initialize the pushbutton pins as an inputs:
   pinMode(buttonPinB, INPUT_PULLUP);

}
 
 void loop()
  {
  int note = 61;
  
  int sensorValue = analogRead(A9);
  
  buttonStateA = digitalRead(buttonPinA);
  buttonStateB = digitalRead(buttonPinB);

if (sensorValue > 5);

  if (buttonStateA == LOW) 
  { note = note -1; }                                    
                                          
  if (buttonStateB == LOW)
  {note = note -2;  }
   
   MIDI.sendNoteOn(note, 100, channel);
   MIDI.sendControlChange(2, sensorValue, 1);
   delay(100);

}
[/CODE]
 
I changed them and it's working but like one of those optical illusions that looks like an old woman and a young woman, I"m only seeing it one way. So thanks! I'm sure I'll get into trouble again very quickly.


Code:
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

                                  // constants won't change. 
const int channel =1;             // They're used here to set pin numbers:
const int buttonPinA = 6;         // the number of the pushbutton pin
const int buttonPinB = 9;         // the number of the pushbutton pin

                             // variables will change:
int buttonStateA = 0;         // variable for reading the pushbuttonA status
int buttonStateB = 0;         // variable for reading the pushbuttonB status

int note = 61;   //C# (no fingers pressed.)

int lastnote = 62;


void setup() {

   MIDI.begin(MIDI_CHANNEL_OFF);

   pinMode(buttonPinA, INPUT_PULLUP);   // initialize the pushbutton pins as an inputs:
   pinMode(buttonPinB, INPUT_PULLUP);


}

 void loop()
 
 {
   
  int note = 61;
  int sensorValue = analogRead(A9);

 buttonStateA = digitalRead(buttonPinA);
 buttonStateB = digitalRead(buttonPinB);
 
if (sensorValue > 20) {


  if (buttonStateA == LOW) 
   { note = note -1; }                                    
                                          
   if (buttonStateB == LOW)
   {note = note -2;  }
   
   if (lastnote == note)  {
  
    
    MIDI.sendControlChange(2, sensorValue, 1);   //VCF (moog)
    MIDI.sendControlChange(19, sensorValue, 1);   //Volume
    delay(100); 
   
    }
   else
   
   if (sensorValue > 20) {
     
    MIDI.sendNoteOn(note, 100, channel);
    MIDI.sendControlChange(2, sensorValue, 1);
    MIDI.sendControlChange(19, sensorValue, 1);
    delay(100);
    lastnote=note;
    }

      else
   
   if (sensorValue < 20) {
     
    MIDI.sendNoteOff(note, 100, channel);

    

      }
    }
 }

midistream2pots.png

Made much further progress! You guys would be proud of me considering how little programming experience I have. I have a potentiometer standing in for a breath sensor. When I turn it I get a stream of continuous controller data and the currently fingered note at the beginnng of each stream. There seems to be a problem with my synth only playing one note over and over, though. I looked at the stream of midi data coming out of the professional AKAI EWI and they have it put out a NoteOFF message when the breath sensor goes to zero. My potentiometer is so noisy that it never zeros out, which is why my code is set to a threashold of 20: > than 20, it puts out a note, < 20, it should put out a stream of the currently fingered note, but it doesn't. I can't figure out why. Here's the code and a picture of the midi monitor. (I want it to only put out one NoteOff message but the code the way it appears here looks like it should put out a stream of them, but it doesn't. I will eventually want just one noteOFF message, but...one step at a time.

midistream2.png

Included above is a midimonitor snapshot of what the correct data stream should look like (this is from a the AKAI EWI4000, a professional instrument that plays my synth correctly), the beginning and end of each note should start with a NoteON message and end with a NoteOFF message when the breathsensor dips below a threshold, in the case of the correctly working instrument, that should be a value of 0.
 
Want to hire a programmer.

Looks like the wires may be swapped.

The green wire in your photo connects to 3.3V. That should go to pin 4 (positive), but it looks like it's wired to pin 5 (negative). Likewise for the orange wire, it should got to pin 5 (negative) but is actually wired to pin 4.

View attachment 26200

While not criitical to making MIDI work, pin 2 should connect to GND rather than AGND.



Hey Paul, perhaps I was spoiled by the quick responses I got for my first few questions. I really want to get my code working and given my skill level, it will take years before I can piece together something that is going to work well. As I said, there is a similar instrument with open source code that I can use as a model, but I don't understand most of it. I want to find a programmer who will work on an hourly basis to piece together working code to my specifications. Is there a way to find someone on this board who will do a good job?
 
Status
Not open for further replies.
Back
Top