0
Offline
Jr. Member
Karma: 0
Posts: 54
Arduino rocks
|
 |
« Reply #120 on: November 19, 2009, 10:12:37 pm » |
Well I got it to work using this code. byte incomingByte; byte note; byte velocity; byte check; int statusLed = 13;
void setup() { //start serial with midi baudrate 31250 or 38400 for debugging Serial.begin(31250); digitalWrite(statusLed, HIGH); }
void loop () {
if (Serial.available() > 0) { incomingByte = Serial.read(); delayMicroseconds(400);
if (incomingByte== 144) { note = Serial.read(); delayMicroseconds(400); velocity = Serial.read();
while (check!= 128 ) { check = Serial.read(); freqout(note); } } check=0; } }
void freqout(int freq) { int hperiod;
hperiod = (500000 / (freq*2)); analogWrite(12, 255); delayMicroseconds(hperiod); digitalWrite(12, LOW); delayMicroseconds(hperiod-1); }
But it only works if I send midi from live on my computer. If i try to use my keyboard controller it will triger a note and the just hold it on forever *shrug* Also I had to use the micro second delays to read the serial info, but now if I have 2 note trigger right next to the other it will miss the second one, I assume due to the delay.
|
|
|
|
« Last Edit: November 20, 2009, 08:45:00 am by Starfire »
|
Logged
|
|
|
|
|
France
Offline
Sr. Member
Karma: 0
Posts: 262
|
 |
« Reply #121 on: November 20, 2009, 02:32:43 am » |
If you have and LCD, this could be a way to know what's exactly happening. Some keyboard are strange sometimes. But note that often keyboards send a note on with velocity instead on note off.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 54
Arduino rocks
|
 |
« Reply #122 on: November 20, 2009, 08:36:04 am » |
Yeah that's what I'm thinking is going on. I wish I could get rid of those delays but when I do it quits working.
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Sr. Member
Karma: 0
Posts: 262
|
 |
« Reply #123 on: November 20, 2009, 12:02:53 pm » |
Yes, it should be possible, I didn't use some in my controller.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 54
Arduino rocks
|
 |
« Reply #124 on: November 20, 2009, 09:27:28 pm » |
I just can't get it to work without the delays, is it just blowing by the data in the serial stream with no delays?
I rigged up a LCD and when there is no delays both the note and velocity are read as 255 all the time, no idea!
|
|
|
|
« Last Edit: November 21, 2009, 01:16:01 am by Starfire »
|
Logged
|
|
|
|
|
France
Offline
Sr. Member
Karma: 0
Posts: 262
|
 |
« Reply #125 on: November 22, 2009, 12:21:48 pm » |
You perhaps modified it now, but that is a bit strange... while (check!= 128 ) { check = Serial.read(); freqout(note); } }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 12
Arduino rocks
|
 |
