MIDI signal (using a 6n137 octocoupler) - Page 1
Forum section: electronics / projects

author: Fluxia
author_rank: Contributor
timestamp: March 24, 2025, 04:00:56 pm
content: Hello.I found a very interesting project on this yt channelhttps://www.youtube.com/@SynthetechIt's a DIY synth:I wanted to build this Synth. I bought all the parts and put them together, but still cannot get it to work.On the YT channel there is a toubleshooting video as well which I followed and the author was also very kind to provide some advice in the comment but clearly I cannot abuse his kindness, as it looks like I need more than a one off advice...(initially I had a 6n138, but replacing it with the 6n137 did not sort the problem).There are a few questions I have about how midi works.I have tested with my oscilloscope pin 2 and 3 of the octocoupler (which are respectively connected to pin 4 (through a 220 resistor) and pin 5 of the midi plug. When idle pin 2 sits at 5 v (as expected) and pin 3 at around 3.8v (is this normal?). when sending midi signal the "LOW" level for pin 2 is 2.6 v and the one for pin 3 is 1.2v approx.On the other side of the octocoupler i get good signal with pin 6 going from HIGH 3.3 to LOW 0 v.The problem with the BP synth is that I do not get any audio output (I am going to assume that since this has been testedby many others and the author, nothing can be wrong with the code - the firmware I simply loaded the one provided by the author - which seems to be working as I get the clock square wave from the board relative pin as expected). However no audio output from the BP pin.Now is there anything in regard to the midi signal as tested that is wrong and could affect the functioning of the BP synth? I have attachedpictured of the oscilloscope test of midi signal (the first pic is the input on pin 2 of the octocoupler and the out put on pin 6 of the octocoupler. the other two pics are pin 2 and 3 of the octocoupler.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 24, 2025, 06:55:56 pm
content: Looks like a normal asynchronous serial signal to me. MIDI is based on 31250 bits per second asynchronous serial communication. MIDI should works with a 6N138 just fine.Seeing that the signal on the input of the optocoupler looks fine, you should look at what is on the other side of the optocoupler. Pin 6 is the output to the receiver input, and pin 5 is ground.I glanced at the guys youtube channel and some videos a bit and it looks like a blackpill STM32 board with a DAC board for the output on a breadboard, and that is as safe way to ask for trouble. Best to get a perf board and solder things together to make proper connections. There can be all sorts of signal integrity problems on a breadboard.Make sure that the signals to the DAC board are correctly connected and show proper signals. Most likely a high frequency system clock, a slower bit clock and an even slower word clock.Edit: I found the "schematics" and for the DAC the high frequency system clock is not used. Just the bit clock and the word clock, and of course a data signal.Edit2: The 6N137 has a supply voltage requirement of at least 4.5V, but the schematic shows 3.3V, which is to low. The 6N138 has a wider supply range. Also adding a 100nF decoupling capacitor near the output side of the optocoupler is good practice, especially for the 6N137.For the 6N137 there is no need for a pull up resistor. The 6N138 does need it though.Edit3: Did not read the 6N137 datasheet properly. It is open drain, so a pullup resistor is needed.

