Arduino Forum

Forum 2005-2010 (read only) => Hardware => Development => Topic started by: sal_one on Jan 11, 2011, 05:28 pm

Title: 8u2 midi
Post by: sal_one on Jan 11, 2011, 05:28 pm
Hello everyone

Im trying to reprogramm the 8u2 as generic MIDI device. I got as far as sending hard-coded MIDI-messages to my computer, but i cant catch the serial messages sent from my Arduino and change them to MIDI-messages.
As base file i took the Arduino-usbserial.c
I think my fault lies in taking the wrong variable as input from the atmega:
Code: [Select]

while (BufferCount--)
{
     channelMIDIMessages(RingBuffer_Remove(&USARTtoUSB_Buffer), buffercnt);
     if(buffercnt == 2)
     {
           sendMIDIMessage();
           buffercnt = 0;
     } else
     {
           buffercnt++;
     }
}

I thought, the function RingBuffer_Remove(&USARTtoUSB_Buffer) returns the byte read from the atmega, but i never get anything from it.
Title: Re: 8u2 midi
Post by: sal_one on Jan 11, 2011, 05:28 pm
Here is my entire code from the file Arduino-usbserial.c

http://www.pasteall.org/18222
Title: Re: 8u2 midi
Post by: Davide_Gomba on Jan 13, 2011, 10:02 am
I would put a bounty on this.

Sadly enough, I don't know much about LUFA :( , but it's one coolest and most interesting aspects of the new arduino UNO.

hold on!
Title: Re: 8u2 midi
Post by: stimmer on Jan 14, 2011, 12:55 am
I had MIDI working in the other direction (computer to arduino) but that was easier. Even then it only seemed to work on Linux and not on Windows so I gave up.

Getting MIDI from the Arduino into the computer is a little harder. From reading the docs I think you have to wait for all the bytes of the message to come through before sending it (usually 3 bytes). So you do have to do a little parsing of the data as it comes in. Don't bother with ringbuffers, you don't need them at MIDI speeds, just send each complete message as you get it.

I might have another look at it again in the future, i have an idea for a project which might need it...
Title: Re: 8u2 midi
Post by: sal_one on Jan 16, 2011, 05:39 pm
I got it to work now, after i decided to throw out all this ringbuffer stuff since i found a very simple command to read serial messages from the arduino on this forum (Serial_IsCharReceived() and Serial_RxByte()).
The parsing i do on the function channelMidiMessage, i save the messages in an array of length 3 and as soon as i have 3 messages i put it together and send it further on.
If anyone is interested, my colleague will put the project on sourceforge as soon as were finished with it and i will post the link here ;)
Thx for the help