Hi, i wanted to make a midi synthetizer. i already found one project of a polyphonic synthetizer and it uses a 4n25 optocoupler. i dont have any of these and i am wondering if one of my 4n35 optocouplers are usable. like if they are fast engouth for the 31.25K baud rate.
It should work fine. the 4N35 is listed as a replacement for the 4N25.
ok i made the circuit but when i plug the arduino the TX led lights up. and yes i connected the optocoupler to the RX pin. (im using a mega2560 to generate a midi signal).
i opened the serial line in putty with the baud rate of 31250 and here what it shows
I'm not sure what to expect... Raw MIDI data is NOT ASCII text.
i know but it is not supposed to send back the midi data trough the sub serial port.
So what is it supposed to send through the serial port?
By crystal ball is on the blink so you will have to post your code (correctly in code tags) before we can see what it is.
What is that black blob? You made a circuit, please post a schematic as you wired it, not a frizzy picture so we can understand what exactly you made. Be sure to show all power, ground, and power supplies. My crystal ball was recalled because of cracks, it will be a long time until I can get a new one. You might want to spend a few dollars on a cheep logic analyzer and compare the ins and outs.
so here is the code :
/*********************************************************************************************
JCR SYMPLE 3 OSC POLYSYNTH WITH MIDI - REV.1 - By Julio Cesar - CesarSound Dec/2020
NOTE 23 1 B0 Note On NOTE 23 1 B0 Note Off
NOTE 108 1 C8 Note On NOTE 108 1 C8 Note Off
-----------------------------------------------------------
NOTES:
-Connect to MIDI OUT of your MIDI controller via 5 pin DIN MIDI connector (not USB MIDI).
-For Arduino Uno / Nano / Pro Mini - See Schematics for wiring details.
-The number of tones that can be generated at the same time is limited by the number of
hardware timers available on the hardware (e.g. ATmega328 has 3 available timers, and the
ATmega1280 has 6 timers).
**********************************************************************************************/
#include <MIDI.h> //MIDI I/Os for Arduino
#include <Tone.h> //Bhagman Tone Library
byte i = 0, j = 1, k = 1;
static const uint16_t note[89] = { //MIDI NOTES TO FREQUENCY ARRAY
NOTE_B0, NOTE_C1, NOTE_CS1, NOTE_D1, NOTE_DS1, NOTE_E1, NOTE_F1, NOTE_FS1,
NOTE_G1, NOTE_GS1, NOTE_A1, NOTE_AS1, NOTE_B1, NOTE_C2, NOTE_CS2, NOTE_D2,
NOTE_DS2, NOTE_E2, NOTE_F2, NOTE_FS2, NOTE_G2, NOTE_GS2, NOTE_A2, NOTE_AS2,
NOTE_B2, NOTE_C3, NOTE_CS3, NOTE_D3, NOTE_DS3, NOTE_E3, NOTE_F3, NOTE_FS3,
NOTE_G3, NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3, NOTE_C4, NOTE_CS4, NOTE_D4,
NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4,
NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5,
NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6,
NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6,
NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7,
NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7, NOTE_C8, NOTE_CS8, NOTE_D8, NOTE_DS8,
};
MIDI_CREATE_DEFAULT_INSTANCE();
Tone notePlayer[3]; //[3] = 3 OSC (MAX)
void setup(void) {
MIDI.begin(MIDI_CHANNEL_OMNI);
pinMode(2, INPUT_PULLUP);
notePlayer[0].begin(3); //OSC 1 - OSC 1 OUTPUT PIN 3
notePlayer[1].begin(5); //OSC 2 - OSC 2 OUTPUT PIN 5
notePlayer[2].begin(11); //OSC 3 - OSC 3 OUTPUT PIN 11
MIDI.setHandleNoteOn(MyHandleNoteOn);
MIDI.setHandleNoteOff(MyHandleNoteOff);
}
void loop(void) {
MIDI.read();
}
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
i = pitch - 23;
j = j + 1;
if (j > 3) j = 1;
switch (j) {
case 1:
notePlayer[0].play(note[i]);
break;
case 2:
notePlayer[1].play(note[i]);
break;
case 3:
notePlayer[2].play(note[i]);
break;
}
}
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
k = k + 1;
if (k > 3) k = 1;
switch (k) {
case 1:
notePlayer[0].stop();
break;
case 2:
notePlayer[1].stop();
break;
case 3:
notePlayer[2].stop();
break;
}
}
and it is not sending anything to the serial port.
the only thing that it does is to check if it recive a midi noteOn message, if yes it plays the note and stops it at a midi noteOff message. and it can do 3 simultaneous notes.
also, here is the schematic (the only modification i did was to replace the 4n25 optocoupler by a 4n35 optocoupler :

Disconnect the RX1 connection from the MIDI and see if that output is working. I suspect it is. There is also a 1K on the Nano connecting RX to TX of the FT232RL. This is probably killing your signal. Hopefully you can get a scope or logic analyser to verify this, scope prefered. Hopefully this will get you going.
Having looked at the data sheet I would say you can't push a MIDI signal through a 4n35.
If you look at the data sheet of the two parts, the 4n35 has a typical rise and fall time of 10uS, where as the 4n25 has typical rise and fall time of 2uS.
Lets assume that the fastest signal consist a rise time plus a dwell time plus a fall time where the dwell time is the same as the rise time. ( it might be lower that this but can't be faster).
Then the 4n25 would give a maximum baud rate of 166,666 Baud, and a 4n35 would give a maximum baud rate of 30,303 baud. Given that the MIDI baud rate is 31,250 Bauds then you can see how the 4n35 is not fast enough for MIDI.
The MIDI hardware specification recommends using a PC900V or a 6N138 / 6N139 which is described as a 100,000 Baud capable opto isolator. Where as the 4n25 and 4n35 make no claims as to how fast it will transfer a serial signal. So I think in practice the calculations I made would be an over estimation of the Baudrate capabilities.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
