[noob] Another Arduino is as good as a multiplexer, right?

So, I’ve had a surge of motivation this weekend and my desk is now littered with a subset of the hundreds (read: more than ten) of microcontrollers I’ve amassed over the years. Of these, the most suitable one that is at hand is a Teensy 3.2, which has the type of USB functionality to act as a native USB Midi host. I also have a pile of stomp switches that arrived from China this week, with some other goodies on the way, including the rotary encoders Zynthian uses. It has a fair number of pins available, enough to get one off to a good start, but not enough for my mad science.

If I was starting from nothing I would just order a cheap multiplexer and not even consider dedicating another whole microcontroller to just bringing more pins to the table, but right here in front of me are an Arduino Mega, Uno, a couple of Nanos, and at least four ESP32 devices, one with a small screen on it, which I’m eyeing as a BTMidi brain with minimal info display.

So just in the name of not leaving this stuff in the bin or having to wait any longer, I’m thinking I’ll just let the Mega handle all the hardware interactions and report on the real world to the Teensy, which can handle all midi processing and messaging.

I also have one of these Linksprite Midi Shields, which I did briefly get working back when I first bought it, but fought it for an hour last night and couldn’t get working. However, the keyboard I plugged into it is extremely sus so I haven’t written it off just yet.

So basically at this point I’m envisioning the Mega doing all or most hardware interaction with its absurd number of pins, let the Teensy handle processing/filtering of messages and communication with USB and the real midi ports if I can get that going again.

That’s fine, right? I’m not losing responsiveness or anything by using a microcontroller instead of a simple multiplexer? Being this is a device that will be operated by humans, I can’t see either of the controllers being the bottleneck here.

1 Like

Of course a microcontroller will add some latency as it reads, processes then writes the data and the link between processors will also add latency but it is a fine idea as the latency can be kept sufficiently low to be insignificant.

How are you intending to link your i/o interface (mega) with your brains (teensy)? Maybe you want to use I2C which is a short distance interface designed for just this purpose (communication between ICs).

That was what I was thinking. It took me a longer time than I would prefer to have the thought that “hey, if the arduino can talk to all these other devices with i2c, I bet two of them could talk to each other with it too!”

Got a good suggestion for a primer? This is by far the most ambitious thing I’ve attempted with microcontrollers.

I2C is a multi-master, multi-slave bus system. Any connected device may alter the bus to make requests or respond to requests. There are arduino libraries for I2C master and slave. It would normally make sense to make the Teensy the master which polls for changes and the Mega the slave that sends its data on demand then use an interrupt from the mega to the teensy to tell it there is data available… however with a one to one use of the I2C then it may make sense to reverse that with the mega acting as master and sending the data when it changes and the mega listening for these change messages. Of course you need to consider initialisation but that could be done with a simple wait cycle (assuming it all powers up together).

Check out the various Arduino I2C library examples. It is very common hence much is written.