MIDI Library for MikroC or MPLAB X - Page 1
Forum section: electronics / general

author: lorenrus
author_rank: Regular Contributor
timestamp: October 01, 2019, 09:16:17 am
content: Hi everybodyi'm looking for a MIDI Library, like the one that exists for Arduino, for MikroC or MPLAB X.Best regards

author: andersm
author_rank: Super Contributor
timestamp: October 01, 2019, 10:38:23 am
content: MPLAB X is an IDE. What microcontroller are you targeting, what kinds of features and functionality are you expecting from the library? Basic MIDI by itself is just bytes sent over a serial port.

author: lorenrus
author_rank: Regular Contributor
timestamp: October 01, 2019, 12:17:36 pm
content: HelloThanks for the reply.I initially made with Arduino Mega. Now that I have to industrialize it, I would like to use a PIC, for example 18f4520, but I'm not sure if he has enough pins.For this my first version I only use the Program Change function, but in the future I would also like to use its other features as well.So I wanted to know if there was a library that included any MIDI functionality. Like the one that exists for the arduino IDE.Best regards

author: Bassman59
author_rank: Super Contributor
timestamp: October 01, 2019, 10:01:09 pm
content: Quote from: lorenrus on October 01, 2019, 12:17:36 pmI don't remember offhand what is in the Arduino MIDI library, but I suppose I should ask: what is your intent? Are you designing a MIDI controller, that is something that will send MIDI messages to another device, or are you designing a MIDI-controlled "thing," which receives MIDI messages and does something interesting as a result? Or both?Also I assume you're using serial MIDI on DIN jacks and not MIDI over USB.MIDI isn't all that difficult. On the receive side you wait for bytes and build up a message to parse. On the transmit side you wait for an event and build a message based on it, then transmit the message.

author: lorenrus
author_rank: Regular Contributor
timestamp: October 02, 2019, 06:16:05 am
content: Thanks for the replyI have already realized my MIDI PEDAL but with Arduino mega. For this first realization i used only PROGRAM CHANGE function of Midi Protocol. I know that PROGRAM CHANGE is equal to a serial data.Now i have to create a PCB and i can't use Arduino Mega and i think to use PIC.For the subsequent realizations of my pedal board i would like to use all of functions of MIDI Protocol so i would like to know if there are a Midi Library for MPLAB iDE or MikroC that included all MIDI function.I hope I was clearbest regards

author: Fire Doger
author_rank: Regular Contributor
timestamp: October 02, 2019, 12:09:21 pm
content: You can't use Arduino mega but you can use atmega2560 which is what arduino mega has.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 02, 2019, 12:19:43 pm
content: From what I understand, you want to design a device that basically emits some MIDI commands (are you interested in receiving MIDI commands as well? doesn't look like it.)From the MCU POV, MIDI is very simple. You just need a UART TX @ 31250 bps. (You'll have to choose the system clock properly so that you can get this rate with the embedded UART peripheral of your MCU. This one is pretty easy. 31250 was not choosen randomly. You'll get that from dividing a pretty standard clock rate by a power of two.)Then it's just a matter of sending a few bytes. MIDI commands/messages are very simple. You really don't need any library to do this. You just need an MCU with an embedded UART, and send bytes.Actually, MIDI communication is pretty slow, so you could even bit-bang it without any embedded UART peripheral, even on a small MCU (but don't bother, there are craptons of small and cheap MCUs with appropriate UARTs.)

author: Siwastaja
author_rank: Super Contributor
timestamp: October 02, 2019, 02:02:33 pm
content: Yes. It's basically:1) Pickanymicrocontroller,2) Use a suitable crystal frequency so that it divides properly to the desired baudrate (31250 bps). 8 MHz will do fine, because 8000000/256 = 312503) Literally recreate the most basic "Hello world" uart example available. Should be approx. 10 lines of code.4) Instead of "Hello World" text, now just output the MIDI command bytes.

author: lorenrus
author_rank: Regular Contributor
timestamp: October 02, 2019, 03:38:19 pm
content: Yes i know. I spoke about PIC beacuase at home i have already PIC 18f4520.And i can program it with MPLAB X, for example. Correct ?Best regards

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 02, 2019, 03:44:07 pm
content: Quote from: lorenrus on October 02, 2019, 03:38:19 pmThe PIC18F4520 would be fine for this use. It has one UART, one ADC (if you ever need that for reading pots or such), and enough IOs.Since it can run from 2.0V to 5.5V, you have ample choice for your power supply too.One last advice is, preferably use an external crystal than the internal oscillator. MIDI is kind of picky regarding the baud rate, so a crystal-based oscillator will be safer to make your device robust.Yes you can use MPLAB X. You'll also need the XC8 compiler, which is a separate download AFAIK, unless you want to program in assembly (which I doubt).Of course you'll need a programmer "probe" too (such as Pickit or ICD...)

author: Bassman59
author_rank: Super Contributor
timestamp: October 02, 2019, 09:50:13 pm
content: Quote from: lorenrus on October 02, 2019, 06:16:05 amI think you're still missing the point. There are no "MIDI Functions," per se.You receive a MIDI message and parse it, and then decide what to do with the contents. And that's application-specific. What does your pedalboard need to do in response to messages it might receive from -- where?On the transmit side: you have a pedalboard, so I imagine a row of buttons. When you press a button, you send a control-change message. Or a program-change message. Or a Note On/Off message. Building the messages is easy.But you have to work out what your hardware is supposed to do.

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 02, 2019, 10:33:42 pm
content: Yep. If the OP still insists on using this said library, they can just give us a link to it here (provided that it's open source). It's likely not much more than some light sugar coating around UART transmission, and maybe a few constants with the various midi messages. Maybe a few functions to further sugar-coat it, each sending a couple bytes. Probably nothing to write home about.

author: lorenrus
author_rank: Regular Contributor
timestamp: October 03, 2019, 08:33:00 am
content: HelloPremise:I know Midi Protocol and i able to use Midi fuction without library.I was just curious if there was a Midi library for MPLAB X or MikroC.Best regards

author: SiliconWizard
author_rank: Super Contributor
timestamp: October 03, 2019, 05:01:51 pm
content: Just saying here, but you are probably (/have already) wasting more time looking for a possible ready-made library than writing it yourself...

author: lorenrus
author_rank: Regular Contributor
timestamp: October 04, 2019, 05:58:18 am
content: Good morningYes you are right, but in the meantime i'm realizing projects for job.I'm not idle hahahThank you very much