Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 16 of 16

Thread: Interrupt on teensy 4.0 + Adafruits Neotrellis

  1. #1
    Junior Member
    Join Date
    Oct 2021
    Posts
    8

    Interrupt on teensy 4.0 + Adafruits Neotrellis

    Hi all.

    Im using Teensy 4.0 to control Adafruits Neotrellis 16 LEd/button board programing it with Arduino Ide

    All works fine with the Adafruit example but the interrupt function ( it works fine with an arduino uno board)


    HTML Code:
    /* This example shows basic usage of the NeoTrellis
      with the interrupt pin.
      The buttons will light up various colors when pressed.
    */
    
    #include "Adafruit_NeoTrellis.h"
    
    Adafruit_NeoTrellis trellis;
    
    #define INT_PIN 8
    
    // Input a value 0 to 255 to get a color value.
    // The colors are a transition r - g - b - back to r.
    uint32_t Wheel(byte WheelPos) {
      if(WheelPos < 85) {
       return trellis.pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
      } else if(WheelPos < 170) {
       WheelPos -= 85;
       return trellis.pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
      } else {
       WheelPos -= 170;
       return trellis.pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
      }
    }
    
    //define a callback for key presses
    TrellisCallback blink(keyEvent evt){
      
      if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING)
        trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
      else if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING)
        trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
        
      trellis.pixels.show();
      return 0;
    }
    
    void setup() {
      Serial.begin(9600);
      //while(!Serial);
    
      pinMode(INT_PIN, INPUT);
      
      if(!trellis.begin()){
        Serial.println("could not start trellis");
        while(1);
      }
      else{
        Serial.println("trellis started");
      }
    
      //activate all keys and set callbacks
      for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
        trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
        trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
        trellis.registerCallback(i, blink);
      }
    
      //do a little animation to show we're on
      for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
        trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
        trellis.pixels.show();
        delay(50);
      }
      for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
        trellis.pixels.setPixelColor(i, 0x000000);
        trellis.pixels.show();
        delay(50);
      }
    }
    
    void loop() {
      if(!digitalRead(INT_PIN)){
        Serial.println("Hello");
      }
      delay(2);
    }


    When I press the button I get "Hello" printed continuosly but when I let it go it keeps printing.

    any idea?

  2. #2
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    239
    Just wired up a Neotrellis to a T4 and using the above sketch get the same result so I did this :-
    Code:
    void loop() {
      if(!digitalRead(INT_PIN)){
        trellis.read(false); //This line is in the library example
        Serial.println("Hello");
      }
      delay(2);
    }
    and now the pressed button lights when pressed and the serial monitor prints Hello once when the button is either pressed or released. Hope that helps.

  3. #3
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Thanks for the answer.

    I try


    HTML Code:
    void loop() {
      if(!digitalRead(INT_PIN)){
        trellis.read(false);
      }

    and I get



    HTML Code:
    Sketch: In function 'void loop()':
    Sketch:107: error: no matching function for call to 'Adafruit_MultiTrellis::read(bool)'
         trellis.read(false); //This line is in the library example
                           ^
    In file included from C:\Users\Moris\Desktop\Sketch\Sketch.ino:1:0:
    C:\Users\Moris\Documents\Arduino\libraries\Adafruit_seesaw_Library/Adafruit_NeoTrellis.h:85:8: note: candidate: void Adafruit_MultiTrellis::read()
       void read();
            ^
    C:\Users\Moris\Documents\Arduino\libraries\Adafruit_seesaw_Library/Adafruit_NeoTrellis.h:85:8: note:   candidate expects 0 arguments, 1 provided
    Sketch: In function 'void (* blink(keyEvent))(keyEvent)':
    Sketch:45: warning: control reaches end of non-void function 
     }
     ^
    no matching function for call to 'Adafruit_MultiTrellis::read(bool)'
    Sorry for my lack of knowledge. Im not a programmer, im trying to build a controller for a synth

  4. #4
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    239
    Code:
    delay(2);  //Is missing
    }  // and more importantly, loop() needs this closing brace
    I'm using some Neotrellis as a controller for a Synth controller.

  5. #5
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    It works!!!!

    Thank you!!!

    Made my day. Have a good one!

  6. #6
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Victory too soon.

    I have new data.

    Now sometimes does print Hello just once and sometimes keeps printing. When it keeps printing, sometimes, when I press again stops again.

    Tha would mean its not a code problem and more of a hardware thing?

  7. #7
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    239
    A good pic of your setup and some idea of what you are trying to achieve might be helpful.

    My setup uses a 15v wallwart and a 2.1 Amp 5v switchmode supply and a brownout can derail the Neotrellis but not necessarily the T4.0 that drives them.

    For testing your code here I'm using a single Neotrellis connected to a T3.2 or 4.1 and powered via usb cable from laptop. Both combinations are fussy about cable length. Keep it short.

    Neotrellises will misbehave if they don't get a clean startup.

  8. #8
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Thank you for that.

    I have 32 Neotrellis boards soldered together in a 4x8 grid with a 5v 20 amp supply.

    Im closing in to the problem.

    I try the Multitrellis Adafruits example (mine has additional problems i guess)

    If I load 16 boards (even thou they are all soldered together) interrupt works perfect. If I load more boards the error starts to pop up.


    Im with this proyect for a time now. When I was trying an Arduino mega board, having other problems, different people told that the entire grid had too many pullup resistors, each board has 10k pullup. So I unsoldered half of them with no differnece in behaviour. Thay suggested to unsolder 3/4

    Could that thing be affecting the interrupt?

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,057
    Oh, now I *really* want to see a photo!


    Could that thing be affecting the interrupt?
    Very difficult to know without seeing the signal on an oscilloscope.

  10. #10
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    239
    Have you tried an external pullup resistor to +3.3v on the interrupt pin? Suggesting 2k2.

    Are you using the latest SeeSaw library? Was updated a few months ago.

  11. #11
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Quote Originally Posted by PaulStoffregen View Post
    Oh, now I *really* want to see a photo!




    Very difficult to know without seeing the signal on an oscilloscope.

    Click image for larger version. 

