Bought a "Button Box" On Etsy, it's not working as expected

Hello all! I got a button box off of Etsy that has a set of 3 encoders that are not working as expected. Basically if an encoder has button 34 as counterclockwise and button 35 as clockwise, as you turn the encoder you'll have the button bouncing between 34 and 35 making it absolutely useless.

I worked with the programmer/builder of the box but he's stumped as to how to get any improvement. He gave me the code he used inside the box (Arduino Leonardo) and said I should mess around in IDE with the section below (delay being ms between accepted button presses):

delay(50);
Joystick.releaseButton(i+34);

Does anyone have any suggestions I can try? If needed I can post the code in it's entirety.

The concept I think you’re looking for is hysteresis.

You.ne ed to decide on a couple of constants, then only act on the encoder xhange when those terms are valid.

Honestly all I'm interested in is using the encoders to scroll positive or negative.

The builder said this may be due to the encoders that he used, but ones that "may" fix the problem are more expensive so he doesn't use them.

My guess is that one of the encoder pins is stuck HIGH or LOW. As the other pin goes HIGH and LOW the encoder appears to be going forward and backward.

I would test it by writing a sketch that just reports the values of the encoder inputs every time they change. If you see one pin that doesn't change, that's a hardware problem.

I'm 100% a programming idiot and the best I've ever been able to do were SQL reports/queries.

Any suggestions on what I can try?

Maybe some details about this "etsy encoder box".
I hope you're not figuring everyone will say, "oh, yeah, the etsy box, well, what you do is,...".

Hi, @simmer1522
Welcome to the forum.

Can you post a link(s) to data/specs/purchase of the "Button Box".

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Lots of "button boxes" on Etsy.

Hi,
Can you please post some image(s) of your Button Box?
Can you open it and see how it is wired inside?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Lol, ask and ye shall received. I'll post some pictures today along with the code.

Pictures as promised. ( can only post one at a time as a new user so let me know if you need more)

Top row has 2 way switches, row 2 has 3 way, row 3&4 has push buttons.

Keypad setup on right are just push buttons.

Encoder.H code

#ifndef Encoder_h
#define Encoder_h
#include "Arduino.h"

class Encoder {
  private:
    int DTPin;
    int CLKPin;
    int SWPin;
    bool currentCLKState;
    bool lastCLKState;
 public:
  Encoder(int CLK, int DT);
  Encoder(int CLK, int DT, int SW);
  
  void setDTPin(int DT);
  void setCLKPin(int CLK);
  void setSWPin(int SW);
  bool getDT();
  bool getCurrentCLKState();
  bool getLastCLKState();
  void setLastCLKState(int state);
  bool getSwitchState();
};
#endif

Leonardo Code

#include <Joystick.h>
#include <Encoder.h>
#define ROWS 6
#define COLUMNS 5

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
40, 0, // Button Count, Hat Switch Count
false, false, false, // X and Y, but no Z Axis
false, false, false, // No Rx, Ry, or Rz
false, false, // No rudder or throttle
false, false, false); // No accelerator, brake, or steering




Encoder encoder(0,3,18);
Encoder encoder1(1,4,20);
Encoder encoder2(2,5,21);

void setup() {
//Serial.begin(9600);
Joystick.begin();
for(int i = 6; i<=14; i++){
if(i==11){i=14;}
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
for(int o = 15; o<=21; o++){
if(o==17){o=18;}
pinMode(o, INPUT);
}
for(int e = 0; e<=5; e++){
pinMode(e, INPUT_PULLUP);
}
attachInterrupt(digitalPinToInterrupt(1), readRotary,RISING);
attachInterrupt(digitalPinToInterrupt(0), readRotary,RISING);
attachInterrupt(digitalPinToInterrupt(2), readRotary,RISING);
encoder.setLastCLKState(encoder.getCurrentCLKState());
encoder1.setLastCLKState(encoder1.getCurrentCLKState());
encoder2.setLastCLKState(encoder2.getCurrentCLKState());

}

void loop() {

int k = 0;
for(int r = 6; r<=14; r++)
{
if(r==11){r=14;}
digitalWrite(r, HIGH);
for(int c = 15; c<=20; c++){
if(c==17){c=18;}

if(r==6 && c<19){

if(digitalRead(c)){
Joystick.releaseButton(k+1);
Joystick.pressButton(k);
}
if(!digitalRead(c)){
Joystick.releaseButton(k);
Joystick.pressButton(k+1);
}
k+=2;
}
else if((r==6 && c>18) || (r==7 && c<20)){
if(digitalRead(c)){
Joystick.releaseButton(k+1);
Joystick.releaseButton(k+2);
Joystick.pressButton(k);
}
else if(digitalRead(c+1)){
Joystick.releaseButton(k);
Joystick.releaseButton(k+1);
Joystick.pressButton(k+2);
}
else{
Joystick.releaseButton(k);
Joystick.releaseButton(k+2);
Joystick.pressButton(k+1);
}
k+=3;
c++;
}
else if(r==14 && c>18){}
else{
if(digitalRead(c)){
Joystick.pressButton(k);
}
if(!digitalRead(c)){
Joystick.releaseButton(k);
}
k++;
}
}
digitalWrite(r, LOW);
}
for(int i = 0; i<6; i++){
delay(50);
Joystick.releaseButton(i+34);
}
}
void readRotary(){
int btn = 34;
volatile bool currentState = encoder.getCurrentCLKState();
volatile bool currentState1 = encoder1.getCurrentCLKState();
volatile bool currentState2 = encoder2.getCurrentCLKState();
if(currentState != encoder.getLastCLKState() && currentState == 0)
{
if(encoder.getDT() == 1){
Joystick.pressButton(btn);

}else{
Joystick.pressButton(btn+1);
}
}
if(currentState1 != encoder1.getLastCLKState() && currentState1 == 0)
{
if(encoder1.getDT() == 1){
Joystick.pressButton(btn+2);
}
else{
Joystick.pressButton(btn+3);
}

}
if(currentState2 != encoder2.getLastCLKState() && currentState2 == 0)
{
if(encoder2.getDT() == 1){
Joystick.pressButton(btn+4);
}
else{
Joystick.pressButton(btn+5);
}
}
encoder.setLastCLKState(currentState);
encoder1.setLastCLKState(currentState1);
encoder2.setLastCLKState(currentState2);
}

On this image

are those wires soldered?

I believe they are but I'd need to check to confirm.

Could it possibly just as easy as replacing the encoders with higher quality/light based ones?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.