0

Debouncing a NeoTrellis RGB PCB?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Mon Mar 01, 2021 12:59 pm

Hello there! I have recently constructed both the 4x4 and 8x8 NeoTrellis kits, and they are fantastic. I am running into an issue with both kits though, where if my finger presses certain buttons not exactly on the center of the keypad (so kind of towards the edge of a key), it will accidentally light up and activate other lights/buttons in that key's row as well. I was thinking this was perhaps something to do with me not debouncing the button presses well enough in the code, but for the life of me I can't seem to get it right. Has anyone else run into this issue, or does anyone have any ideas how this could be avoided or fixed? Any help would be much appreciated. Thank you so much!

Cheers,
Nathan

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by dastels on Mon Mar 01, 2021 1:29 pm

What other lights/buttons? 1 or more? Adjacent to what you try to pres? On one side or both? On the side that your finger is on, on the button you mean to press? Lack of debouncing shouldn't cause that. Speaking of which, how are you debouncing it? Only certain buttons? Which buttons?

Dave

dastels
 
Posts: 6494
Joined: Tue Oct 20, 2015 3:22 pm

Re: Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Mon Mar 01, 2021 2:11 pm

Hi Dave, thanks for replying!

So it only happens on buttons that share a column with the button I'm originally trying to press. It looks to be only the column that is on the particular Trellis board that the button was pressed on (so for the 8x8 build, it only happens on the 4 buttons that share the column with the button I pressed on that single Trellis board, not the entire column of the arrayed Trellis boards). What it looks like to me is if I'm even slightly off-center pressing certain buttons, say the second button down in the first column, the button I pressed activates and lights up, but so do the other buttons in that column (albeit erratically), so if I press a button a little bit more on the edge of the keypad rather than directly in the center, it's making the entire keypad column make contact with the board, thereby activating the lights and button functions that I've got running. I hope that makes sense. I'm just not really sure how to fix it. As for my current debouncing, I've just got a slight delay in my loop like I would have in most functions for debouncing, but I've tried adding delays in different places in my code, and nothing fixes this particular problem. Any suggestions or help would be appreciated, thanks!!

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by dastels on Mon Mar 01, 2021 2:27 pm

Can you post your code?

Do you actually see the other keypresses in the code, or just the lights?

Dave

dastels
 
Posts: 6494
Joined: Tue Oct 20, 2015 3:22 pm

Re: Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Mon Mar 01, 2021 2:33 pm

Sure! I've just built on the basic NeoTrellis example that I got from the SeeSaw library. I'm also using the Feather M0 Bluefruit board for BLE MIDI capabilities, so that's all the extra stuff in there.

And its both lights and keypresses, as each time the other buttons light up in the originally button's column, I'm getting the corresponding MIDI notes and functions as well.

Also, I apologize for my sloppy coding, I'm not a professional programmer, so I apologize for its messiness and lack of commenting.

Code: Select all | TOGGLE FULL SIZE
/* This example shows basic usage of the NeoTrellis.
  The buttons will light up various colors when pressed.
  The interrupt pin is not used in this example.
*/
#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
#include "Adafruit_BluefruitLE_UART.h"
#include "Adafruit_BLEMIDI.h"
#if SOFTWARE_SERIAL_AVAILABLE
#include <SoftwareSerial.h>
#endif

#include "BluefruitConfig.h"
#define CHANNEL 1
#define FACTORYRESET_ENABLE         1
#define MINIMUM_FIRMWARE_VERSION    "0.7.0"
#include "Adafruit_NeoTrellis.h"
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
Adafruit_BLEMIDI midi(ble);
bool isConnected = false;
// A small helper
void error(const __FlashStringHelper*err) {
  Serial.println(err);
  while (1);
}

// callback
void connected(void)
{
  isConnected = true;

  Serial.println(F(" CONNECTED!"));
  delay(1000);

}

void disconnected(void)
{
  Serial.println("disconnected");
  isConnected = false;
}
#define BNO055_SAMPLERATE_DELAY_MS (10)
#define MOMENTARY false
#define TOGGLE true
bool toggleStates[16];
int buttonModeChoice = false;
const int VBATPIN = A7;
bool battCheck = false;

Adafruit_NeoTrellis trellis;


