2

I am working on a project that needs multiple digital signals and I am considering the CD74HC4067 (on a break-board) to work as a multiplexer. More specifically i am trying to build a keypad with multiple ttp123 break-boards. Each ttp123 signal is connected to one of the 0-15 pins of the CD74HC4067. The S0-S3 pins are connected to digital Pins D6 to D9 on a pro mini. Signal is on A0 and EN is on A1. A1 and EN have a 4K7 resistor to ground. I power the setup with a separate 5v and the arduino is connected on a pc usb port.

I expect when a ttp123 is pressed to trigger a HIGH and this event to be passed to SIG pin. Here is my code:

//Using CD74HC4067 16-Channel Analog Multiplexer
//Mux control pins

int s0 = 6;
int s1 = 7;
int s2 = 8;
int s3 = 9;


//Mux in "SIG" pin
int SIG_pin = A0;
int EN_pin  = A1;

void setup(){
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  pinMode(EN_pin, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  digitalWrite(EN_pin, LOW);

  Serial.begin(9600);
  Serial.println("keypad interfacing_CD74HC4067 starting...");
}


void loop(){
  String a;
  //digitalWrite(EN_pin, HIGH);
  Serial.println(" press any key to continue ...");
  //digitalWrite(EN_pin, LOW);
  while (!Serial.available());
  while(Serial.available()) {
    
  //Loop through and read all 16 values
  for(int i = 0; i < 16; i ++){
    //Serial.print("Value at channel ");
    //Serial.print(i);
    //Serial.print("is : ");
    //Serial.println(readMux(i));
    
      float volts = readMux(i);
          
      Serial.print("Value at channel ");
      Serial.print(i);
      Serial.print(" is : ");
      Serial.print(volts);
      Serial.println();
    
    //delay(1000);
  }
  a= Serial.readString();// read the incoming data as string
}
}
float readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through the 4 sig
  
  for(int j = 0; j < 4; j ++){
    digitalWrite(controlPin[j], muxChannel[channel][j]);
  }
  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  float voltage = (val * 5) / 1024.0;
  return voltage;
}

Just for simplicity, I have connected only one ttp123 on the system, ttp123 signal to channel12 on 74HC4067. With ttp123 touched, I would expect to get a high on SIG when I write {0,0,1,1}, to S0-S3. All other channels should be LOW. However here is what I get:

On my first run after a boot:

press any key to continue ...
Value at channel 0 is : 2.53
Value at channel 1 is : 2.58
Value at channel 2 is : 2.53
Value at channel 3 is : 2.60
Value at channel 4 is : 2.51
Value at channel 5 is : 2.55
Value at channel 6 is : 2.50
Value at channel 7 is : 2.52
Value at channel 8 is : 2.42
Value at channel 9 is : 2.47
Value at channel 10 is : 2.43
Value at channel 11 is : 2.50
Value at channel 12 is : 2.40
Value at channel 13 is : 2.43
Value at channel 14 is : 2.38
Value at channel 15 is : 2.44

and then after each sample run all channels seem to get lower values...

press any key to continue ...
Value at channel 0 is : 1.70
Value at channel 1 is : 1.76
Value at channel 2 is : 1.71
Value at channel 3 is : 1.78
Value at channel 4 is : 1.70
Value at channel 5 is : 1.76
Value at channel 6 is : 1.72
Value at channel 7 is : 1.77
Value at channel 8 is : 1.67
Value at channel 9 is : 1.72
Value at channel 10 is : 1.69
Value at channel 11 is : 1.76
Value at channel 12 is : 1.69
Value at channel 13 is : 1.73
Value at channel 14 is : 1.67
Value at channel 15 is : 1.74

and I get no HIGH on channel 12 as I should.

Is there a need for a pullup or pulldown resistors in this setup? Should I connect a resistor to each S0-S3 with ground? Why is this not working?

Edit: schematic

When the system is resting I measure 4.93V at the ttp's Vs to GND and 0V TTP_SIGNAL to GND. When ttp's are touched TTP_SIGNAL to GND i measure a 3.94-3.88v. But the strange thing is that when i touch the ttp's I measure 2.xx Volts at all the mux channels. I think that there must be some kind of short circuit somewhere but it is not visible. The problem is that I can't test another CD74HC4067 since i have only one right now. Unless there is another suggestion I will look for a couple of these (CD74HC4067) as soon as possible.

