DIYstompboxes.com

DIY Stompboxes => Building your own stompbox => Topic started by: Esppse on January 20, 2023, 12:19:40 PM

Title: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 12:19:40 PM
Hello,

I have been trying to create a tiny midi keyboard that supposed to be installed into one of my projects. I have come close to getting it to work but have not fully completed it.

Basically, most of the buttons are just Note on/off messages. However when I press one button, it shoots out for example A2, A#2, B3 all at once instead of just the assigned A2 note.

This key has 27 buttons, and I am using 2 multiplexers:
https://www.digikey.com/en/products/detail/e-switch/TL1105EF250Q7-3RED/10371?utm_medium=email&utm_source=oce&utm_campaign=4251_OCE22RT&utm_content=productdetail_US&utm_cid=3297766&so=78637232&mkt_tok=MDI4LVNYSy01MDcAAAGH-elfm9y1eAZbHdq1hCFkVa62ie4oErS80ftLVnWY-MTAg7RnYHCWNhLOdJGfLP30tSF50fVUiWwAn3ucNgSr2BeZogcXdLfOts_4jRmm

https://www.digikey.com/en/products/detail/onsemi/MC74HC4067ADWR2G/2512516?utm_medium=email&utm_source=oce&utm_campaign=4251_OCE22RT&utm_content=productdetail_US&utm_cid=3297766&so=78738185&mkt_tok=MDI4LVNYSy01MDcAAAGIG7jmufc3TCC4wp6MjiCfCjYvcK64lETjFqDnhzcs9n8JoRBQBpeajz8ZFd4tQEbPB2Dx_rfjZIJeK2P-NzcscpZ78RJlOkhClxSTLmk4

I used the code from here:
https://www.youtube.com/watch?v=NmxoBdEJG28&t=902s

Here was when the Nano was used:
https://www.youtube.com/watch?v=ellhUszaMZs

The code was specifically for the Arduino Uno, however in one of the other tutorials from the same channel, the Nano was supposed to be compatible as well. I followed the instructions for the code exactly as shown in the tutorial. 1 button works right, the others either shoot out multiple notes, or nothing at all.

Here is the schematic and pcb(double sided, only top shown below):