TrellisCallback momentary(keyEvent evt) {
  if (buttonModeChoice == MOMENTARY) {
    //Serial.println("buttonModeChoice is now MOMENTARY");
    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
      toggleStates[evt.bit.NUM] = true;
      midi.send(0x90, evt.bit.NUM, 127);
      //Serial.println("i'm on");
    }
    else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
      trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
      toggleStates[evt.bit.NUM] = false;
      midi.send(0x80, evt.bit.NUM, 0);
      //Serial.println("i'm off");
    }

  }
  else if (buttonModeChoice == TOGGLE) {
    //Serial.println("buttonModeChoice is now TOGGLE");
    if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
      toggleStates[evt.bit.NUM] = !toggleStates[evt.bit.NUM];
      trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
      if (toggleStates[evt.bit.NUM] == true) {
           midi.send(0x90, evt.bit.NUM, 127);
      }
      else{
           trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
           midi.send(0x80, evt.bit.NUM, 0);
      }
       
    }
//    else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
//     
//    }
  }

 
  trellis.pixels.show();
  delay(1);
  return 0;
}





void BleMidiRX(uint16_t timestamp, uint8_t status, uint8_t byte1, uint8_t byte2) {
  if (status == 0x90) {

    if (int(byte1) == 126) {   //momentary mode
      buttonModeChoice = MOMENTARY;
      //Serial.println("i'm in momentary mode now");

      //trellis.unregisterCallback(i, toggle);

    }
    if (int(byte1) == 127) {   //toggle mode
      buttonModeChoice = TOGGLE;
      //Serial.println("i'm in toggle mode now");
      //trellis.unregisterCallback(i, momentary);
    }
  }
}

void setup() {
  Serial.begin(115200);
  //while(!Serial);
    for (int i = 0; i < 16; i = i + 1) {
    toggleStates[i] = false;
  }

  Serial.println(F("Adafruit Bluefruit MIDI Example"));
  Serial.println(F("---------------------------------------"));

  /* Initialise the module */
  Serial.print(F("Initialising the Bluefruit LE module: "));

  if ( !ble.begin(VERBOSE_MODE) )
  {
    error(F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
  }
  Serial.println( F("OK!") );

  if ( FACTORYRESET_ENABLE )
  {
    /* Perform a factory reset to make sure everything is in a known state */
    Serial.println(F("Performing a factory reset: "));
    if ( ! ble.factoryReset() ) {
      error(F("Couldn't factory reset"));
    }
  }

  // change device name to make it more friendly
  ble.sendCommandCheckOK(F("AT+GAPDEVNAME=NeomeMinor"));

  //ble.sendCommandCheckOK(F("AT+uartflow=off"));
  ble.echo(false);

  Serial.println("Requesting Bluefruit info:");
  /* Print Bluefruit information */
  ble.info();

  /* Set BLE callbacks */
  ble.setConnectCallback(connected);
  ble.setDisconnectCallback(disconnected);

  // Set MIDI RX callback
  midi.setRxCallback(BleMidiRX);

  Serial.println(F("Enable MIDI: "));
  if ( ! midi.begin(true) )
  {
    error(F("Could not enable MIDI"));
  }

  ble.verbose(false);
  Serial.print(F("Waiting for a connection..."));
 
  if (!trellis.begin()) {
    Serial.println("Could not start trellis, check wiring?");
    while(1);
  } else {
    Serial.println("NeoPixel 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, toggle);
    trellis.registerCallback(i, momentary);
  }

  //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(42);
  }
  for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
    trellis.pixels.setPixelColor(i, 0x000000);
    trellis.pixels.show();
    delay(42);
  }
}

void loop() {
  ble.update(10);
  float measuredvbat = analogRead(VBATPIN);
  measuredvbat *= 2;    // we divided by 2, so multiply back
  measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
  measuredvbat /= 1024; // convert to voltage
  measuredvbat += 100;
  midi.send(0xB0, 99, measuredvbat);
  trellis.read();  // interrupt management does all the work! :)
  delay(BNO055_SAMPLERATE_DELAY_MS); //the trellis has a resolution of around 60hz
}


/******************************************/

// 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);
  }
  return 0;
}

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Sun Mar 07, 2021 1:14 am

Hi Dave!

I was just wondering if you had had a chance to look over the code I posted? From my ongoing tests that I'm doing trying to fix the issue, I'm pretty sure it's hardware related, at least from what I can tell. I'm not sure if its something with the keypads accidentally activating the column, or if there is some small point on the Trellis board that shorts out if its hit just right, but any help would be most appreciated! They are very usable, but with that option always there of triggering 4 notes instead of just the one I push, it makes me a little nervous to actually use it in a musical performance context, which is my ultimate goal.

