code crash.

hello all,

i am messing with midi out, soon i will mess with midi in when i get my leds and everything else to test out what i need. but i am running into a weird problem with some code that i hooked up. sometimes when i start, say, live. it crash the whole computer when the arduino is plugged in to midi with a power cord to, well, power it. very strange.

obviously this has to be a code problem, i could not see any other reason why not. but cant see at the moment what it is that could be causing this.
just got a bit of a tired head on me at the moment.

this was made with code from a blog site that has been mentioned a few times, sorry i cant remember just now.

many thanks if you can help.

lewis

// command bytes
byte status_byte = 176; // control change on channel 1
byte cc_number = 0; // value for control number

// init transfer and operation values
byte data_send = 0; // stores outgoing byte for spi bus

// init looping and working values
int workPort = 0; // working value for outgoing port
int workAn = 0; // working value for analog input

// setup begins here
void setup() {
Serial.begin(115200); // open serial port
delay(600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
}

// main program begins here
void loop() {

for(int i = 0; i <= 15; i ++) // loop the following code 8 times
{
cc_number = 20 + i; // set control number to between 20 and 25 depending on loop iteration
workPort = (i / 2) * 4; // get pot 1 to 8 ignoring bits 0 and 1 of a 5 bit value
PORTD = workPort; // set pins 2, 3 and 4 to value between 0 (00000) and 7 (11100)
workAn = i % 2; // and read in either analog input 0 or 1 depending on the loop
data_send = analogRead(workAn) / 8; //read analog pin into variable... with 10 bit -> 7 bit
Serial.print(status_byte); // send status byte
Serial.print(cc_number); // send CC number
Serial.print(data_send); // send data value
// loop back...
}
// loop back...
}

obviously this has to be a code problem,

Why do you say that? Is live prone to crashing when it gets rubbish?

It could be the bytes sent at power up and reset looking for the download of a sketch. However as no one else has reported this problem it is unlikely.

Have the system powered up before you plug it. The other thing to do is to make sure the ground is connected before the signal is connected. You could try running a strap from the ground of your arduino to the ground of the PC independent of MIDI leads.

aye, i know i may be jumping to a conclusion with that. but it even crashed the computer when starting max as well. odd, but anyhow...