I am preparing to undertake my first Arduino project, building a microtonal MIDI controller and could use some help making sure I get a setup that should work to hopefully save some time and money as I am developing it.
The MIDI controller will be an 8 x 32 grid of 256 mechanical keyboard keys and would need to be able to handle at least 10 keys being pressed simultaneously. I am aware that MIDI only uses 128 notes, but this will be used for microtonal scales and will be sending data for MPE and or MIDI 2.0. I would like to use analog keys to be able to make the controller pressure/velocity sensitive, and potentially would like to have RGB LEDs for each key as well. I am willing to drop those two requirements if they are too difficult to implement.
As well, the controller will have approximately 20 additional digital input keys, a small LCD or OLED screen, an endless encoder, additional LEDs, and a few potentiometers for editing paramaters, mod cc, transposing, etc.
What would be the best setup for this project? I realize that 256+ is a lot of inputs, especially if they need to be analog. However, I would like to make it. Would multiplexing be the best option for expanding analog connectivity? What potential problems would I run into? What board or boards, expanders or multiplexers, would you recommend for this project. Should I consider something other than Arduino?
I have considered that if having each key analog pressure sensitive is not feasible that I could do a matrix approach that I would need to code to handle multiple inputs. What board/expansion would be best for this approach?
Thanks for any input. If you need more clarification, let me know.
This is not a first Arduino project. This is an advanced/expert level Arduino project.
There is a great risk that those that would like to help you would be wasting their time. They will pour out well meaning advice and you will realise the scale and difficulty of the project, and how far ahead of your current knowledge and experience it is, and you will slip away quietly. It happens frequently on the forum.
So you first task will be to convince others why this is not going to happen.
Thanks for the concern. I have experience programming audio/midi plugins and have done my share of dabbling in electronics, but not with microcontrollers. I am aware of the development process, testing concepts, and scaling. I am not asking what I should do for my first project, or whether it is too big etc. I am considering Arduino because it seems like the tool to use for what I want to make, rather than just coming up with a project to learn how to use Arduino.
As for people spending time to give advice or direction, that is up to them, and the benefit is for the community as a whole that the knowledge base increases. I am only asking because I could not find someone asking a similar enough question to satisfy what I am looking for. Whether I will end up finishing the project or not, is beside the point. Of course I hope to finish it, but even if I don't, I will be learning and enjoying the process along the way, and others can learn from what I contribute as I engage with the community as well.
I am asking for some suggestions from those who may have undergone similar projects, what it might take, and what's possible, limitations etc. so that I have a reasonable idea of where I'm headed, and hopefully save some time and money in the long run. The main issue that I'm foreseeing is the limitation on the number of pins and how to best increase that. I know that I can mitigate that by using a matrix and not using analog keys, but would like to figure out if analog is feasible and potentially what hurdles I would run into.
Sounds like you are on a reasonable track. Since MIDI interfaces and controllers are popular projects with Arduino, what have you found on line in the way of useful approaches or even model projects?
Would multiplexing be the best option for expanding analog connectivity
It is the only option.
Please consider that this forum attracts lots of beginners who have no idea how anything works, come here with totally impractical or impossible projects, and ask for finished code and wiring diagrams.
I haven't been able to find a ton on multiplexing, and don't quite yet understand how it works yet. I know I probably just need to dig more. I'm curious how responsive they would be as many of the projects I've found using them are for applications where latency doesn't matter. There should be projects using analog keys for gaming keyboards that would handle the issue, but haven't found one yet. Other possibilities outside of multiplexing I've considered would be using multiple microcontrollers, or pin expanders, the later seem to be primarily for digital inputs from what I can gather, and using multiple microcontrollers seems like an awkward solution.
On any Arduino with an ADC, the ADC input is already multiplexed over several pins, typically 8 or 16. You would know this if you had, say, a basic Arduino Uno R3, and experimented with the analogRead() function.
What do you want to multiplex? Device communications, analog input channels, or ...?
I would like to have 256 analog mechanical keyboard keys. Each would have it's own variable signal that it could send depending on how far it is depressed. I don't believe a matrix would be ideal for this because of the changing variable voltage.
One option would be 16x(ATmega640/1280/2560), each with 16 internally multiplexed analog inputs.
Another would be a custom board with 16x analog signal multiplexer chips (e.g. CD4067B), each feeding to one of the 16, internally multiplexed, analog input channels of an Arduino Mega2560.
@fuzzybeverage I feel reassured by your replies, both in terms of your reaction to my challenging question and what you have told us about how you would approach the project and your previous relevant experience. Apologies if my challenge seemed harsh or rude. If you become a regular on the forum, helping others with their projects, you will come to understand why I asked it.
So.... What to tell you first?
If you want to be able to plug the Arduino into a PC/laptop and have it recognised as a MIDI device, without having to install extra software to allow the Arduino to emulate a MIDI device, then you need to choose a model of Arduino which has "native USB support". Many of the most common Arduino models, like Uno and Mega, do not have this. They have an extra USB-serial chip and can only appear as a serial communications port to the PC. But an Arduino with native USB support does not need that additional chip and can be configured to appear to the PC to be a serial port, a QUERTY keyboard, a mouse, a joystick or a MIDI device.
Probably the most common and basic types of Arduino that have this ability would be the Arduino Micro or Sparkfun Pro Micro. An additional advantage of these models is that they are breadboard compatible. They plug directly into a breadboard, enabling you to build a much more stable and relatively robust and neat prototype. Building prototypes like this is important step before attempting to design a PCB. It's a common beginner mistake to think they can design a PCB before they have prototyped and tested their circuit design.
Building complex prototypes with Uno and Mega boards and breadboards is almost certain to lead to a prototype which becomes a huge rat's nest of connecting wires which becomes impossible to manage or find faults in (and there will be faults to find!).
There are less common Arduino/Arduino-compatible models which also have native USB, and given your requirement to read many analog input devices, maybe worth considering some of these too.
@PaulRBryson and @jremington
Many thanks to both for your input. The suggestions for multiplexing and info on native USB support are quite helpful. I'll make sure and share what I decide to purchase when I think I have something figured out. Also, no worries on seeming rude, I understand how figuring out where someone is at in experience and understanding could change the way that a question is answered.
Can you post a link to the specs or datasheet of the type of analog mechanical keys you mentioned? Then the forum can suggest ways to connect them with the Arduino. Maybe analog multiplexers is the best and only answer, but there may be other ways.
I would suggest building a prototype with just a small number of these keys, probably 8, to begin with. You might learn something which changes the approach to connecting 256 of them.
Velocity and pressure sensing requires multiple ADC samples over a fraction of a second, which seems quite impractical considering your other requirements of 256 keys, with up to 10 keys pressed at once.
Accomplishing that would require one ADC (not ADC channel), or one microprocessor per key. One ATtiny per key is not a problem, but then you are faced with how to rapidly acquire 2 samples of data from each of 256 ATtinys, also within some fraction of a second.
I agree with @PaulRB suggestion to start with an 8 key model, and reassess project goals as needed.
I finally found an analog switch that I can purchase. If I'm able to figure out how to make this work, it will probably be what I end up going with. I'm thinking there may actually be a way to do it in a matrix, similar to the above video, which would make things much easier. I just need to wrap my head around how it would work.
(sorry for necroposting or whatever it's called, I just realllly wanna talk about this specific project)
Yo, this is definitely a diy lumatone replacement right? I'm actually in almost the exact same situation as I wanna build a big isomorphic keyboard with analog keyswitches
The way I would approach the massive amount of analog keys is by connecting the columns of the button matrix onto a chain of parallel-out shift registers, and the rows into an analog multiplexer. This should work (in theory, haven't tested yet), as only one switch is a part of a closed circuit at a time, so the shift register(s) shouldn't get fried by too much current
I wrote some "dummy" code to test the theoretical polling speed by executing the digitalWrite's and analogRead's as if I was polling the keyswitches and I got a polling rate of 250000/s??? (that can't be right)
int rows = 8*4;
int columns = 8;
int state;
long time;
long finaltime;
void setup() {
Serial.begin(9600);
}
void loop() {
time = micros();
for (int r = 0; r < 10000, r++;) { // testing how long it takes to poll the switches 10000 times
read();
}
finaltime = micros() - time;
Serial.println(finaltime);
}
void read() {
for (int j = 0; j < columns, j++;) {
digitalWrite(2, random(1)); // "selecting" the multiplexer row
digitalWrite(3, random(1));
digitalWrite(4, random(1));
for (int i = 0; i < rows, i++;) {
digitalWrite(5, "HIGH"); // pulsing the relevant shift register pins
digitalWrite(5, "LOW");
digitalWrite(6, "HIGH");
digitalWrite(6, "LOW");
state = analogRead(A0);
}
}
}
Also @fuzzybeverage I would really love to chat with you as our projects are so similar we could offer advice to each other (also MICROTONES!!!1!!)
No worries, thanks for your response. I've been a little side-tracked starting a master's program, but am definitely planning on still doing this project, just a matter of when is the only question. I would love to keep in touch and collaborate/learn from each other, and yes, you are correct in that it is somewhat of a lumatone replacement. On the microtonal end though there's some functionality I want that a lumatone may not be able to do.
Hey thanks for getting back to me!
Now I'm really curious of that additional microtonal functionality you're talking about..!
I was about to ask about the form factor, just read the first message again.. kind of like an extra long linnstrument!
I wonder if you've done pcb design before.. I'm struggling with it myself and I've been trying to gather the courage to actually order something custom from a pcb manufacturer
(I'm on discord and youtube under the same username, hmu)