Triggering multiple notes from single button press - mxltiplexer 74hc4051

Status
Not open for further replies.
MIDI controller - multiple notes from single button press - mxltiplexer 74hc4051

I currently have thirteen buttons hooked up to two digital pins (0,1) on a Teensy 3.2 through two 74HC4051 muxes. The Muxes are controled by pins 10,11,12. MUX 1 has eight pushbuttons and MUX 2 five, with the spare pins tied to ground.
I am using the midicontroller.h library from here:

https://github.com/tttapa/MIDI_controller

the circuit is essentially the same as the one shown here, but with only two Multiplexers:
schematic_ioexpand.png

Some of the buttons are DigitalLatch, some are simple Digital (see code below)

Everything is working as it should up to a point. However the DigitalLatch buttons on Pin 7 and Pin 3 of MUX 1 seem to alternate between firing the two MIDI notes assigned to these pins at a very fast rate when either button is pushed.
After much playing around, I am wondering if this might be an issue with the S2 control pin getting current even when it is nominally "low", causing the read to flicker between these pins?

as per the datasheet, this is the difference between reading pin 7 and pin 3

https://assets.nexperia.com/documents/data-sheet/74HC_HCT4051.pdf

If this is the case what can I do to solve this? I read someone suggesting tying the control pins to ground via a high value resisitor might help. Is this a possible solution?

I have already re-soldered the control pin connections, and tried replacement buttons, and also tried moving the buttons on MUX 2 to different pins. One interesting result here was that removing the button from pin 7 and moving it to pin 4 of the mux seemed to cause the button on pin 6 to exhibit the same behavior.

Something even stranger seems to happen on the other Multiplexer - On Pin7 of Mux 2 the Digital button appears to trigger MIDI note 16, as well as 12 (which it is allocated)..... and it triggers both again at a very fast repeat, rather than held note.
I am sort of hoping solving the first problem will also help with this though!

thanks in advance for any advice.



Code:

#include <Encoder.h>

#include <MIDI_Controller.h>
//Midi controller library

#include <ResponsiveAnalogRead.h>
// analog smoothing

#include <Bounce.h>
// include the Bounce library for 'de-bouncing' switches -- removing electrical chatter as contacts settle
// usbMIDI.h library is added automatically when code is compiled as a MIDI device

using namespace ExtIO;
// use standard arduino digital write pin mode etc.

AnalogMultiplex buttonsmux1(1, { 10, 11, 12 } );
AnalogMultiplex buttonsmux2(0, { 10, 11, 12 } );
// creating muxers
//AnalogMultiplex(pin_t analogPin, { pin_t addressPin1, addressPin2, ... addressPinN } )
//analogPin: the analog input pin connected to the output of the multiplexer
//addressPin#: the digital output pins connected to the address lines of the multiplexer

DigitalLatch Arcadebuttons[] = {
{buttonsmux1.pin(0), 0, 14, 127, 10},
{buttonsmux1.pin(1), 1, 14, 127, 10},
{buttonsmux1.pin(2), 2, 14, 127, 10},
{buttonsmux1.pin(3), 3, 14, 127, 10},
{buttonsmux1.pin(4), 4, 14, 127, 10},
{buttonsmux1.pin(5), 5, 14, 127, 10},
{buttonsmux1.pin(6), 6, 14, 127, 10},
{buttonsmux1.pin(7), 7, 14, 127, 10},
// Create 8 new instances of the class 'DigitalLatch', on the 8 pins of the buttonsmux1
// that send MIDI notes on channel 14
//Digital(pin_t pin, uint8_t note, uint8_t channel, uint8_t velocity = 127, latch time)
//pin: the digital input pin to read the state from, the internal pull-up resistor will be enabled
//note: the MIDI note number [0, 127]
//channel: the MIDI channel [1, 16]
//velocity: the MIDI velocity of the Note events [1, 127], how hard the key/button is struck
};

DigitalLatch Arcadebuttonextras[] = {
{buttonsmux2.pin(3), 8, 14, 127, 10},
{buttonsmux2.pin(4), 9, 14, 127, 10},
//extra two arcade buttons
};

Digital Navigation[] = {
{buttonsmux2.pin(5), 10, 14, 127},
{buttonsmux2.pin(6), 11, 14, 127},
{buttonsmux2.pin(7), 12 , 14, 127},
// Create 3 new instances of the class 'Digital' for navigation buttons, on the 3 pins of the buttonsmux2
// that send MIDI notes on channel 14
//Digital(pin_t pin, uint8_t note, uint8_t channel, uint8_t velocity = 127, latch time)
//pin: the digital input pin to read the state from, the internal pull-up resistor will be enabled
//note: the MIDI note number [0, 127]
//channel: the MIDI channel [1, 16]
//velocity: the MIDI velocity of the Note events [1, 127], how hard the key/button is struck
};

//CONSTANT VALUES

const static byte Channel_Volume = 0x7;
// controller number 7 is defined as Channel Volume in the MIDI implementation.
const static size_t analogAverage = 8;
// Use the average of 8 samples to get smooth transitions and prevent noise
const static byte velocity = 127;
// the maximum velocity, since MIDI uses a 7-bit number for velocity.
const static int latchTime = 3000;
// the amount of time (in ms) the note is held on. Read documentation or see source code for more information.
const static byte C4 = 60;
// note number 60 is defined as middle C in the MIDI implementation.
const static byte E0 = 16;
// note number 60 is defined as middle C in the MIDI implementation, so 16 is E0
const byte Channel = 14;
// MIDI channel 14
const byte Controller = 0x14;
// MIDI controller number
const int speedMultiply = 1;
// no change in speed of the encoder

void setup() {

}
void loop() {

MIDI_Controller.refresh();
}
 
Last edited:
Sorry, this should probably be in the "tech support" sub, my mistake
Probably not an issue. As many of us read most/all messages coming in.

And for example I have not tried to answer this one as I have never done anything with midi nor some of the other libraries, so figured I would not be much help...

So hopefully someone who uses these will be able to give you a better answer.
 
Probably not an issue. As many of us read most/all messages coming in.

And for example I have not tried to answer this one as I have never done anything with midi nor some of the other libraries, so figured I would not be much help...

So hopefully someone who uses these will be able to give you a better answer.

thanks - if tying the select pins to ground doesn't work, I guess I may have to start again at the beginning as I suspect something somewhere is mis-connected, but if it is i can't see it! don't think my mistake is in the code...
 
It might not be you.

It's possible Teensy is running the code too fast for signals to stabilize after the mux is set.

You could try a 5 microseconds delay between lines 7 and 8 of the analog mux library .cpp
 
thanks, will definitely give that a try!
Had exhausted my knowledge of "things that could be wrong" a bit so all leads gratefully received.
 
It might not be you.

It's possible Teensy is running the code too fast for signals to stabilize after the mux is set.

You could try a 5 microseconds delay between lines 7 and 8 of the analog mux library .cpp


thank you so much for the help!

for anyone reading this in future: this seems to have entirely solved the issue.

I assume it may also be worth adding the same delay between 13 & 14 for analog pins? or perhaps not as it is already using analogRead - will that be taking care of this?

thanks again, so happy to be able to push on with this.
 
Yes... the analog needs it too; even more so as it needs an accurate reading and not just to cross a threshold.
 
Status
Not open for further replies.
Back
Top