author: Fluxia
author_rank: Contributor
timestamp: March 25, 2025, 03:47:58 pm
content: Hi and thanks for your reply. I am aware of the issues with the breadboard, but I ensured that the connections were proper by testing everything directly from the boards pins. Everything seems to have the right signal coming and going, except for the pin on the blackpill board (A7) which is meant to send the signal to the DAC. I have followed the troubleshooting videoto the letter as well and still the only missing signal is on pin A7 of the blackpill....I have now tested the MIDI signal with a digital analyzer and it seems to be fine on both end. As it can be seen from the picture attached, when I pressed a key on the keyboard I got the correct message decoded by the digital analyzer both on TX and RX (on both sides of the octocoupler, but also on the blackpill pin, A3 - I tested it). The only thing that I don't undertsand about the midi signal is why the TX signal (tested on pin 3 of the octocoupler goes from approx 4 v to 1.2v rather than from 5 to 0 - may not be relevant to resolve the problem posted but it is something I do not understand - you can see the midi TX and RX as respectively the blue and yellow on the oscilloscope screen).In regard to the octocoupler it seems thast it is being used with 3.3 v even though you are correect in saying that the specs advise to use it with 5 v. There is a brief debate about thishere.But the bootom line is that this project has been tested by other and it seems to be working for them, so wander what I am doing wrong. I found this guywho has also built a BP synth based on Synthetech's project and posted a video about it. I doubt it is a problem with the code as their project also would not work....

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 25, 2025, 05:38:06 pm
content: Quote from: Fluxia on March 25, 2025, 03:47:58 pmThis has to do with the voltage drop over the LED and the resistor(s) and the driving source at the MIDI out end. It has been quite long ago that I worked with MIDI, but if I recall correctly there is also a resistor in series in the sending device. These series resistors take a slice of the voltage when current is flowing. The forward voltage across the LED is typically 1.4V, so when driving from 5V, 3.6V has to be put somewhere. That the off level is around 4V can be due to the MIDI interface you are using not reaching 5V to start with.Quote from: Fluxia on March 25, 2025, 03:47:58 pmSo the LITEON datasheet states it working on 2.7V - 3.6V and 4.5V - 5.5V. The VISHAY datasheet I found says 4.5V - 5V. To me this means that there is a possibility that not all 6N137 optocouplers will work at 3.3V, and when designing something that makes use of one that does work on 3.3V you have to specify this in the bill of materials and or on the schematic. As it seems, yours is working, so not the source of your problem.Quote from: Fluxia on March 25, 2025, 03:47:58 pmYes, that is the big question. It is a bit of a shame that the software is not open source, because it would then be possible to do some debugging to see if the MIDI is actually seen by the F411. But for this you could try to setup something with the Arduino IDE and write a test program.I myself am more of a bare metal freak, so do not use the Arduino IDE for my own development. Maybe others can chime in with a simple test sketch.

author: moffy
author_rank: Super Contributor
timestamp: March 25, 2025, 08:45:24 pm
content: It is easy with RS-232 to have a simple inversion of the transmission on either the Tx or Rx.

author: Fluxia
author_rank: Contributor
timestamp: March 26, 2025, 01:33:45 pm
content: Thanks,QuoteI think I need to look into MIDI signal path and understand better how it works.QuoteThe keyboard does output 5 v but on pin 4 of the MIDI plug. I have used the Synthetech schematics to show what voltage levels I get at each node (attached pic). As you can see during idle state pin 4 and 5 are both high, one at 5 v and the other at 3.84v... yes I definitively need to learn a bit more about midi signal and how it works...Quotethat is probably what I will need to do, try with an arduino. There is a course on Synthetech YT channel on how to write the code for the BP synth and I am planning to watch it as I would be interested in custumise the project so that I can add some knobs touse directly with the synth. I was planning to make a synth for a friend as a 50th birthday persent and I have got still a few months to work on it

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 26, 2025, 02:02:43 pm
content: I'm no analog electronics expert, but the LED in the optocoupler probably still drops 1.2V due to some very small current flowing into the measurement device.I have to look at that video you mention as this is also something I'm interested in. Have lots of projects on the shelf that relate to audio synthesis.Edit: For ones that are interested in it, here is the playlist for the teaching series:https://www.youtube.com/playlist?list=PLOjbFVchrTEyJBfXwbhBicpxuOOPgtQ3vEdit2: For those interested in the source code, I attached the latest from the teaching series here. It uses the STM32 HAL crap which makes it less clear to read and understand what is where. The teaching series explains things in depth, but I don't like to watch these kind of videos. I rather read the source.

author: hexreader
author_rank: Frequent Contributor
timestamp: March 26, 2025, 03:16:33 pm
content: May be of no consequence, but my datasheet states that the output load resistor should be 4k Ohms maximum. You appear to have 10k.I would have used a 1k resistor for better rise/fall times.Having said that, your oscilloscope trace for opto pin 6 looks pretty good.Just a thought....