(https://i.postimg.cc/8Jb67xPp/Midi-Keys-schematic.png) (https://postimg.cc/8Jb67xPp)

(https://i.postimg.cc/dZtTrnL8/midi-pcb.png) (https://postimg.cc/dZtTrnL8)


I am not sure what is wrong, but I must inquire about the multiplexers. Should I have used a digital multiplexer or an analog multiplexer? I went with analog for the midi keys. Only 1 button works correctly (the middle All Notes Off button). I checked the soldering with a multimeter and the schematic, I think it is all good there. Very simple, one side of button is GND, one side goes to an input pin on a multiplexer.

2 multiplexers, so S0, S1, S2, and S3 on both multiplexers are parallel, go to Nano Pin 2-3-4-5. E and GND on both multiplexers are grounded. Output of 1st multiplexer to Nano Pin 9. Output of 2nd multiplexer to Nano Pin 10.

Is there another midi keyboard code template that already exists that I can try with the Nano controller?
Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 20, 2023, 01:18:03 PM
It doesn't look too impossible to sort out.

There's two 1-to-16 multiplexers (did you use the 74HC4067 like in the schematic?), both permanently enabled. There's four address lines to select one of the inputs on each of the multiplexers, and then there's the two multiplexer outputs (MUX1 & 2) going back to the Arduino.

There's no pull-ups on the schematic, so the Arduino code will need to specify pull-ups on the chip's two MUX inputs. Without a default "high" level, you can't detect when a switch pulls it low.

Have you got a link to the code? It sounds like something isn't configured right.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 02:09:24 PM
Quote from: ElectricDruid on January 20, 2023, 01:18:03 PM
It doesn't look too impossible to sort out.

There's two 1-to-16 multiplexers (did you use the 74HC4067 like in the schematic?), both permanently enabled. There's four address lines to select one of the inputs on each of the multiplexers, and then there's the two multiplexer outputs (MUX1 & 2) going back to the Arduino.

There's no pull-ups on the schematic, so the Arduino code will need to specify pull-ups on the chip's two MUX inputs. Without a default "high" level, you can't detect when a switch pulls it low.

Have you got a link to the code? It sounds like something isn't configured right.

Yep I used 2 of those multiplexers.

This is the original template from notes & volts:
https://drive.google.com/file/d/0BwnVMB_6yujwR1dydVJ6MHJib2M/view?resourcekey=0-pn-udeWBz6syK75kNbdIkg

And here is my modified one for the notes/cc messages I wanted:
https://easyupload.io/kk629u
Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 20, 2023, 03:54:15 PM
Ok, thanks, that's good.

When I open the MIDI_Controller_v1_2 folder, I see an Arduino sketch MIDI_Controller_v1-2.ino, whichopens and show me the assignments and so on, with Controller.cpp, and Controller.h  in the windows in the background.

When I open your 20 Key MIDI Controller folder, I see an Arduino sketch called 20 Key MIDI Controller.ino, but when I open that, I only see Controller.cpp and Controller.h. What happened to the main file with all the definitions and assignments and stuff?
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:24:45 PM
Quote from: ElectricDruid on January 20, 2023, 03:54:15 PM
Ok, thanks, that's good.

When I open the MIDI_Controller_v1_2 folder, I see an Arduino sketch MIDI_Controller_v1-2.ino, whichopens and show me the assignments and so on, with Controller.cpp, and Controller.h  in the windows in the background.

When I open your 20 Key MIDI Controller folder, I see an Arduino sketch called 20 Key MIDI Controller.ino, but when I open that, I only see Controller.cpp and Controller.h. What happened to the main file with all the definitions and assignments and stuff?

I am unsure what the definitions and assignments are. I basically zipped up the entire arduino sketch folder.

Does it look like this when you open 20 Key Midi controller?

(https://i.postimg.cc/GThpj82W/Screenshot-8.png) (https://postimg.cc/GThpj82W)

Which file am I missing to add to the zip? There are a total of 3 files right?
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:33:19 PM
Hmm, when I open the file from the zip, its shows one tab. The 20 Key Midi Controller.

When the files are all extracted, it shows all 3 tabs. Did you try to extract all files first? Or double clicked the 20 key Midi controller from inside Winzip?

Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 20, 2023, 04:36:33 PM
Quote from: Esppse on January 20, 2023, 04:33:19 PM
Hmm, when I open the file from the zip, its shows one tab. The 20 Key Midi Controller.

When the files are all extracted, it shows all 3 tabs. Did you try to extract all files first? Or double clicked the 20 key Midi controller from inside Winzip?

I unzipped, then opened "20 Key Midi Controller.ino". This is what I see:
(https://i.postimg.cc/yJNZfZzf/Screenshot.png) (https://postimg.cc/yJNZfZzf)

Only two files. I can see three in the zip, but the one that I clicked on doesn't show up for some reason.

It looks like the Arduino environment doesn't like that file maybe? I can open it with other applications ok. I'll have a look and see if I can spot anything.

At least I can see your button definitions and so on now.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:37:09 PM
This is what it look like when all files are extracted first:

(https://i.postimg.cc/MXKR5XhZ/Screenshot-9.png) (https://postimg.cc/MXKR5XhZ)

And if only 1 file is double clicked, see how the Controller tabs are missing:


(https://i.postimg.cc/bs4tqgdd/Screenshot-10.png) (https://postimg.cc/bs4tqgdd)

Is this what you mean?
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:38:33 PM
Hmm odd, I am not sure why its showing up like that. Is it a different version of Arduino IDE that would do this? Im very new to this coding arduino stuff. I downloaded the latest version recently.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:39:29 PM
Im on version 2.0.3
Title: Re: Struggling with making an arduino nano midi controller
Post by: Kevin Mitchell on January 20, 2023, 04:41:03 PM
I've actually breadboarded my own midi controller using analog multiplexers recently. Got pretty far before the next shiny thing came along to distract me  :icon_lol:
Without getting into the code right now, I will say that it would be ideal to have pullup resistors on the mux pins for each button. 10K to +5v should be fine. This will help stabilize the readings to avoid false presses.

Alternatively, when plugging the buttons straight into the MCU you would do this with the atmega's internal pullup resistors through code.

FYI - anything UNO ready is also NANO ready. The main difference between the two dev boards is that the nano uses a resonator instead of a quartz crystal. Typically the timing between the two is negligible, until it isn't.
They also use different USART to USB chips for serial communications.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:41:36 PM
This is what should be in the main 20 Key Midi Controller file:
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 20, 2023, 04:42:17 PM
If you want to show code here, open the sketch in Arduino and control A to select all the text, copy it then use the "Code" tags in the reply (the one with the #). Paste the text in the tags. It shouldn't mess with the formatting.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:42:23 PM
#include <MIDI.h>
#include "Controller.h"

/*************************************************************
  MIDI CONTROLLER

  by Notes and Volts
  www.notesandvolts.com

  Version 1.2 **Arduino UNO ONLY!**
*************************************************************/

MIDI_CREATE_DEFAULT_INSTANCE();

//************************************************************
//***SET THE NUMBER OF CONTROLS USED**************************
//************************************************************
//---How many buttons are connected directly to pins?---------
byte NUMBER_BUTTONS = 0;
//---How many potentiometers are connected directly to pins?--
byte NUMBER_POTS = 0;
//---How many buttons are connected to a multiplexer?---------
byte NUMBER_MUX_BUTTONS = 27;
//---How many potentiometers are connected to a multiplexer?--
byte NUMBER_MUX_POTS = 0;
//************************************************************

//***ANY MULTIPLEXERS? (74HC4067)************************************
//MUX address pins must be connected to Arduino UNO pins 2,3,4,5
//A0 = PIN2, A1 = PIN3, A2 = PIN4, A3 = PIN5
//*******************************************************************
//Mux NAME (OUTPUT PIN, , How Many Mux Pins?(8 or 16) , Is It Analog?);


Mux M1(9, 16, false); //Digital multiplexer on Arduino pin 10
Mux M2(10, 16, false); //Analog multiplexer on Arduino analog pin A0
//*******************************************************************


//***DEFINE DIRECTLY CONNECTED POTENTIOMETERS************************
//Pot (Pin Number, Command, CC Control, Channel Number)
//**Command parameter is for future use**

//Pot PO1(A0, 0, 1, 1);
//Pot PO2(A1, 0, 10, 1);
//Pot PO3(A2, 0, 22, 1);
//Pot PO4(A3, 0, 118, 1);
//Pot PO5(A4, 0, 30, 1);
//Pot PO6(A5, 0, 31, 1);
//*******************************************************************
//Add pots used to array below like this->  Pot *POTS[] {&PO1, &PO2, &PO3, &PO4, &PO5, &PO6};
Pot *POTS[] {};
//*******************************************************************


//***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
//Button (Pin Number, Command, Note Number, Channel, Debounce Time)
//** Command parameter 0=NOTE  1=CC  2=Toggle CC **

//Button BU1(2, 0, 60, 1, 5 );
//Button BU2(3, 0, 61, 1, 5 );
//Button BU3(4, 0, 62, 1, 5 );
//Button BU4(5, 0, 63, 1, 5 );
//Button BU5(6, 0, 64, 1, 5 );
//Button BU6(7, 0, 65, 1, 5 );
//Button BU7(8, 1, 64, 1, 5 );
//Button BU8(9, 2, 64, 1, 5 );
//*******************************************************************
//Add buttons used to array below like this->  Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
Button *BUTTONS[] {};
//*******************************************************************


//***DEFINE BUTTONS CONNECTED TO MULTIPLEXER*************************
//Button::Button(Mux mux, byte muxpin, byte command, byte value, byte channel, byte debounce)
//** Command parameter 0=NOTE  1=CC  2=Toggle CC **

Button MBU1(M1, 0, 0, 57, 1, 5);
Button MBU2(M1, 1, 0, 58, 1, 5);
Button B3(M1, 2, 0, 59, 1, 5);
Button C4(M1, 3, 0, 60, 1, 5);
Button CS4(M1, 4, 0, 61, 1, 5);
Button D4(M1, 5, 0, 62, 1, 5);
Button Eb4(M1, 6, 0, 63, 1, 5);
Button E4(M1, 7, 0, 64, 1, 5);
Button F4(M1, 8, 0, 65, 1, 5);
Button FS4(M1, 9, 0, 66, 1, 5);
Button G4(M1, 10, 0, 67, 1, 5);
Button GS4(M1, 11, 0, 68, 1, 5);
Button MBU13(M1, 12, 0, 69, 1, 5);
Button Bb4(M1, 13, 0, 70, 1, 5);
Button B4(M1, 14, 0, 71, 1, 5);
Button C5(M1, 15, 0, 72, 1, 5);
Button CS5(M2, 0, 0, 73, 1, 5);
Button D5(M2, 1, 0, 74, 1, 5);
Button Eb5(M2, 2, 0, 75, 1, 5);
Button E5(M2, 3, 0, 76, 1, 5);
Button CCA(M2, 4, 1, 102, 1, 5);
Button CCB(M2, 5, 1, 103, 1, 5);
Button CCC(M2, 6, 1, 104, 1, 5);
Button CCD(M2, 7, 1, 105, 1, 5);
Button CCE(M2, 8, 1, 106, 1, 5);
Button CCF(M2, 9, 1, 107, 1, 5);
Button ANO(M2, 10, 1, 123, 1, 5);

//*******************************************************************
////Add multiplexed buttons used to array below like this->  Button *MUXBUTTONS[] {&MBU1, &MBU2, &MBU3, &MBU4, &MBU5, &MBU6.....};
Button *MUXBUTTONS[] {&MBU1, &MBU2, &B3, &C4, &CS4, &D4, &Eb4, &E4, &F4, &FS4, &G4, &GS4, &MBU13, &Bb4, &B4, &C5, &CS5, &D5, &Eb5, &E5, &CCA, &CCB, &CCC, &CCD, &CCE, &CCF, &ANO};

//*******************************************************************


//***DEFINE POTENTIOMETERS CONNECTED TO MULTIPLEXER*******************
//Pot::Pot(Mux mux, byte muxpin, byte command, byte control, byte channel)
//**Command parameter is for future use**

//Pot MPO1(M2, 0, 0, 1, 1);
//Pot MPO2(M2, 1, 0, 7, 1);
//Pot MPO3(M2, 2, 0, 50, 1);
//Pot MPO4(M2, 3, 0, 55, 2);
//Pot MPO5(M2, 4, 0, 50, 1);
//Pot MPO6(M2, 5, 0, 55, 2);
//Pot MPO7(M2, 6, 0, 50, 1);
//Pot MPO8(M2, 7, 0, 55, 2);
//Pot MPO9(M2, 8, 0, 50, 1);
//Pot MPO10(M2, 9, 0, 55, 2);
//Pot MPO11(M2, 10, 0, 50, 1);
//Pot MPO12(M2, 11, 0, 55, 2);
//Pot MPO13(M2, 12, 0, 50, 1);
//Pot MPO14(M2, 13, 0, 55, 2);
//Pot MPO15(M2, 14, 0, 50, 1);
//Pot MPO16(M2, 15, 0, 55, 2);
//*******************************************************************
//Add multiplexed pots used to array below like this->  Pot *MUXPOTS[] {&MPO1, &MPO2, &MPO3, &MPO4, &MPO5, &MPO6.....};
Pot *MUXPOTS[] {};
//*******************************************************************


void setup() {
  MIDI.begin(MIDI_CHANNEL_OFF);
}

void loop() {
  if (NUMBER_BUTTONS != 0) updateButtons();
  if (NUMBER_POTS != 0) updatePots();
  if (NUMBER_MUX_BUTTONS != 0) updateMuxButtons();
  if (NUMBER_MUX_POTS != 0) updateMuxPots();
}


//*****************************************************************
void updateButtons() {

  // Cycle through Button array
  for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
    byte message = BUTTONS[i]->getValue();

    //  Button is pressed
    if (message == 0) {
      switch (BUTTONS[i]->Bcommand) {
        case 0: //Note
          MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
          break;
        case 1: //CC
          MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
          break;
        case 2: //Toggle
          if (BUTTONS[i]->Btoggle == 0) {
            MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
            BUTTONS[i]->Btoggle = 1;
          }
          else if (BUTTONS[i]->Btoggle == 1) {
            MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
            BUTTONS[i]->Btoggle = 0;
          }
          break;
      }
    }

    //  Button is not pressed
    if (message == 1) {
      switch (BUTTONS[i]->Bcommand) {
        case 0:
          MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
          break;
        case 1:
          MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
          break;
      }
    }
  }
}
//*******************************************************************
void updateMuxButtons() {

  // Cycle through Mux Button array
  for (int i = 0; i < NUMBER_MUX_BUTTONS; i = i + 1) {

    MUXBUTTONS[i]->muxUpdate();
    byte message = MUXBUTTONS[i]->getValue();

    //  Button is pressed
    if (message == 0) {
      switch (MUXBUTTONS[i]->Bcommand) {
        case 0: //Note
          MIDI.sendNoteOn(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
          break;
        case 1: //CC
          MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
          break;
        case 2: //Toggle
          if (MUXBUTTONS[i]->Btoggle == 0) {
            MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
            MUXBUTTONS[i]->Btoggle = 1;
          }
          else if (MUXBUTTONS[i]->Btoggle == 1) {
            MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
            MUXBUTTONS[i]->Btoggle = 0;
          }
          break;
      }
    }
    //  Button is not pressed
    if (message == 1) {
      switch (MUXBUTTONS[i]->Bcommand) {
        case 0:
          MIDI.sendNoteOff(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
          break;
        case 1:
          MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
          break;
      }
    }
  }
}
//***********************************************************************
void updatePots() {
  for (int i = 0; i < NUMBER_POTS; i = i + 1) {
    byte potmessage = POTS[i]->getValue();
    if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);
  }
}
//***********************************************************************
void updateMuxPots() {
  for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
    MUXPOTS[i]->muxUpdate();
    byte potmessage = MUXPOTS[i]->getValue();
    if (potmessage != 255) MIDI.sendControlChange(MUXPOTS[i]->Pcontrol, potmessage, MUXPOTS[i]->Pchannel);
  }
}

Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 20, 2023, 04:43:21 PM
Quote from: Esppse on January 20, 2023, 04:37:09 PM
Is this what you mean?

No. I'm using Arduino 1.8.8 on a Mac, so it's not the latest version. But this doesn't look like a "latest version" issue, to be honest. If you want I suppose I can try upgrading it.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:44:48 PM
I just uploaded the code, hopefully it posted ok. Strange that it wasn't showing up on yours. Im not sure if the assignments are broken after zipping from 7zip?
Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 20, 2023, 04:49:18 PM
The bit that most struck me suspicious was this part from Controller.cpp:


void Button::muxUpdate()
{
  byte temp = _muxpin;
  temp = temp << 2;
  if (_numMuxPins > 8) PORTD = PORTD & B11000011;
  else PORTD = PORTD & B11100011;
  PORTD = PORTD | temp;
}


That's *very* specific. Are you sure you have your Muxes wired up to exactly the pins they're using? If not, the muxes might finish up scanning through some sub-group of inputs multiple times (like doing buttons 1 to 4 over and over, or doing buttons 1-8 twice through, instead of doing all 16). That would lead to several "software buttons" being triggered by the same "hardware button" - the code thinks it's reading button 8, but really it's reading button 0 again because the Mux isn't addressed correctly.

Do you see what I mean?

Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 04:56:48 PM
Yes, I checked the pin to the proper destination with a multimeter. The PCB created was auto routed using EasyEDA. I also checked for solder bridges, it all looks clean. It uses 27 out of 32 input pins. I put 27 in the section that asks how many are attached. Is that correct?


(https://i.postimg.cc/QKhrQR6V/20230120-165525.jpg) (https://postimg.cc/QKhrQR6V)
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 05:00:13 PM
The last button in the series of all buttons works right for some reason. The ANO (all notes off) one.
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 20, 2023, 05:23:04 PM
Does the middle pin of the Midi jack need to be grounded? I am using a UM-One midi interface. I left the Ground from the midi Out of the controller disconnected. The USB cable grounds the controller and the keybed. Does the UM-One interface require that?
Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 20, 2023, 05:31:54 PM
Have you got any way you can check that you get the correct incrementing count on the S0-S1-S2-S3 Mux address pins? They should all be at octave frequencies, since it's a binary count.

You showed us a picture of your PCB, but not of your arduino or where the wires from the PCB go to. Can we see that too, please? Clearly if the board is wired to the Arduino incorrectly, it's not going to do what it's supposed to do.

Also please tell us what you think you've done - what you've connected to what and why. This is partly so we can cross-check, but also because I often find that by trying to explain something to someone I go "Aaaaahhhh!!!" and realise what it was that I was missing. So explain to us in complete detail how the two boards connect together and which pins go to which and what each one does. You might find you have a "Aaah!" moment too.


Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 21, 2023, 11:48:30 AM
Quote from: ElectricDruid on January 20, 2023, 05:31:54 PM
Have you got any way you can check that you get the correct incrementing count on the S0-S1-S2-S3 Mux address pins? They should all be at octave frequencies, since it's a binary count.

You showed us a picture of your PCB, but not of your arduino or where the wires from the PCB go to. Can we see that too, please? Clearly if the board is wired to the Arduino incorrectly, it's not going to do what it's supposed to do.

Also please tell us what you think you've done - what you've connected to what and why. This is partly so we can cross-check, but also because I often find that by trying to explain something to someone I go "Aaaaahhhh!!!" and realise what it was that I was missing. So explain to us in complete detail how the two boards connect together and which pins go to which and what each one does. You might find you have a "Aaah!" moment too.

Ok here are some more detailed pictures of the wires:

So the color code is:
S1: White
S2: Blue
S3: Green
S4: Yellow

M1: Orange
M2: Purple

5V: Red
GND: Black

2-3-4-5 need to be S0-S1-S2-S3 according to the instructions so I have done that. 5V goes to the VCC pin on both Multiplexers. All the buttons (bottom pin), GND, and Enable pins on the multiplexers are all grounded.

220 Ohm resistors for midi (to 5V and to TX pins)

What does increment counting mean on S0-S1-S2-S3? Sorry, very new to digital coding.

(https://i.postimg.cc/QVp1qz8s/20230121-114156.jpg) (https://postimg.cc/QVp1qz8s)

(https://i.postimg.cc/rKMWZ9s4/20230121-114157.jpg) (https://postimg.cc/rKMWZ9s4)

(https://i.postimg.cc/RNdtknJD/20230121-114214.jpg) (https://postimg.cc/RNdtknJD)

(https://i.postimg.cc/zyfh8XnX/20230121-114236.jpg) (https://postimg.cc/zyfh8XnX)
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 21, 2023, 01:56:56 PM
Even if you don't have a scope, your DMM reading volts can give clues when hunting logic bugs.
Assuming it runs off 5v...
5V reading means it's stuck high and not pulsing (unless really fast narrow pulses). Conversely, 0v tells the same story.
2.5v or near suggests it is pulsing and you would expect a counter output to read very close to 2.5v.
S0 to S3 counts up (or down!) in binary...
S3>S0
0000
0001
0010
0011... etc until
1111 then back to...
0000 and repeat.
Any of these pins will read around 2.5v.
The 4 S pin bits select which of the mux chips inputs connect to the COM pin.
When you press a switch, it will ground whichever mux input is selected and be read as a 0 on either mux1 or mux2, otherwise, with no buttons pressed, the mux inputs will stay near 5v and read as 1(with MCU pin pull-up enabled).
The program uses the current select count and the state of the mux input to work out which key has been pressed.

Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 22, 2023, 06:36:38 AM
Well, I dunno. I've been through your code and checked the button assignments and mux setup and whathaveyou, and it all looks ok. The wires are wired up as per the comments in the code - Mux S pins to pins 2,3,4,5, and the two mux common wires on pins 9 and 10. It *looks* like it should be simple, but if it's not working, it isn't.

Something's not right somewhere, but without knowing what the Arduino code is *expecting* it's hard to find.

It still sounds to me like the Mux isn't scanning properly, but I don't know why that would be the case. Are you sure that the Nano is a drop-in replacement for the Uno in this case? If the code assumed a certain pin layout which is only true on the Uno, that could explain why things aren't working for you.
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 22, 2023, 08:30:27 AM
Nano is just using the SMD quad pack ATMega328 while the Uno is a DIP28 version - the same chip. Although the Nano can have 2 more pins for the complete 8 bits of portA versus 6 bits.
Title: Re: Struggling with making an arduino nano midi controller
Post by: ElectricDruid on January 22, 2023, 11:24:21 AM
Quote from: anotherjim on January 22, 2023, 08:30:27 AM
Nano is just using the SMD quad pack ATMega328 while the Uno is a DIP28 version - the same chip. Although the Nano can have 2 more pins for the complete 8 bits of portA versus 6 bits.

I see. Thanks Jim. That does sound pretty interchangeable. Dang! There goes another theory!  :icon_eek:
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 22, 2023, 09:42:38 PM
Quote from: anotherjim on January 21, 2023, 01:56:56 PM
Even if you don't have a scope, your DMM reading volts can give clues when hunting logic bugs.
Assuming it runs off 5v...
5V reading means it's stuck high and not pulsing (unless really fast narrow pulses). Conversely, 0v tells the same story.
2.5v or near suggests it is pulsing and you would expect a counter output to read very close to 2.5v.
S0 to S3 counts up (or down!) in binary...
S3>S0
0000
0001
0010
0011... etc until
1111 then back to...
0000 and repeat.
Any of these pins will read around 2.5v.
The 4 S pin bits select which of the mux chips inputs connect to the COM pin.
When you press a switch, it will ground whichever mux input is selected and be read as a 0 on either mux1 or mux2, otherwise, with no buttons pressed, the mux inputs will stay near 5v and read as 1(with MCU pin pull-up enabled).
The program uses the current select count and the state of the mux input to work out which key has been pressed.

I just checked the voltages of all the buttons, they are all over the place. A bunch read between 3.6-4.3.  A few read 2.9. And there were a couple as low as 1.12.

Like on the first multiplexer, the first 12 input pins read 4.3. Then the rest gradually drop 3.7, 2.9, 2.0, 1.1.
The first 2 on the second multiplexer reads 2.0. Then the next 7 are 3.7. The last 2 are 4.2. Rest unused. 

S0-S3 are all about 2.0.
M1 is 4.5
M2 is 3.1.

V is 4.67

I am assuming this is irregular?
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 23, 2023, 05:00:13 AM
S0-S3 may be ok. Each of those S pins will be 1 for close to the same time period they are 0 so the DMM will average the reading to half of the total voltage. 2v isn't too bad and all four being the same is good.

The two Mux inputs though should be both close to supply volts with no button pressed and it seems that only one is.

Because each button only gets selected by a mux chip for 1/16th of the total scan time, the button pins of the mux chip only tell the truth 1/16th of the time. They will "float" at no particular level when unselected and no button is pressed. Your DMM won't see this as it ought to zero on a disconnected wire, but perhaps it's sensitive enough to read leakage in the mux chip or from the wiring. Pressing a button only connects the mux pin to 0v for 1/16th of the time, so it will only cause a tiny drop in the average reading.

Are the mux chips in sockets? Take them out and see what the Arduino mux inputs read then. They should both be 4.9 ish.
If they are good, turn off and use the DMM continuity test to look for shorts between adjacent mux pins and that a pin shorts to 0v when its button is pressed.

If the chips are not socketed, you'll have to disconnect the two mux wires. You can still do continuity checks of the mux chips, but be careful to keep probe polarity correct (negative on 0v) or else the CMOS chip pin protection diodes will conduct and fool you.

Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 25, 2023, 01:43:16 PM
Quote from: anotherjim on January 23, 2023, 05:00:13 AM
S0-S3 may be ok. Each of those S pins will be 1 for close to the same time period they are 0 so the DMM will average the reading to half of the total voltage. 2v isn't too bad and all four being the same is good.

The two Mux inputs though should be both close to supply volts with no button pressed and it seems that only one is.

Because each button only gets selected by a mux chip for 1/16th of the total scan time, the button pins of the mux chip only tell the truth 1/16th of the time. They will "float" at no particular level when unselected and no button is pressed. Your DMM won't see this as it ought to zero on a disconnected wire, but perhaps it's sensitive enough to read leakage in the mux chip or from the wiring. Pressing a button only connects the mux pin to 0v for 1/16th of the time, so it will only cause a tiny drop in the average reading.

Are the mux chips in sockets? Take them out and see what the Arduino mux inputs read then. They should both be 4.9 ish.
If they are good, turn off and use the DMM continuity test to look for shorts between adjacent mux pins and that a pin shorts to 0v when its button is pressed.

If the chips are not socketed, you'll have to disconnect the two mux wires. You can still do continuity checks of the mux chips, but be careful to keep probe polarity correct (negative on 0v) or else the CMOS chip pin protection diodes will conduct and fool you.

Ok some progress, I disconnected M2 from the Nano. (its S0-S3 pins are still tied with the first multiplexer, and it is still receiving voltage)

M2 is 1.8 volts disconnected from the board.

And interestingly enough, all the buttons tied to the first multiplexer actually work right now! So what is strange is that when M2 goes to the Nano, it affects buttons tied to the first multiplexer. Ex... 1st button sends out A and A# notes. It basically sends out the adjacent button's note assignment, sometimes the next 3. Odd right? What could be causing this?

When I tested it just now, I didnt even change the code to say I only have 1 multiplexer connected, and it still worke (first multiplexer buttons). So that lower voltage on M2 is definitely suspicious. Any ideas?



OK just did another test, I put M2 into Nano Pin 8 instead of 10 (adjusted the code for it). It all works except 1 button. The first input of the second multiplexer.

I tested the physical button, it works correctly, shorting to ground when pressed. The button also passes the continuity test going to the its multiplexer input. And there are no shorts to any adjacent pins. Now this is strange. The note I designated to it is C#4. When I press that button, it wont send out the note. When I push a different button, sometimes it sends out C#4 like 12 times. As if the previous presses were "held", then released when I pressed a different button. But I cant replicate this behavior though. Is this a bad chip?
Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 25, 2023, 02:12:50 PM
Another test, for some reason, that button came to life just now... but unfortunately that random stream comes out. Look here:


(https://i.postimg.cc/YGRhT2CG/Screenshot-11.png) (https://postimg.cc/YGRhT2CG)


All the C#4 messages shown here were after a different button was pressed.
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 25, 2023, 04:46:09 PM
If you're going by silkscreen legends on a board -  they can have errors. I spent ages trying to get midi i/o working until I realized they had swapped the UART Tx and Rx pin legends on a Uno clone board.
Also, some I/O shares functions or have something attached. The onboard LED they have for the test/programming indicator might be in the way - it can stop a pin being used as an input.
You may need to check with the Arduino board documentation. They are supposed to be open source so it should exist.

Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 26, 2023, 07:46:46 AM
So, I tried to read thru the sketch (not 100% familiar with this high-level language stuff), and I don't see any nuts&bolts pin setup commands at all. I do see an #include for controller.h, so I imagine this is a barebones framework for this application. In which case, I have no idea what it's doing!
I do suspect M2 is behaving like it has no pull-up enabled. It's odd that it's connected to A0, which can be used for digital input, but it has to be told that somewhere.
It could be proved by fitting an external pull-up resistor on M2 to 5v, 10k to 100k.
Note that AVR chip inputs include Schmitt trigger action, so an input voltage floating between 0v and 5v will be ignored.

Title: Re: Struggling with making an arduino nano midi controller
Post by: Esppse on January 26, 2023, 08:19:51 AM
Quote from: anotherjim on January 26, 2023, 07:46:46 AM
So, I tried to read thru the sketch (not 100% familiar with this high-level language stuff), and I don't see any nuts&bolts pin setup commands at all. I do see an #include for controller.h, so I imagine this is a barebones framework for this application. In which case, I have no idea what it's doing!
I do suspect M2 is behaving like it has no pull-up enabled. It's odd that it's connected to A0, which can be used for digital input, but it has to be told that somewhere.
It could be proved by fitting an external pull-up resistor on M2 to 5v, 10k to 100k.
Note that AVR chip inputs include Schmitt trigger action, so an input voltage floating between 0v and 5v will be ignored.


M2 is actually connected to digital pin 8. I originally tried 10 but that didn't work for some reason. This is the second micro controller I tried with this garbled messaging. The first one was an ItsyBitsy.

Does it say somewhere that M2 is connected to A0? Some of the text in the code is actually "example user help text" and has no effect on the output.

I assume you mean this:
Mux M2(10, 16, false); //Analog multiplexer on Arduino analog pin A0

The text after the semicolon was just default example text that may be deletable. The 2 forward slashes make that part dim in the Arduino program, which I think is inactive.
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 26, 2023, 09:09:55 AM
Quote//Analog multiplexer on Arduino analog pin A0
Everything after // on the line is ignored by the compiler. It's a Comment, meant to help understand the code. Get in the habit of fixing it if it's not relevant.

QuotepinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors
This is how an Arduino sketch sets up a pin function for input with pullup.

QuoteMux M2(10, 16, false)
This function looks like it's looking for a button press returning a 0 (false) but I've no idea what 10 & 16 mean unless it's testing a specific location in an array which is probably what controller.h code is working. That included code may be written in C anyway since Arduino language only works one pin at a time for I/O and it needs to handle 4bits for the mux chip addressing.

Title: Re: Struggling with making an arduino nano midi controller
Post by: FiveseveN on January 26, 2023, 02:46:27 PM
Quote from: anotherjim on January 26, 2023, 09:09:55 AM
probably what controller.h code is working
Something along those lines. It defines Mux
Mux(byte outpin_, byte numPins_, bool analog_);

And two other classes:
Button(byte pin, byte command, byte value, byte channel, byte debounce);
Button(Mux mux, byte muxpin, byte command, byte value, byte channel, byte debounce);

Pot(byte pin, byte command, byte control, byte channel);
Pot(Mux mux, byte muxpin ,byte command, byte control, byte channel);
Title: Re: Struggling with making an arduino nano midi controller
Post by: anotherjim on January 27, 2023, 05:02:08 PM
Well, I don't know. It looks like controller.h expects 16 buttons on mux1 and 16 pots on mux2 doesn't it? That would explain why the code has A0 for mux2, it's feeding the chips ADC.