multiplexing touch pins

Status
Not open for further replies.

emmanuel63

Well-known member
Hello,

I try to multiplex Touch inputs but I get inconsistent values. I guess touch pins cannot be multiplexed. Did someone have any success multiplexing touch pins ?
Emmanuel

Code:
//Mux control pins
int s0 = 0;
int s1 = 1;
int s2 = 2;
int s3 = 3;

//touch pin values
int touch_value[16] = {0};

//Mux output pin
int touch_pin = 30;

void setup() {

  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  Serial.begin(9600);

}

void loop() {
  updateMux1();
  Serial.println(touch_value[0]);
  delay(5);
}

void updateMux1 ()
{
  for (short i = 0; i < 16; i ++)
  {
    digitalWrite(s0, HIGH && (i & B00000001));
    digitalWrite(s1, HIGH && (i & B00000010));
    digitalWrite(s2, HIGH && (i & B00000100));
    digitalWrite(s3, HIGH && (i & B00001000));
    delayMicroseconds (5);
    touch_value[i] = touchRead(touch_pin);
  }
}
 
I would assume multiplexing touch inputs can be done on any microcontroller. However I don't see anywhere in your code where you are reading anything from the inputs, and you don't have any inputs defined. With multiplexing I think you need to rapidly charge and discharge the touchpad as if it was an RC/Time circuit. I have done it but on a different microcontroller, different programming language, years ago. If you are interested in inspecting my code feel free too, it is still at http://forums.parallax.com/discussion/134537/ppdb-using-the-full-ppdb-updated-code-version-1-4 at the end of the first post is a zip attachment. The code you will be interested in is the Matrix Keypad code. Not in C, but spin is a simple language to follow and probably convert.

But in general, if memory serves me correctly, you need to set the pins to output, to charge, then to input to read. Repeat!
 
Touch sensors work on stray capacitance (at the pF kind of scale), which is affected by switching as small amounts of
charge get transfered everytime a switch closes. The problem is the stray capacitances are similar either side of
the switch/multiplexer, so the voltage is strongly affected by closing the switch - high impedance buffers would be
needed before the switch to solve this (JFET of CMOS input opamps as followers, for example).
 
Thanks a lot UHF for the link.
And thanks MarkT for the explanation.
I will give a try to theses little boards, this is exactly what I need.
 
Status
Not open for further replies.
Back
Top