Go Down

Topic: Using the Arduino to manage several serial connections (Read 522 times) previous topic - next topic

bcnx

Hi all,

I'm playing with the idea of building a MIDI (serial musical protocol at 31250 baud) patch bay, so I can connect different MIDI devices to a series of other MIDI devices (in the beginning in just a one to one basis).
In other words, I would be building a switch board that samples serial data on one port (in) and copies it to another serial port (out).
Sounds simple enough, but the Uno just has one serial port. I've seen the SoftwareSerial library, but this uses only one port at the time. I suspect possible latency problems in that scenario.
I think I would probably need some sort of UART to get this done, but I would like to have some tips on how approach this process. Maybe the Arduino is not the best choice for this, but running at 16 MHz, I would like to believe it could be done,

Cheers!

BC

DrDiettrich

An Arduino Mega has 4 Serial devices in hardware.

Robin2

A cheap way to add extra USARTs is to add extra Atmega 328s connected to the "master" Arduino by SPI.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sterretje

A one-to-one can be done. A one-to-many can be done. A many-to-many can't be done reliably without uarts.

But why the use of the uart? What you want to build is basically a router. And that can simply be done with multiplexers. I have no experience with MIDI (so not sure about electrical requirements) but you can look at e.g. the 74HC4067.

Each 4067 has 16 inputs; one of them can be routed to the output. Use two or more (each individual input going each an input on each 4067) and you can expand the number of outputs. With ease you can go to 16x16.

You can use port expanders or shift registers to control which input has to go to which output.

You will have the same problem as with a real patch panel; that is, if you patch (switch) while a command is being send, it will result in data corruption.

Note:
you might need additional electronics to meet the specification
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

bcnx

An Arduino Mega has 4 Serial devices in hardware.
I was aiming for more inputs, about 16  :-)

bcnx


A cheap way to add extra USARTs is to add extra Atmega 328s connected to the "master" Arduino by SPI.

...R
That's an interesting idea, but to avoid having to use a lot of microcontrollers (I aim to use 16 inputs and outputs) I think I would need to involve "bit banging" (emulating serial connections by programming digital inputs).
In that context I worry about how to scan 16 different pins and moving the same info in a timely manner to the output pins,

cheers,

BC

bcnx

A one-to-one can be done. A one-to-many can be done. A many-to-many can't be done reliably without uarts.

But why the use of the uart? What you want to build is basically a router. And that can simply be done with multiplexers. I have no experience with MIDI (so not sure about electrical requirements) but you can look at e.g. the 74HC4067.

Each 4067 has 16 inputs; one of them can be routed to the output. Use two or more (each individual input going each an input on each 4067) and you can expand the number of outputs. With ease you can go to 16x16.

You can use port expanders or shift registers to control which input has to go to which output.

You will have the same problem as with a real patch panel; that is, if you patch (switch) while a command is being send, it will result in data corruption.

Note:
you might need additional electronics to meet the specification
Hi Sterretje (Vlaams of Nederlands?),

thanks for the elaborate answer.

Indeed, one-to-one and one-to-many are the only feasible (relative simple) situations. Many-to-many involves a maxing of the signals, which adds considerable complexity.

MIDI is basically using 5V for highs and 0V for lows, pretty straightforward.

I already considered multiplexers but I was worried about the situation where several data trains arrive at different ports at the same time: MIDI is time sensitive, so the same speed needs to be more or less honored. Maybe some electronics to mimic interrupt requests are necessary to have this all handled by a simple microcontroller ...

Can multiplexers handle multiple incoming data signals?

Thx!


BC



sterretje

As indicated, you would have the same problem with a physical patch panel. If that is a concern, the solution will not work.

If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Robin2

I think I would need to involve "bit banging" (emulating serial connections by programming digital inputs).
That won't be any better than SoftwareSerial and that is pretty crap. A 16 MHz MCU is not fast enough.

You need multiple UARTs - hence my suggestion. You could write a standard program for each "slave" Atmega328 so that it receives and buffers the incoming data and passes it to the master whenever requested. Likewise for sending stuff on behalf of the master.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

bcnx

As indicated, you would have the same problem with a physical patch panel. If that is a concern, the solution will not work.


If we would adhere to the patch panel metaphore, only one-to-one connections are possible. One-to-many would be desirable however.

thx,

BC

bcnx

That won't be any better than SoftwareSerial and that is pretty crap. A 16 MHz MCU is not fast enough.

You need multiple UARTs - hence my suggestion. You could write a standard program for each "slave" Atmega328 so that it receives and buffers the incoming data and passes it to the master whenever requested. Likewise for sending stuff on behalf of the master.

...R
OK, thank you. Maybe I need to reconsider using an Arduino for this. What would be a fast enough speed for this application? 
Using multiple Arduinos also requires some protocol to sync the MIDI clock that is present in the MIDI signal.

I was also thinking that, to allow multiple incoming MIDI signals, I would periodically scan the input ports to detect low-to-high transitions, which indicate starting MIDI conversations. From that point on, the MIDI clock in the signal needs to be synced to.

Cheers, I appreciate the feedback and tips,


BC

bcnx

I found this as a possible faster Arduino:


http://leaflabs.com/devices/maple/


I've also been looking at digital crosspoint switches, which are ICs that basically present a big matrix of switch that can be one by one configured to pass through a digital signal. These are big SMD packages though, hence not very easy to breadboard with,

BC

Robin2

I found this as a possible faster Arduino:
Quote from that website
Quote
As of March 2015, the LeafLabs Maple line and the libmaple library are end-of-life and no longer supported by LeafLabs.
There are Arduino products with high-end MCUs but I still think you will need multiple hardware UARTs

You have not mentioned at all how much data will need to be manipulated - how many bytes per second when they are all working, and what sort of manipulations will need to be done.

Perhaps you really need the power of a high-end PC?

By the way I know nothing about midi or music - except to listen to.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sterretje

Fritzing Project - Midi Router

It was done before; I can't say how successful it was; but you can always try it ;)

I also found Next/previous switching a multiplexer

Again I have no idea how well it works.

I don't understand your problem with the timing; multiplexers are like electrical switches (basically no delays). As said, you might interrupt a message and switch into the middle of another message and that will cause corruption. The second link has a "sound detection" circuit in one of the pages to light a LED while data is being received; you might be able to use that to prevent switching.

But then it becomes a lot more complicated.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

bcnx

Quote from that website
There are Arduino products with high-end MCUs but I still think you will need multiple hardware UARTs

You have not mentioned at all how much data will need to be manipulated - how many bytes per second when they are all working, and what sort of manipulations will need to be done.

Perhaps you really need the power of a high-end PC?

By the way I know nothing about midi or music - except to listen to.

...R
Hi,

the amount of MIDI data is relative. For example: one note requires 3 bytes for a "note on" message and two more bytes for a "note off" message (if I'm notmistaking). You have however also performance data which possible create relatively more data. However, a composition can be made of several simultanious instruments all producing MIDI data. All and all it should however be quite manageable, as devices that do what a describe, already exist and contain also "simple" MCUs. I have such a device with 8 ports. But I'd like to go higher.

BC







Go Up