Pages: [1]   Go Down
Author Topic: Faster Serial Communication?  (Read 550 times)
0 Members and 1 Guest are viewing this topic.
Rochester, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 14
oh hai
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I'm going to build an electronic drum kit with my Arduino. I just wrote a bit of code for a bass pedal:

Code:
int butpin = 2;
int last;
int but;


void setup() {
  Serial.begin(31250);
  pinMode(butpin, INPUT);
}

void loop() {
  but = digitalRead(butpin);
 if (but == HIGH && last == 0){
   noteOff(1, 20, 0);
   last = 1;
 } else{
 }
 if (but == LOW && last == 1){
   noteOn(1, 20, 64);
   last = 0;
 } else {
 }
// delay(1);
}

void noteOn(byte channel, byte note, byte velocity) {
  midiMsg( (0x90 | (channel & 0xf)), note, velocity);
}

// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
  midiMsg( (0x80 | (channel & 0xf)), note, velocity);
}


// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
  //digitalWrite(ledPin,HIGH);  // indicate we're sending MIDI data
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
  //digitalWrite(ledPin,LOW);
}

When I press the pedal it sends a midi note(yippy). The only issue is I can hear the lag. Right now I have my Arduino hooked up to a USB1.1 port, will I gain any speed by using a USB2.0 port? Is there any way for me to improve this performance? My expansion plans involve piezos and the analog pins. There isn't much point in continuing if I can't significantly reduce this lag.

Right now I'm running the Roland Serial Midi driver.

Thanks in advance.
Logged


0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
he's not a real doctor
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should be able to send somewhere between close to 3K   characters a second with the serial (unless there is software overhead I am missing).   However digitalRead has some error checking and has a significant delay.  As I recall,  it is around 1/60 of a second.

If digitalRead/Write are slowing you down you can read/write directly to the port close to 4million times a second.  Look up "port manipulation".  There are several forum posts on the subject.  The serialWrite code is pretty tight and I doubt you could do it any faster than the library.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 504
Posts: 31324
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As I recall,  it is around 1/60 of a second.

No it's not it's closer to 0.4mS. If you can hear any lag then it is the rest of the system not what you posted here.

Quote
USB1.1 port, will I gain any speed by using a USB2.0 port?

No you are just using serial bridge running at the MIDI rate.

Are you feeding the Arduino MIDI output directly into your system or is there some other software in between?
Logged

Montreal
Offline Offline
Full Member
***
Karma: 0
Posts: 185
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i have heard of lag in MIDI if you send more then one note and keep sending the overhead, you will heard the lag, but if you send 3 note in the same message that lag should not be there!
Not sure if this is what you need
Logged

Patgadget
Montreal

Rochester, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 14
oh hai
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the info, it's quite helpful. After your posts I focused on my software rather than my code/the arduino. Turns out that Ableton Live is just really slow. Maybe it is my computer though. I changed programs and it responds MUCH faster.
Logged


Pages: [1]   Go Up
Jump to: