Sorry to revive an old post but i’ve read the “faq” and viewed many posts in the entire forum, many times without success, and i think this post is the better to ask for help, so…
First of all, sorry if i made a mistake writing this, i’m Chilean…
Well, the goal is the same as many people, piezo+arduino+midi. The arduino+midi is an old story so i don’t have problem in this part, but the problem are piezos+arduino, and looking for a way to control the piezo signal i found in the web an electrical sketch (i cann’t put the link cause it’s my first post), and now i can process perfectly 6 pads (duemilanove), but trying to mux more than those 6 pads in a MC14067BCP i get signal in many inputs, depending on the strike volume.
I know that i must connect the mux to one analog input, selecting digitally the channel to read and from arduino to read the analog input (in my case it should be analogRead(0) cause i have just one mux) .
This is the code (spikenzielabs adapted version)…
unsigned char PadNote[] = {38,46,48,74,75,76,77,78};
int PadCutOff[] = {0,0,0,0,0,0,0,0};
int MaxPlayTime[] = {80,80,80,80,80,80,80,80};
#define midichannel 0;
boolean activePad[] = {0,0,0,0,0,0,0,0};
int PinPlayTime[] = {0,0,0,0,0,0,0,0};
unsigned char status_;
int pin = 0;
int hitavg = 0;
int ds[][4]={ {LOW,LOW,LOW,LOW},
{HIGH,LOW,LOW,LOW},
{LOW,HIGH,LOW,LOW},
{HIGH,HIGH,LOW,LOW},
{LOW,LOW,HIGH,LOW},
{HIGH,LOW,HIGH,LOW},
{LOW,HIGH,HIGH,LOW},
{HIGH,HIGH,HIGH,LOW} };
void setup() {
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(31250);
}
int analogRead_(int i){
digitalWrite(5, ds[i][3] );
digitalWrite(4, ds[i][2] );
digitalWrite(3, ds[i][1] );
digitalWrite(2, ds[i][0] );
return analogRead(0);
}
void loop() {
for( pin=0; pin < 8; pin++){
hitavg = analogRead_(pin);
PinPlayTime[pin]++;
if((hitavg > PadCutOff[pin])) {
if( !activePad[pin] ) {
MIDI_TX(144,PadNote[pin],hitavg);
PinPlayTime[pin] = 0;
activePad[pin] = true;
}
} else if( activePad[pin] && (PinPlayTime[pin] > MaxPlayTime[pin])) {
activePad[pin] = false;
MIDI_TX(128,PadNote[pin],127);
}
}
}
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) {
status_ = MESSAGE + midichannel;
Serial.print(status_,BYTE);
Serial.print(PITCH,BYTE);
Serial.print(VELOCITY,BYTE);
}
In the mux, the pin 24 goes to arduino 5v, pins 12,15 go to arduino ground, 10,11,14,13 go to arduino digitals 2,3,4,5 respectively, pin 1 to arduino analog 0, the pin 9 goes to the output of the circuit (piezo+diodes+resistor+etc.) and finally this circuit ground to arduino ground. So having just one pad, i get signals on all the mux analog inputs not only in the input 0, even when the signal doesn’t go over 50. It’s so random that sometimes analog 0 gets 6 and in the next read analog 1 gets 2 or 1, sometimes analog 0 gets 127 then the same input gets 26 and then the analog 1 gets 1. I’ve tried putting delays (micros and millis), i tried putting a 10k resistor between de piezo circuit and the mux analog 0, and i tried putting the mux inhibit pin 15 to the arduino 5v (10k resistor between them) as i read in a forum, and i tried putting the unused analog pins to ground, but nothing. And believe me when i bypass the mux, connecting every circuit to the arduino analogs everything is ok. So my problem is the mux.
I’m not an electrical but i know that maybe somewhere a made a mistake in the circuit or in the code, so any help ? is this mux too lower to be used in a drum ?
Thanks in advance.