author: Fluxia
author_rank: Contributor
timestamp: March 27, 2025, 06:58:11 pm
content: @pcprogrammerQuoteglad to hear that ! then we may speak again when you get round to do one of these... why don't you try tio build the BP synth as well. you may have more luck than me...it is pretty simple if things workI will watch the Synthetech course, hopefully will help me to sort this mystery...@hexreaderQuotethat's what I thought but I suppose there is no harm in trying a smaller resistor, will do that

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 27, 2025, 07:57:12 pm
content: I do have the parts for it, but first have to finish some other projects.I wonder which DAC board you are using. Yesterday I received 6 PCM5102A boards I ordered on Aliexpress, which were on offer. Only 0.97 euro a piece.https://www.aliexpress.com/item/1005006104038963.htmlAs I needed to test them I connected them to a board I made with a STM32F303 and a different PCM5102A board.https://www.aliexpress.com/item/32828177686.htmlAt first I tried it without soldering with female dupont wires, but despite all the input signals seemingly being on the board there was no output signal. I made a small conversion board to connect them and soldered the headers to the new PCM5102A boards. Again no output signal. On scoping the signals again I noticed that the XSMT (soft mute) was low instead of high. Was a bit of an oversight on my part. I had connected it to the 3.3V output of the PCM module on my test board, but I did not use the 3.3V output from the new boards.After fixing that, it is now working. For the new modules I found a schematic that also shows how the jumpers on the board should be set. Mine arrived with all settings open, so by default it will be muted on the output.Maybe this is also the case in your setup.

author: Fluxia
author_rank: Contributor
timestamp: March 28, 2025, 09:02:37 pm
content: QuoteI am using the CJMCU-1334 UDA1334A I2S DAC, one just likethisI think I have already checked the jumpers on the DAC, as it was mentioned in the tutorial, but in any case there is no signal from the A7 pin. In the troubleshooting video of Synthetech, at minute 9, he is testing the DAC input and then the output from the blackpill on pin A7. You can see the audio signal on both. This is where I have the issue. No signal from output A7 at all when I play the keyboard. I still have not had the time to test with an arduino (actually I am thinking to use an esp32 which I have in the box) just to see if the midi is received correctly on the other side of the octocoupler.If you get round to test yours with the blackpill let me know if it works

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 29, 2025, 06:18:16 am
content: You can install the mxcube ide that the developer used and have it echo the midi in on the tx out. I don't know the HAL stuff for this and how to configure this in the cube ide, but in the main.c file is where the uart interrupt is being handled. There you can add the write to the transmit register.You have to enable the TX pin for its alternate function of course. In the training series there is a video on the mid, so maybe watch that to see how to do this.

author: Fluxia
author_rank: Contributor
timestamp: March 29, 2025, 11:33:28 am
content: I will try but it will take me some time I think, I have used arduino in the past to build midi controllers but just recently started learning using ESP32 boards (with platformio on visual studio), which seems reasonably similar to coding an arduino. But STM32 seems like a much steeper learning curve (also my knowledge of C is fairly basic). These videos will certainly help me, I hope.In themeantime I found this guy who explains MIDI very well, I am posting it as if anyone is interested in learning MIDI this is pretty good...this is just the part where he talks about the electrical signal path, he mentioned that he also has a video on octocouplers but haven't found that yet (he might have deleted it)[url=https://www.youtube.com/watch?v=V0LmHM54nwc]https://www.youtube.com/watch?v=V0LmHM54nwc] [url=https://www.youtube.com/watch?v=V0LmHM54nwc]https://www.youtube.com/watch?v=V0LmHM54nwc]https://www.youtube.com/watch?v=V0LmHM54nwc] https://www.youtube.com/watch?v=V0LmHM54nwc]https://www.youtube.com/watch?v=V0LmHM54nwc]https://www.youtube.com/watch?v=V0LmHM54nwc]https://www.youtube.com/watch?v=V0LmHM54nwc] https://www.youtube.com/watch?v=V0LmHM54nwc

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 29, 2025, 12:37:42 pm
content: The link in your post is corrupted. Here is a proper one.For me this is all old news. I worked with MIDI almost since it was released. First as a hobbyist connecting my Radioshack/Tandy TRS-80 to my Siel Opera6 and later as a kind of instrument developer working for a Dutch foundation called STEIM.https://en.wikipedia.org/wiki/STEIMI think the STM32 MCU's are easier than the ESP32, but that is because I have not played with the ESP32 yet. For what I understood, both are more or less supported by the Arduino environment.In my opinion, what is needed maybe more than knowledge of a programming language, is to understand how the hardware works. Things like serial interfaces, timers and DMA. The connection to C on hardware level is very simple. Just reads and writes of memory locations.Basic plain C is all one needs to get things working. With this I mean the syntax and the low level instructions like if, for, switch, while and of course creating functions. A lot of what people call C are actually extensions from libraries. Functions like printf or fopen are not fundamental parts of C. These are just functions one can call to do specific tasks.I most of my embedded projects I do not use these libraries. The Arduino environment on the other hand is basically build on it. For every hardware module or display you can find, there almost always is a library available to make use of it. That is what makes it appealing to many people.

