my circuit acts mad

Status
Not open for further replies.

AdmiralCrunch

Well-known member
Hey folks,

i apologize in advance for this, .. this is really stupid, but don't know what to do anymore :/

i am working on a bigger project (some of you may know me because i often ask questions here) .. at a point I needed to re-produce a part of my circuit on the breadboard for testing/debugging. I did this about a hundred times now and it is really simple .. but my circuit goes totally mad and I really can't help myself.

so here is the problem:
.. distributed on two breadboards I have:

breadboard1: .. the T_3.6 and a pushbutton (which is not connected to the teensy)
breadboard2: .. a 74HC4051-multiplexer, to which 8x switchbuttons are connected.. the 4051-out goes to T_3.6-pin 15

- one 74HC4051-multiplexer, to which 8x switchbuttons are connected.. the 4051's out goes to T_3.6-pin 15
- one seperate switchbutton, .. which is not connected anywhere

20180913_224414.jpg
20180919_221614.jpg
20180919_221625.jpg

now the following happens:

- when I press the one seperate switchbutton, it somehow triggers the signals at all 4051-inputs..
- when I press one of the buttons connected to the 4051, it also triggers the signal at all 4051-inputs

how can this be?


the code should work, I have extraced it from my already working project.

Code:
    int muxPin1 = 2;
    int muxPin2 = 3;
    int muxPin3 = 4;   
    int muxPinInh = 5;
    
    // PINS D
    int btnTrackSelectPin = 15;
    int btnShiftPin = 14;
  
    int MuxBit1;
    int MuxBit2;
    int MuxBit3;

    bool shiftStatus;

    #include <btnTrackSelect.h>
    btnTrackSelect btnTrackSelect[16];

    #include <Bounce.h>
    Bounce btnShift = Bounce(btnShiftPin, 10); 

void setup() {
  // 4051 - ctrl
  pinMode(muxPin1, OUTPUT);
  pinMode(muxPin2, OUTPUT);
  pinMode(muxPin3, OUTPUT);
  pinMode(muxPinInh, OUTPUT);

  // 4051 - INPUT PINS
  pinMode(btnTrackSelectPin, INPUT);
  pinMode(btnShiftPin, INPUT_PULLUP);

  Serial.begin(9600);
  while ( !Serial && (millis() < 4000) ) {
    // ..
  }
  Serial.println("SERIAL PORT INITIALIZED");
}

void loop() {
  pollShift();
   
  for(int i = 0; i <= 7; i++) {
    // count through MUX
    digitalWrite(muxPinInh, HIGH);
    MuxBit1 = bitRead(i, 0);
    MuxBit2 = bitRead(i, 1);
    MuxBit3 = bitRead(i, 2);    
    digitalWrite(muxPin1, MuxBit1);
    digitalWrite(muxPin2, MuxBit2);
    digitalWrite(muxPin3, MuxBit3); 
    digitalWrite(muxPinInh, LOW); 
    delayMicroseconds(40);

    btnTrackSelect[i].btnStatus = digitalRead(btnTrackSelectPin);
    
    if (btnTrackSelect[i].btnStatusOld != btnTrackSelect[i].btnStatus) {      
      Serial.print(i); Serial.print(" : "); Serial.println(btnTrackSelect[i].btnStatus);
      btnTrackSelect[i].btnStatusOld = btnTrackSelect[i].btnStatus;  
    }   
  }  
}

/* Polls Shift-Button and sets Status-Var */
void pollShift() {
    if (btnShift.update()) {
        if (btnShift.fallingEdge()) {
            shiftStatus = true;
            Serial.println("Shift pressed..");                      
        } else {
            shiftStatus = false;            
            Serial.println("Shift released..");              
        }
    }
}
 
Edit:

is my Teensy broken? ..oO

I unplug everything and load the pushbutton-example
Code:
void setup()   {                
  Serial.begin(38400);
  pinMode(7, INPUT);
}

void loop()                     
{
  if (digitalRead(7) == HIGH) {
    Serial.println("Button is not pressed...");
  } else {
    Serial.println("Button pressed!!!");
  }
  delay(250);
}

the output is "Button is not pressed..."


now I change the pin to 14
Code:
void setup()   {                
  Serial.begin(38400);
  pinMode(7, INPUT);
}

void loop()                     
{
  if (digitalRead(14) == HIGH) {
    Serial.println("Button is not pressed...");
  } else {
    Serial.println("Button pressed!!!");
  }
  delay(250);
}

now the output is "Button pressed!!!"

how can that be? what have I overlooked?
 
Is the button wired to 3.3V 'pulled up' with a resistor and to the pin?

Second code in post #2 has setup() { … pinMode(7, INPUT); } :: Then does digitalRead(14); - is that the code as used?

If button were wired to GND and the pin set pinMode(7, INPUT_PULLUP); it would read HIGH until pressed.
 
Hi

Is the button wired to 3.3V 'pulled up' with a resistor and to the pin?
yes, with a 10K resistor.

Second code in post #2 has setup() { … pinMode(7, INPUT); } :: Then does digitalRead(14); - is that the code as used?
Oh, i'm sorry.. forgot to change the pinMode back after I tried various things.. it is both pinMode/digitalRead on pin 14

If button were wired to GND and the pin set pinMode(7, INPUT_PULLUP); it would read HIGH until pressed.

yes but whatever it reads.. why does the one switchbutton "trigger" all the signals on the 4051?
 
Hi

yes but whatever it reads.. why does the one switchbutton "trigger" all the signals on the 4051?

That seemed a complex question - figured getting to read one physical button reliably would be a good first step. If that isn't reading right on one pin then any other inputs as needed to read the Mux something is bad with or outside the Teensy it seemed.

Once all input pins needed could be trusted - perhaps a longer delay in the 1 to 7 loop and print the 'bit pattern' under test - maybe with a loop { delay; print(digitalRead) ) to allow manually changing each Mux input in turn.

Question: with an external pullup on an input pin does that switch go to GND - my question didn't have a picture or good phrasing
 
If the code has worked on a different project then the likely culprit is that something may have been miswired or the hardware is at fault. If you have a multimeter I would suggest manually addressing the multiplexer, without the Teensy, and reading the output with the multimeter to see if the buttons behave how you would expect them to. If they still behave in the same way then you either have a bad multiplexer or the wiring got mixed up somewhere, I’ve made the same mistake before.
 
Hi guys .. thank you for the advices.

I have now tested EVERYTHING .. and now I found out that it really was wires.. i have ordered me some more jumperwires and breadboards from amazon and after I recieved them I mixed them with the ones I already have.. now i have a full box of jumperwires where some are broken :/

after testing every wire before usage, everything seem to run as it should again.
 
FWIW: I see that you have some jumper wires with a round plastic end and some that are square. I have always had trouble with the rounded ones and never use them any more. They don't fit into a breadboard properly (at least, the ones I have don't) which can cause all sorts of weird intermittent problems.
I'd replace all the round ones.

Pete
 
Where does the btnTrackSelect.h come from?

I can't understand what your program is really doing without knowing what that library really does.
 
Status
Not open for further replies.
Back
Top