The problem is that I get a lot of latency with that device other than with my usb midi keyboard for example. I am running Windows 10 64bit on this computer with a Focusrite Scarlett 2i4 audio interface. Usually the latency from the MIDI IN of it and the external keyboard is really low.
But with my DIY midi controller the latency is just really big, making it not usable at the moment. I use Cakewalk Sonar Platinum as my DAW, but I don't think it is an issue with that program, as it deals with every other usb midi controller very well.
So I usually start LoopMidi and there a new port, then start Hairless Midi and connect it MIDI IN and MIDI Out there to the Loop Midi port. Then I just have to choose that Loopmidi in my DAW, and everything works as it should, except the latency.
Does anyone have an idea about how this could possibly be fixed? I really tried to find an answer on the internet, but with no success yet.
AndiH1213:
The delay is there for debouncing the switches I use.
How was I supposed to know that a delay() in a function that sends serial data is intended to debounce a switch. If you need a delay put it somewhere logical.
More importantly, don't use delay() at all. Use millis() to manage timing without blocking as in Several Things at a Time.
In any case, if the delay() is not causing the latency I suggest you look at the output from your Arduino program on the Arduino Serial Monitor. If there is no latency there it suggests the problem is in your PC software rather than your Arduino code.
Removing the delay just causes the buttons to bounce. For what I want it to do I think the code should be fine. I am new to programming and put that one together with help from the forum (thanks to Grumpy_Mike again), and I basically just want it to work and not be perfect.
The latency issue is just really bothering me. I tried to work through a couple tutorials on fixing the latency through the ftdi drivers, like this one:
But under the advanced port settings I don't have an option to set the latency, I only have the choice for disable/enable FIFO-buffer and setting receive buffer and transmit buffer. Changing those doesn't have a positive effect, too.
I have the feeling that is has someting to do with those drivers. Hairless Midi also says that FTDI drivers don't seem to be installed, but they are.
You could maybe further improve the code by only setting a flag if button states have changed in the for loop and not execute the delay if no button changes (no need to debounce).
Ok so it seems that I (almost) solved the problem. I had to change the latency in the fdtiport.inf file of the drivers. Right now I am running this Micro Pro as a Leonardo with the drivers coming with the Arduino software.
So with those drivers, the latency on Windows is initially set to 16ms, but I set it to 1.
It is much better right now, but even though I realize a small latency.
I haven't tried out how to include the millis() function to my code. I just don't have that much time right now. But I might look into that soon as I am planning to build another midi-foot-controller in the future, using a board like a teensy that can do usb to midi without additional software like LoopMidi + Hariless Midi. I actually bought the Micro Pro as it said it would be compatible to the Arduino Leonardo, but it seems it doesn't have the same USB to Midi function.
Another problem I have is that the Pro Micro sometimes is not beeing recognized by Hairless Midi any more and I have to restart the programs, reconnect the hardware and sometimes it works again. No clue what is happening there. Having to rely on an additional program to send Midi data kind of sucks