Name:	Neotrellis.jpg 
Views:	6 
Size:	60.1 KB 
ID:	26169


    Some extra characters

  12. #12
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Quote Originally Posted by MatrixRat View Post
    Have you tried an external pullup resistor to +3.3v on the interrupt pin? Suggesting 2k2.

    Are you using the latest SeeSaw library? Was updated a few months ago.

    Yes. The latest library.


    Any pin on the teensy is good for interrupt?

  13. #13
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    239
    Any digital pin should be Ok. for Int. Not using Int here, only using 4x Neotrellis configured as 8x8.

    I found this:-

    https://www.state-of-the-art.io/proj...di-controller/

    Using an 8x3 grid of Neotrellisess, you might like to play with.
    Last edited by defragster; 10-14-2021 at 12:12 AM. Reason: fix link

  14. #14
    Junior Member
    Join Date
    Oct 2021
    Posts
    8
    Cant load the link

  15. #15
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,081
    Quote Originally Posted by Moris526 View Post
    Cant load the link
    Just missing www. : www.state-of-the-art.io/projects/matrix-midi-controller/

  16. #16
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    239
    Thank you Defragster.

    @Moris526, in the Multirellis example's void setup() we have this:-
    Code:
    void setup() {
      Serial.begin(9600);
      //while(!Serial);
    
      if(!trellis.begin()){
        Serial.println("failed to begin trellis");
        while(1);
      }
    
      /* the array can be addressed as x,y or with the key number */
      for(int i=0; i<Y_DIM*X_DIM; i++){
          trellis.setPixelColor(i, Wheel(map(i, 0, X_DIM*Y_DIM, 0, 255))); //addressed with keynum
          trellis.show();
          delay(50);
      }
      
      for(int y=0; y<Y_DIM; y++){
        for(int x=0; x<X_DIM; x++){
          //activate rising and falling edges on all keys
          trellis.activateKey(x, y, SEESAW_KEYPAD_EDGE_RISING, true);
          trellis.activateKey(x, y, SEESAW_KEYPAD_EDGE_FALLING, true);
          trellis.registerCallback(x, y, blink);
          trellis.setPixelColor(x, y, 0x000000); //addressed with x,y
          trellis.show(); //show all LEDs
          delay(50);
        }
      }
    
    }
    You might try:-
    Code:
    void setup() {
      Serial.begin(9600);
      //while(!Serial);
    
      if(!trellis.begin()){
        Serial.println("failed to begin trellis");
        while(1);
      }
    
      /* the array can be addressed as x,y or with the key number */
      for(int i=0; i<Y_DIM*X_DIM; i++){
          trellis.setPixelColor(i, Wheel(map(i, 0, X_DIM*Y_DIM, 0, 255))); //addressed with keynum
          trellis.show();
          delay(50);
      }
      
      for(int y=0; y<Y_DIM; y++){
        for(int x=0; x<X_DIM; x++){
          //activate rising and falling edges on all keys
          trellis.activateKey(x, y, SEESAW_KEYPAD_EDGE_RISING, true);
          trellis.activateKey(x, y, SEESAW_KEYPAD_EDGE_FALLING, true);
          trellis.registerCallback(x, y, blink);
          trellis.setPixelColor(x, y, 0x000000); //addressed with x,y
        }
      }
      trellis.show(); //show all LEDs
      delay(50);
    }
    Sorted out my issue with getting the second block working, with or without using the Int pin

Posting Permissions

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