author: Fluxia
author_rank: Contributor
timestamp: March 31, 2025, 09:14:55 am
content: Quoteyou are right, the part where you configure the hardware is completely new to me and it's a part that is behind the scene in Arduino. it seems it gets included in the main file with stm32 (although self populated from the initial configuration GUI of the STM32CubeIDE.it's good to learn but takes time... and I still have not had the time to test the midi signal, hope to find some time today...in regards to the libraries, I tend to use when convenient (is for periferals like lcd screen, neopixel etc....) it would be just too much work to do everything at low level. I have created some library for myself, worked a bit with classes, that is my level ... fairly basic, but you are right it's enough to get on for these kind of project (and have fun:))

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 31, 2025, 04:01:04 pm
content: To me the STMCube stuff obscures all the hardware initialization too, to some extend. I find this whole HAL stuff horrible, and for me it takes just as much time to read up on the available functions and how to setup the initialization structures, as reading the chapters in the reference manual for the particular peripheral.As written before, I'm a bare metal programmer and start at the reset vector. Here is a link to some early work with the STMF303.https://github.com/pecostm32/STM32F303_Sine_Square_Generator/tree/mainI'm still working on finding a good balance between making things more reusable and fast coding a simple project in almost a single file.Here is a link to a bit more structured work:https://github.com/pecostm32/FT_Remote

author: Fluxia
author_rank: Contributor
timestamp: March 31, 2025, 06:10:56 pm
content: Nice, although quite above my level to give you a proper feedback ...I managed to test the MIDI signal. there is nothing wrong with it. So the mistery remains to why this Blackpill is not outputting what it is suppose to output from Pin A7..., if I didn't try two different boards I would now be sure that this is a hardware problem ... as suggested in his comments by synthetech. But two boards with the same issue seems unlikely - unless it is the model that is the issue

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 31, 2025, 06:41:33 pm
content: Thinking about your problem and synthesis in general, there is more than sending a note on to getting output.The synth needs things like output volume and proper ADSR settings to produce sound. No idea if the basic thing, after programming the black pill has proper settings to begin with.From what I get from your posts is that there is no signal on the data in of the DAC module, but the bit and word clock signals are running as they are supposed to. This means that the DMA is running and sending something to the I2S interface, but the data is constantly zero. Maybe you have to look into the MIDI codes that are used to set the synth parameters.

author: Fluxia
author_rank: Contributor
timestamp: April 01, 2025, 06:09:35 pm
content: QuoteOf course!!... but seing that other people have built this project - and it is working for them - I am going to assume that the hex file that I have uploaded on my blackpill is the same as theirs, and therefore it should work, it should not be a problem with the code. So the possibiolities are the following:1 the hex file has been changed (unlikely as Synthetech would have said it)2 there is something interfering with the hardware (the circuit is exatcly the same as per instructions, and I have now extablished that the midi msg to the blackpill is fine).3 there are hardware differences between my board (BlackPill STM32F411CEU6) and theirs. Synthetech mentions BlackPill STM32F411 in his video so this is also unlikely. Also I have tried 2 boards, just in case it was faulty but had the same result. mindbending.....