• Welcome to Circuitbenders Forum.

Midi - PIC basic & microcontrollers

Started by Z3R0, December 29, 2010, 05:32:30 PM

Previous topic - Next topic

Z3R0

Can anybody suggest a good book to read on this topic?

Obviously there is stuff out there which i could make as an example but i'd rather take it from the ground up so i can tailor my code to suit whatever it is i'm trying to do at the time.

I've got a fair bit of programming PICbasic down but how MIDI is read and turned into useful things by the microcontroller remains a mystery.

It would be preferable to do this in PICbasic for me as i don't want to have to learn another language if i can help it.

Highly liquid are pretty much making what i'd like to do. But i don't like paying that much a shot when i know i could do it myself with some time and effort.

Plus i LOATHE being stung on import duty....

Giving money to people for nothing.... It offends me :/

.

Circuitbenders

I could do with exactly the same thing. I got started on messing around with PIC's but the learning curve is steep to say the least and the book i had involved so much assumed knowledge that it was next to useless unless you more or less already knew 80% of what it was trying to teach you.

Whats more useful for MIDI, a PIC or Arduino/AVR?

i am not paid to listen to this drivel, you are a terminal fool

Z3R0

By the looks of it arduino is the easiest option to take. But PIC is by far the cheapest. Plus i was more drawn to PIC as you're working from the floor up.... A long time ago

I got on ok as far as i took it with PICbasic. But it's one of those things you have to do regularly or else you forget all the TrisA, TrisB, poke 6,255 nonsense. As i have more or less. Getting back into it though.

I'll keep searching and attempt to decipher what i do have to work with and see if i can make sense of it all. It can't be rocket science. Can it?

It's difficult but very rewarding path to take.

I'll buy EVERYONE a stella on the day i tell ableton to make a casio SA20 it's bitch and it works :)



Gordonjcp

I'm not keen on the PICs with BASIC.  Yes, the Arduino boards are a little more expensive, but you can drop a plain unprogrammed Atmega328 in and blat an STK500 bootloader on quickly and easily.  You can also program them in straight C without the Arduino IDE, which is what I prefer to do.

I've actually written some MIDI code for them, although because I'm using the Arduino's USB serial port for programming I just wrote a little converter program which takes MIDI in and translates it to serial data for the Arduino.  If I recompiled my AVR code with the baud rate set to 31250 and stuck a MIDI input onto the board it would work just as well.  In fact, it would be quite easy to make a standalone instrument that uses an AVR, since they only require a crystal and two capacitors to run when programmed up the way an Arduino is!
If at first you don't succeed, stick it through a fuzzbox.

Z3R0

It seems most of what i find is programmed in C. I've taken the basic route simply because it was what i stumbled upon before i knew a thing about any of it. Spent an all nighter in the shed on some basic led projects and in that time made the equivalent to the sequencers i stick in small DD drum machines with a few buttons and a switch to control it. The fact picbasic and the compiler i use were all available to me there and then also decided my microcontroller 'destiny' i guess..... XD515 gave me all the details of his digital dub sirens ages ago. I forget what they were based on but it was similar to an arduino setup. I bought the project board and one of the controllers but never followed that one up through being too busy. Having looked at the code though they do look a lot easier to program than pics in basic.

Once i'm done with my current pcb projects (converting all the stuff i take hours making en-mass on strip board to pcb) i'll get back onto the PIC stuff. It seems that clear infomation and hands on projects involving midi are pretty rare. Even rarer with the uncompiled code to look at. It will undoubtably mean many sessions of walking away at 4am thinking 'fcuk this!' but in the end it'll come together. It usually does.

Z3R0

This may sound like a stupid statement. But having only got to the point of scratching my head and touching on the midi side of microcontrollers it's a bit tiny fish in a huge pond for me right now.

Am i right in assuming that the first step in achieving what i want is to read up and understand thoroughly the way midi is 'spoken' as it were. And then figure out how to write a program which understands this and instructs the pic to do something useful in response to what it's recieving.

I'm guessing this is the case. Do you have any good pointers in where to look to thoroughly understand midi?

So far i've merely told a pic what i want it to do. Not attempted to make it 'talk' to anything else. LCD displays are the next logical step in my sequencer project as wasting defined output pins on things like leds seems totally pointless when i can use an lcd as the complete graphical interface for the system. I'm guessing talking to an LCD will tech me a little of what i'm trying to learn here all be it in a very basic way.

Any help would be great. I'm more into adding stuff to machines than modding what's already there and control is fast becoming the necessity in the stuff i'd like to make in the future. DD6's with 16 step sequencers and some pattern memory would be amazing. But give them midi control too and i reckon given how nicely they mess up when bent they'd sound about as good as it gets in the glitch percussion department.




Gordonjcp

Certainly reading up on the MIDI protocol would help.  Google is your friend.  To boil it down to the simplest, hardware-wise you want a serial port and an opto-isolator for input, and a transistor and a couple of resistors for output.  The serial port needs to run at 31250 baud, which most microcontrollers can do since they can generate pretty arbitrary baud rates (ie. they're not stuck to 1200/2400/4800/9600/19200 and so on, like PCs are).

From the software side, it's just strings of bytes.  Most messages are three bytes long (Note On, note number, velocity for example).  Patch change is two bytes, and some are a single byte.  You've got to watch some of the single-byte Systems Realtime messages since they can occur in the middle of another message!  So you might get Note Off, MIDI CLOCK, note number, velocity - and that won't work correctly!  Your MIDI parser needs to at least ignore these, unless you're actually using MIDI clock.

See, if you used AVR microcontrollers then you could just rip off my MIDI code.  And fix the bugs in it.  Ahem.
If at first you don't succeed, stick it through a fuzzbox.

Z3R0

Haha. Well if all else fails i'll take you up on the offer and start again from scratch. Well.... scratch with some source code to read to help understand the ins and outs of it all. The frustratinf part of anything like this is starting out. Once you understand the fundamentals the rest just falls into place.

Z3R0

For the first time in forever i decided to give the yearly outing of getting absolutely hammered and pointlessly spending about £100 on booze a miss. So i ordered two Pic C books instead :)

I thought about things and decided that as C seems to be far more popular than basic with loads more examples out there to study and learn the working of i'd just jump back to square one and start again.

All i really did in basic was configure some in's and outs to interact and do what i want so it's not gonna' be hard to do it all again in a new language. Seems like a wise move to even the odds a bit before i devote the time to cracking the midi code mystery...

Gordonjcp

Well, the C stuff compiles to machine code so your programs are going to run a hell of a lot faster.  It's not even that hard to program PICs in assembler *anyway* so you have a lot of fine-grained control over timing-critical sections of code.
If at first you don't succeed, stick it through a fuzzbox.