Hi all, I've been trying to use the CD74HC4067 multiplexer with arduino to read 16 (at least) analog inputs in Pd (Pure Data). I've checked the code in this web site http://bildr.org/2011/02/cd74hc4067-arduino/ but it wouldn't really do, so I searched a bit more and ended up with some code I partly wrote, partly copied myself, which is this
#define CONTROL0 11
#define CONTROL1 10
#define CONTROL2 9
#define CONTROL3 8
byte muxarray[16];
void setup() {
Serial.begin(9600);
pinMode(CONTROL0, OUTPUT);
pinMode(CONTROL1, OUTPUT);
pinMode(CONTROL2, OUTPUT);
pinMode(CONTROL3, OUTPUT);
}
void loop() {
for (int i = 0; i < 16; i++) {
digitalWrite(CONTROL0, (i&15)>>3);
digitalWrite(CONTROL1, (i&7)>>2);
digitalWrite(CONTROL2, (i&3)>>1);
digitalWrite(CONTROL3, (i&1));
muxarray[i] = analogRead(0);
}
Serial.write(muxarray, 16);
}
Checking it yesterday with a couple of potentiometers (and the rest of the multiplexer inputs and arduino's inputs connected to ground), I was getting values from 0-255 over and over. Trying to correct this I tryied this
#define CONTROL0 11
#define CONTROL1 10
#define CONTROL2 9
#define CONTROL3 8
byte muxarray0[16];
byte muxarray1[16];
void setup() {
Serial.begin(9600);
pinMode(CONTROL0, OUTPUT);
pinMode(CONTROL1, OUTPUT);
pinMode(CONTROL2, OUTPUT);
pinMode(CONTROL3, OUTPUT);
}
void loop() {
for (int i = 0; i < 16; i++) {
digitalWrite(CONTROL0, (i&15)>>3);
digitalWrite(CONTROL1, (i&7)>>2);
digitalWrite(CONTROL2, (i&3)>>1);
digitalWrite(CONTROL3, (i&1));
muxarray0[i] = analogRead(0);
muxarray1[i] = muxarray0[i] >> 8;
}
Serial.write(muxarray0, 16);
Serial.write(muxarray1, 16);
}
which really doesn't work. Trying the first code with 16 potentiometers attached to the circuit, today I was only getting jumping numbers. Anyone knows how to use this multiplexer with Pd? Btw, I know little about programming (at least with the arduino language).
Thanks