Anyway, thanks again! Any help is most appreciated!

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by dastels on Sun Mar 07, 2021 11:09 am

I didn't see anything wrong with the code. It doesn't sound like a debouncing issue, though. I haven't come up with an explaination yet.

Have you tried reconstructing it? Specifically the elastomer button array. Are the boards clean (i.e. no potentially conductive debris)?

Have you tried running any of the examples? How do they do?

Dave

dastels
 
Posts: 6494
Joined: Tue Oct 20, 2015 3:22 pm

Re: Debouncing a NeoTrellis RGB PCB?

by strags on Sun Mar 07, 2021 5:17 pm

Hi,

I'm experiencing exactly the same thing... every so often (like maybe 1-2% of "normal" presses), I receive key down/up events for every key in the same column as the one pressed.

Slightly modified sample code:

def blink(xcoord, ycoord, edge):
print( "(%d,%d) %d" % ( xcoord, ycoord, edge ) )

Gives:

(2,0) 3
(2,1) 3
(2,2) 3
(2,3) 3
(2,0) 2
(2,1) 2
(2,2) 2
(2,3) 2

When only one key in column 2 was actually pressed.

There does appear to be a mechanical aspect to this - I can get it to occur reasonably consistently by pressing the top edge of the bottom-right button in a single trellis. I've taken it apart, checked joints etc... and can't find anything obviously wrong.

Cheers,
Ben


Edit: Video: https://photos.app.goo.gl/aF3WBs6zFt5j89rQ9

strags
 
Posts: 3
Joined: Thu Aug 02, 2012 8:22 pm

Re: Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Sun Mar 07, 2021 6:15 pm

Hi Dave and Ben,

Dave, I have indeed tried reconstructing it multiple times and cleaning it as well, without any success so far. I have also tried the examples, and it does happen with those too, so it definitely seems to be a hardware issue. I ordered both the 4x4 and 8x8 kits at the same time, do you think there's any way it could potentially be a defect in that particular batch of Trellis boards or something like that? I've looked through the forums and haven't found any other examples of this issue being discussed, so I'm actually wondering if maybe that could be possible. Do you know if there's any way to try a new Trellis board from a different batch somehow? I'm not sure if I would just have to order one, but the more I'm trying to get to the bottom of this, the more I'm thinking that perhaps something is defective on the Trellis boards themselves.

Ben, thanks for commenting as well, it sounds like exactly the same problem that I'm running into, even down to the way you have to push the button to make it function incorrectly consistently.

Anyway, thanks for replying, and I hope we can solve this sometime soon! Thanks for all of your help.

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by dastels on Sun Mar 07, 2021 7:02 pm

I've asked the engineering folks if they've seen this behavior. Personally I haven't, acrtoos several boards.

Dave

dastels
 
Posts: 6494
Joined: Tue Oct 20, 2015 3:22 pm

Re: Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Sun Mar 07, 2021 7:06 pm

Ok, sounds good! I'll just wait and see what they say then. Thanks for checking with them. If I discover anything new before I hear back I'll post here and let you know.

Thanks again for all of your help! I look forward to hearing what they say.

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by strags on Sun Mar 07, 2021 8:47 pm

After googling, I came across this:

https://learn.adafruit.com/adafruit-neo ... ting#faq-6

(The entry about an entire row being detected at once). Is this the same issue? It sure sounds like it.

strags
 
Posts: 3
Joined: Thu Aug 02, 2012 8:22 pm

Re: Debouncing a NeoTrellis RGB PCB?

by MusicManAsman on Sun Mar 07, 2021 8:51 pm

Hi Strags,

Yes, I do believe that is the exact problem!! Thank you so much for sharing this, I will try it out ASAP. Since I'm not using the M4 kit I didn't even think to look in that FAQ section.

Thank you so much!! Will report back on if any of those fixes work for me.

MusicManAsman
 
Posts: 15
Joined: Thu Feb 18, 2016 12:12 am

Re: Debouncing a NeoTrellis RGB PCB?

by dastels on Wed Mar 24, 2021 1:52 pm

That looks very likely. If it persists, you could daub a bit of nail polish over the Neipixel pins/pads/solder to insulate then from the button conductor.

Dave

dastels
 
Posts: 6494
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.