Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 38 of 38

Thread: Trouble installing Teensyduino

  1. #26
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19

    Added two buttons and a pot.

    Quote Originally Posted by Chris Dragptta View Post
    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:Click image for larger version. 

Name:	midi port with two buttons.jpg 
Views:	12 
Size:	140.6 KB 
ID:	26234Click image for larger version. 

Name:	Midi Output with two buttons.png 
Views:	11 
Size:	151.9 KB 
ID:	26233




    #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);
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Teensy 3.2 with midi out port.jpg 
Views:	10 
Size:	200.5 KB 
ID:	26232  
    Last edited by Chris Dragptta; 10-20-2021 at 11:56 PM.

  2. #27
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,763
    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

  3. #28
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19
    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.

  4. #29
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,206
    Quote Originally Posted by Chris Dragptta View Post
    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!

  5. #30
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,206
    Quote Originally Posted by Chris Dragptta View Post
    I don't know what you meant by the "#" icon.
    This:
    Click image for larger version. 

Name:	sc.png 
Views:	7 
Size:	15.7 KB 
ID:	26235

    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 by PaulStoffregen; 10-21-2021 at 01:21 AM.

  6. #31
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19
    Quote Originally Posted by PaulStoffregen View Post
    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.

  7. #32
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19
    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!Click image for larger version. 

Name:	Untitled.png 
Views:	7 
Size:	106.2 KB 
ID:	26236Click image for larger version. 

Name:	PXL_20211021_005516676.jpg 
Views:	8 
Size:	123.0 KB 
ID:	26237

  8. #33
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,206
    Quote Originally Posted by Chris Dragptta View Post
    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.

  9. #34
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,206
    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.

  10. #35
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19
    Quote Originally Posted by PaulStoffregen View Post
    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?
    Click image for larger version. 

Name:	midi stream.png 
Views:	7 
Size:	218.9 KB 
ID:	26274

    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);
    
    }

  11. #36
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,259
    even though it can see that the sensorvalue is < 5 (it is 2). Why is it blowing right by that command?
    This command showing " > " ?? :: if (sensorValue > 5);

  12. #37
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19
    Quote Originally Posted by Chris Dragptta View Post
    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);
    
        
    
          }
        }
     }
    Click image for larger version. 

Name:	midistream2pots.png 
Views:	5 
Size:	223.1 KB 
ID:	26286

    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.

    Click image for larger version. 

Name:	midistream2.png 
Views:	4 
Size:	143.4 KB 
ID:	26287

    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.

  13. #38
    Junior Member
    Join Date
    Oct 2021
    Location
    New Jersey
    Posts
    19

    Want to hire a programmer.

    Quote Originally Posted by PaulStoffregen View Post
    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.

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •