Extra button pushes

Greetings,

This is my first time posting here, and I have been working on a project for a few weeks now. Unfortunately, I am a bit stumped as I am experiencing issues with extra button pushes. For instance, when I press button 0, it triggers a button 8 press as well.

My project comprises of two sides: a server-side and a client-side. I am using a feather board with ethernet and a mux for the server-side, which will switch between inputs to a serial of another device (let's say LEDs for now). The server-side works fine, and I can send TCP commands to change the LEDs.

However, the problem lies on the client-side, which also uses the same hardware (feather board, ethernet, and mux). The idea is to have 10 buttons that will send commands to the server, essentially acting as a TCP remote control.

I have rewritten the code a few times in an attempt to narrow down the issue. I even removed the ezbutton library because I suspected it was buggy. However, the problem persists.

I would appreciate any help, and I am willing to pass along some coffee in exchange for assistance. Thank you.

#include <SPI.h>
#include <Ethernet.h>

const int muxSIG = A4;
const int muxS0 = A0;
const int muxS1 = A1;
const int muxS2 = A2;
const int muxS3 = A3;

void SetMuxChannel(byte channel) {
  digitalWrite(muxS0, bitRead(channel, 0));
  digitalWrite(muxS1, bitRead(channel, 1));
  digitalWrite(muxS2, bitRead(channel, 2));
  digitalWrite(muxS3, bitRead(channel, 3));
}

int buttonValues[16] = { 0 };  // initialize previous values to 0

void SetMuxChannelInt(int channel) {
  const int controlPins[] = { muxS0, muxS1, muxS2, muxS3 };
  const int muxChannel[16][4] = { { 0, 0, 0, 0 }, //1
                                  { 1, 0, 0, 0 }, //2
                                  { 0, 1, 0, 0 }, //3
                                  { 1, 1, 0, 0 }, //4
                                  { 0, 0, 1, 0 }, //5
                                  { 1, 0, 1, 0 }, //6
                                  { 0, 1, 1, 0 }, //7
                                  { 1, 1, 1, 0 }, //8
                                  { 0, 0, 0, 1 }, //9
                                  { 1, 0, 0, 1 }, //10
                                  { 0, 1, 0, 1 }, //11
                                  { 1, 1, 0, 1 }, //12
                                  { 0, 0, 1, 1 }, //13
                                  { 1, 0, 1, 1 }, //14
                                  { 0, 1, 1, 1 }, //15
                                  { 1, 1, 1, 1 } }; //16
  for (int i = 0; i < 4; i++) {
    digitalWrite(controlPins[i], muxChannel[channel][i]);
  }
  int value = digitalRead(muxSIG);
  buttonValues[channel] = value;
}

const int serverPort = 4080;
byte mac[] = { 0x98, 0x76, 0xB6, 0x12, 0x0F, 0x84 };
IPAddress serverAddress(192, 168, 6, 150);
EthernetClient TCPclient;

void setup() {
  pinMode(muxS0, OUTPUT);
  pinMode(muxS1, OUTPUT);
  pinMode(muxS2, OUTPUT);
  pinMode(muxS3, OUTPUT);
  pinMode(muxSIG, INPUT_PULLUP);
  digitalWrite(muxS0, LOW);
  digitalWrite(muxS1, LOW);
  digitalWrite(muxS2, LOW);
  digitalWrite(muxS3, LOW);

  Ethernet.init(11);
  Serial.begin(9600);

  Serial.println("ARDUINO #1: TCP CLIENT");

  IPAddress ip(192, 168, 6, 151);
  IPAddress subnet(255, 255, 255, 0);
  IPAddress gateway(192, 168, 6, 1);
  IPAddress dns(192, 168, 6, 1);
  Ethernet.begin(mac, ip, dns, gateway, subnet);

  if (TCPclient.connect(serverAddress, serverPort)) {
    Serial.println("Connected to TCP server");
  } else {
    Serial.println("Failed to connect to TCP server");
  }
}

void loop() {
  for (int i = 0; i < sizeof(buttonValues) / sizeof(buttonValues[0]); i++) {
    SetMuxChannelInt(i);
    int value = buttonValues[i];
    if (value != 1) {
      Serial.print("Value at channel ");
      Serial.print(i);
      Serial.print(" changed to: ");
      Serial.println(value);
      TCPclient.print(i);
    }
  }
}

the / should be *

sorry.. ~q

??? That would be 32*2 = 64!!!

no, that's correct. Let me reconstruct your hardware:
You have up to 16 buttons attached to a 16:1 mux, and your scanning them one at a time?
Your input is a pullup, but are the buttons pulled up/down at the inputs of the mux? A schematic would really help here.
If they are pulled up, and not reading random noise, then we have to look deeper.

1 Like

This only initializes buttonValues[0].

Given that it's a global, isn't it already initialized anyway?

Yes but I wanted the OP to understand that a single value does not init all of them. In this case it is benign.

1 Like

I suspect @camsysca is on to something with regards to the pullups.

Or maybe, not? What does the compiler do about the other values if an initial value is given for one? I think it's okay, but.

And, I thought there was some newfangled C++ syntax coming where one could spec a single value in a fashion like that, and it would propagate to the whole data item being initialized?

Is there a pattern here? Does button 1 trigger button 9? If so, you may have a wiring issue with your mux.

I think you are right. My bad.

You guys are fast
I do have some schematics and images

Ignore the code in the image as I’ve changed the client side a few times trying to figure this out

I mentioned that when I press button 0 I also get button 8 almost every time

Where as most of the other buttons are fine when I press 8 I get 0 as well..

I also have another full set of hardware and have swapped just in case it was a hardware thing

I think I’m missing something fundamental maybe
I was seeing alsmot the same issue in a few different variations I’ve written

I’ll be back at a compute in about 30 picking up my son but any help is greatly apreshated

Thanks

It dosnt trigger but in addition and yes 0 pushes 8 as well

hardware is correct and i've just posted a schematic.

yes it seems they are pulled up and perhaps getting specific noise

Use a strong pullup on the multiplexer common I/O pin (recommend 1K).

Easy to ignore code that's too small to be read. Please, don't post images, post the code in code tags.
As for the hardware, again, not enough resolution to read pin or part numbers, generally essential to do so. Remember, we don't have your parts in front of us, so either give us pointers to data sheets, or images that are clear and concise.
Thanks
In particular, I'd like to know what that mux is, because it's characteristics will be important to determine whether your suffering from noise, what your pullups might need to be, etc.

Are they shorted?

Copy,

The board is a Feather nRF52832 with a feather Wing attachment
Mux is mux 16 channel alanlug 2048L -

As for the code, I posted the code initially in the post.
I wasn't home when I posted the image, Which was one that was made for someone else, which is why the code was in it. I clearly said to ignore the code in the image that I posted from my phone while picking up my son..

LOL! I don't think anyone needed to be told to ignore that.

@tfraley did you, or can you, write the simplset of sketches that throws everything overboard except…

... getting the buttons to be individual and well-behaved?

Strip down or start from scratch and just get the buttons working.

ezButton does work, but has some nasty features. I think it is harder to use and get working than other libraries.

So try a test sketch, with wzButton or with a different button library.

a7

So what you saying I should not use the input_pullup and put a 1k resistor inline between the Mux (sig) & Feather(sig pin?)

Image makes me think something else ?
if I'm understanding that wrong could you explain a bit more ? and sorry for that