Edit2:

I got hold of a new CD74HC4067 and connected just one capacitive touch pad. When nothing is touched/pressed, i get the following:

press any key to continue ...
Value at channel 0 is : 1.01
Value at channel 1 is : 0.90
Value at channel 2 is : 0.81
Value at channel 3 is : 0.62
Value at channel 4 is : 0.44
Value at channel 5 is : 0.42
Value at channel 6 is : 0.43
Value at channel 7 is : 0.43
Value at channel 8 is : 0.31
Value at channel 9 is : 0.28
Value at channel 10 is : 0.24
Value at channel 11 is : 0.18
Value at channel 12 is : 0.15
Value at channel 13 is : 0.23
Value at channel 14 is : 0.22
Value at channel 15 is : 0.13

When i touch the pad (connected to c0) i get:

press any key to continue ...
Value at channel 0 is : 4.15
Value at channel 1 is : 3.74
Value at channel 2 is : 3.75
Value at channel 3 is : 3.54
Value at channel 4 is : 3.76
Value at channel 5 is : 3.33
Value at channel 6 is : 2.88
Value at channel 7 is : 2.64
Value at channel 8 is : 3.77
Value at channel 9 is : 3.52
Value at channel 10 is : 3.07
Value at channel 11 is : 2.76
Value at channel 12 is : 2.04
Value at channel 13 is : 1.83
Value at channel 14 is : 1.67
Value at channel 15 is : 1.51

I measure volts between signal and ground at the capacitive touch pad, when touched i get 3.9v

5
  • 2
    You've mentioned separate supply, begginers loves to forgot ground connections. Anyway slowly changing adc readings somewhere far from 0 or 5 usually indicates floating input. You have to measure everything, test that mux separately...
    – KIIV
    Jan 21 at 20:25
  • @KIV thank you for your comment. The grounds of the two separate sources are connected. I will measure everything again and will come back.
    – thermike
    Jan 22 at 11:30
  • Posting a schematic of how you have it wired will help a lot. Even a hand drawn schematic is better than a frizzy picture.
    – Gil
    Jan 22 at 16:36
  • @Gil i edited the question as you suggested.
    – thermike
    Jan 24 at 8:20
  • I got a new CD74HC4067 and tested it. I edited the post above. Any suggestions?
    – thermike
    Feb 4 at 7:44

1 Answer 1

2

I finally managed to get a solution to my problem. There was a cabling and a software issue as well. Firstly, I pulled down the Signal with a 10K resistor. In this way I stopped having those random volt measurements. enter image description here

Secondly, in the code, I had an elementary failure to initialize the A0 analog pin as: pinMode(SIG_pin, INPUT);

Here is the final code:

// interfacing mux with tp223

//Mux control pins

const int s0 = 6;
const int s1 = 7;
const int s2 = 8;
const int s3 = 9;

//Mux in "SIG" pin
int SIG_pin = A0;
int EN_pin  = 10;

void setup(){
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  pinMode(SIG_pin, INPUT);
  pinMode(EN_pin, OUTPUT);
  
  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  digitalWrite(EN_pin, LOW);

  Serial.begin(115200);
  Serial.println("keypad interfacing_CD74HC4067 starting...");
}

void loop(){
    
  //Loop through and read all 16 values
  for(int i = 0; i < 16; i ++){
      int val = readMux(i);
      
      if (val > 0) {
        Serial.print(i);
        Serial.print(" pressed ");
        Serial.print(val);
        Serial.println();
      }
  }
  
}
float readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
    {1,1,0,0}, //channel 3
    {0,0,1,0}, //channel 4
    {1,0,1,0}, //channel 5
    {0,1,1,0}, //channel 6
    {1,1,1,0}, //channel 7
    {0,0,0,1}, //channel 8
    {1,0,0,1}, //channel 9
    {0,1,0,1}, //channel 10
    {1,1,0,1}, //channel 11
    {0,0,1,1}, //channel 12
    {1,0,1,1}, //channel 13
    {0,1,1,1}, //channel 14
    {1,1,1,1}  //channel 15
  };

  //loop through the 4 sig
  for(int j = 0; j < 4; j ++){
    digitalWrite(controlPin[j], muxChannel[channel][j]);
  }
  //read the value at the SIG pin
  int val = digitalRead(SIG_pin);
  //return the value
  return val;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.