« Reply #126 on: January 26, 2010, 02:15:33 pm » |
Hey guys, I've managed to get a small instrument working using this code, but I've also encountered the same problem as Captain Credible (reply #41 on page 3), in that through some MIDI interfaces I can't play more than one note. If I connect the instrument directly to my MIDI keyboard, I can play polyphonically, but if I play through my keyboard into MIDI-OX and out through a separate MIDI interface (a MOTU MIDI Express XT) I can only play monophonically. Does anyone have an idea as to why this might be happening? At first I thought it was because of the note-off differences, between actually specifying a note-off message (128) and a note-on with velocity = 0, but as far as I can tell they both do the note-on, vel=0 thing. I've been racking my brain all day over this, but I'm truly stumped. Any help would be very gratefully received. MIDI portion of code below: if (Serial.available() > 0) { blink(); incomingByte = Serial.read(); if (incomingByte == 144) { action = 1; }else if (incomingByte == 128) { action = 0; }else if ((action == 0) && (note == 0)) { note = incomingByte; playNote(note, 0); note = 0; velocity = 0; action = 2; }else if ((action == 1) && (note == 0)) { note = incomingByte; }else if ((action == 1) && (note != 0)) { velocity = incomingByte; playNote(note, velocity); note = 0; velocity = 0; action = 0; }else{ } }
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 1
Posts: 360
I'm 15. I like making things. I like breaking things better.
|
 |
« Reply #127 on: February 06, 2010, 08:06:59 am » |
Hi All. I am new to the arduino, but i am fairly handy with electronics. i built my setup according to the schematic, except with a 4 channel opto from sparkfun which i had lying around. I connected everything to the correct corresponding pins, and now all that happens when everything is connected is a stream of serial gibberish that doesnt change when i do something on the piano. Any ideas?
Thank you!
|
|
|
|
|
Logged
|
Alice asked the Chesire Cat, who was sitting in a tree, "What road do I take?" The cat asked, "Where do you want to go?" "I don't know," Alice answered. "Then," said the cat," it really doesn't matter, does it?"
-Lewis Carrol
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 75
Arduino rocks
|
 |
« Reply #128 on: February 19, 2010, 12:48:39 am » |
Hi everyone, Ive been trying to get this to work for a while,but no luck. It seems that the arduino is not recieving any data through RX. Like others, many posts back, I get a LED to flicker when connected to +5v and pin 5 of the optoisolator( when the RX is not connected). I measure about 5.2 v on the pin and a 10th of a volt difference corresponding to keystrokes. I get nothing coming in on the serial monitor and even the simplest, one led sketches dont work. I am using a microkorg but have also tried a sci prohet 600. I tried changing the baud. I checked for loose connections, cold soldered joint, and my diecimila is fine other wise. Any suggestions? It seems a few others had this problem but there were no real solutions posted. Id really appreciate any help. Thanks
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 75
Arduino rocks
|
 |
« Reply #129 on: February 19, 2010, 11:56:48 am » |
ok, I got it to work briefly but then I unhooked the RX input and when i put it back it no longer works. I used this: //variables setup byte incomingByte;
int statusLed = 13; // select the pin for the LED
//setup: declaring iputs and outputs and begin serial void setup() { pinMode(statusLed,OUTPUT); // declare the LED's pin as output Serial.begin(31250); //start serial with midi baudrate 31250 or 38400 for debugging digitalWrite(statusLed,LOW); }
void loop () { if (Serial.available() > 0) {
incomingByte = Serial.read(); // wait for as status-byte, channel 1, note on or off if (incomingByte==144){ // 144 is note on ch1 digitalWrite(statusLed, HIGH); delay(20); digitalWrite(statusLed, LOW); delay(1); }
} }
This is how I got it to work ... uploaded this sketch (for like the 20th time) and it didnt work...no surprise. then I took the lead from pin 5 of the opto and directly touch pin 2 on the atmega( the rx pin) then I stuck a 1k resistor between therx and tx sockets, removed it and then put the lead from pin 5 of the opto back into the rx socket. Ta-DA that did it ...worked fine! However... After I removed the input lead and put it back it stoped working and now nothing. I checked continuity.... I think everything is good. I get a strong beep when the probes are directly on the opto's output and the atmega RX pin 2. I am pretty sure the hardware is ok. I think somehow my arduino doesnt want to read incoming data, though it loads sketches fine.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 75
Arduino rocks
|
 |
« Reply #130 on: February 22, 2010, 05:02:07 pm » |
Ok, I got it to work, but not with a 4n28. I tried 10 of them, with every resistor combo imaginable. I could get a led flicker (between +5v and pin 5,with the rx disconnected ), but it did nothing for the arduino. Nothing was being read. Finally i tried another opto, a cny 17-4. It has a similar pinout as the 4n28 and I substituted the 100k for a 220k and the 3.3k for 2.2k. works perfectly(for me).
It seems that there were/are a few others who had trouble with this circuit and the arduino seemingly not being able to read any data. Perhaps for some, there is a problem with using the 4n28. i dont know what, though. It makes no sense to me. A circuit this simple and that has been repeatedly verified by so many, shouldnt be this contrary.
Anyone have any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Sr. Member
Karma: 0
Posts: 262
|
 |
« Reply #131 on: February 22, 2010, 05:09:54 pm » |
As I said a few pages before, for me the solution was not to connect the OptoPin6-100k-GND part, all the rest of the circuit like described on the first post. I built this circuit a few times. In case of a standalone setup without FTDI the 3,3k resistor has to be 1k. 
|
|
|
|
« Last Edit: February 22, 2010, 05:10:22 pm by tep »
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 75
Arduino rocks
|
 |
« Reply #132 on: February 23, 2010, 09:45:48 am » |
All of the 4n28s that I tried, wouldnt even make a LED flicker with ANY resistor value between ground and pin 5.
|
|
|
|
|
Logged
|
|
|
|
|
France
Offline
Sr. Member
Karma: 0
Posts: 262
|
 |
« Reply #133 on: February 23, 2010, 10:01:16 am » |
A resistor between Ground and Pin 5 ? You mean 6 or +5V I think. Anyway I didn't test the flicker think on my side but it worked... If you have time, rebuild it with my schema ?
You're using MIDI on the same serial as a FTDI right ? If it is a Mega I guess it is 1k instead of 3,3k but all the rest the same.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 75
Arduino rocks
|
 |
« Reply #134 on: February 23, 2010, 11:04:27 am » |
Oops, I meant...a resistor between pin 6 and ground. Also my arduino doesnt read midi data when the jack is connected to the arduino. (midi 4>rx, midi 5> ground) I thought that using the optoisolator was just a precaution.??
|
|
|
|
|
Logged
|
|
|
|
|
|