Sunday, October 16, 2011

Atmel Attiny45 / Attiny85 based USB MIDI controller

Today I made a MIDI controller out of an Attiny45 and a potentiometer.

This project implements the V-USB firmware from Objective Development to emulate a class compliant audio / MIDI stream device using an Atmel AVR microcontroller. It is based on the V-USB-MIDI project by Martin Homuth-Rosemann and partly on the 4-key-keyboard project.



The nice thing about this project is that it takes advantage of the internal RC oscillator of the Attiny and therefore not even needs an external crystal.

Hardware needed:
  • 1x Atmel ATTiny45-20PU or ATTiny85-20PU microcontroller
  • 2x Diodes (1N4148)
  • 2x 68 ohm resistors
  • 1x 1.5K resistor
  • 1x 0.1 uF capacitor
  • 1x 10K potentiometer
  • 1x USB cable with USB-A plug
  • Programmer for Attiny45 / 85

Schematics:



The Fuses have to be set to 0xC1 (low), 0xDD (high) and 0xFF (ext.). 

The PID and VID used in this project are sponsored by Objective Development.
AVR is a registered trademark of Atmel Corporation.

Download the project and the .hex file here. It should work equally well on both the Attiny45 and the Attiny85.

19 comments:

  1. Greetings from Estonia.

    Nice project. Simple and cheap. U inspired me to take out my tools and work with my midi project again. What is been sleeping 1,5 years. But can u send me your project files? The link above is death.

    Edu,
    vana.peni@gmail.com

    ReplyDelete
  2. Thanks! It's great to hear that this little experiment is useful for someone. Sorry for the dead link, I didn't know that the file hoster I used deletes files after a certain period of time. I updated it, now it should work again.

    Greetings from Germany,

    Thorsten

    ReplyDelete
  3. Hi
    Nice project.
    How can i complie the project file under windows?
    I tryed both WINAVR and AmtelAVR with no success
    Thx

    ReplyDelete
    Replies
    1. Hi! Sorry for not replying right away. I am using an avr plugin for Eclipse, so I don't have any experience with WINAVR and AtmelAVR. But as far as I know WINAVR has a makefile template which should be easily adapted to this project.

      Delete
  4. I had no problems with understanding the code, but I'm sort of a noob when it comes to electronics. I figure I could replace the 68-ohm resistors with 100-ohm right? Or, would that lower the voltage of the data lines too much?

    BTW, this is an awesome project! I had been looking for a well documented and useful example just like this to learn from.

    ReplyDelete
    Replies
    1. Hi! Thanks! Unfortunately I still haven't had the time to make something useful out of it.

      The 100 ohm resistors work fine. Somewhere I read that "68" is an "educated guess" and anything between 30 and 100 ohms should work well enough. Reportedly you also can leave out the zener diodes and use a 2.2k ohm resistor instead of the 1.5k one, but as my electronics knowledge is also very limited I can't say anything about that. ;-)

      Delete
    2. It's just "diodes" instead of "zener diodes", of course.

      Delete
    3. Thanks for the reply. This has proven to be a good learning experience for me. I have a few thoughts I'd like to share.

      It works well with your circuit (I built it the same day I left the previous comment), but I occasionally got a "USB device not recognized" error in Windows. This was fixed by adding zener diodes (3.6v 250mw) between the data lines and ground.

      USB doesn't like anything above 3.6v or below 3v. Since we're using such small current (20ma I believe) and the response curves of real world diodes is not perfect, the real voltage out of the data lines is about 3.3v at 20ma (what we need).

      I also used a 10k resistor for pull-up instead of the 1.5k one because I couldn't find any and because that's the usual value I've seen so I hoped it wouldn't matter. It worked fine. :-)

      I'm thinking of putting this circuit to use as a MIDI guitar pedal. I could probably put the guts in an old, broken pedal I have. I just need figure out how use the hall effect sensor inside it.

      I use Amplitube 3, so this should map nicely to the virtual wah, volume, etc. pedals in the software. I'm also considering implementing a mode switch function where I can use the same physical pedal to control multiple pedals in various ways. e.g. virtual pedal #1 is inverted and pedal #2 is not, deadzones, auto-oscillation, etc.

      Thanks again, man! I now have something to keep me busy!

      Delete
    4. You're welcome! Thanks for sharing your findings!

      Delete
    5. is it possible to program these hex files into the attiny using arduino as isp?

      Delete
  5. The same question:

    "is it possible to program these hex files into the attiny using arduino as isp?"

    thanks in advance

    ReplyDelete
    Replies
    1. It should work. I've never used the Arduino as an ISP, but as far as I know you can use avrdude (the WinAVR uploader program) together with Arduino ISP.

      Delete
  6. hello,

    Is it possible to update the link for download, it seems broken link without any progress for long time.

    ReplyDelete
    Replies
    1. Hm, for me the link still works. Perhaps you just have to try again.

      Delete
  7. Can you give us the source code of the attiny? I wonder if i can make a 4 pot controller... thank you

    ReplyDelete
    Replies
    1. Hello Alex! The source code is part of the ZIP file I posted the link to in the last paragraph of the article (just click in the word "here" ;-) )

      Delete
  8. Is this a standard midi compliant device? What I mean is, do pins 3 and 6 which are currently unused allow for standard midi to be entered into them and this will be passed onto the host computer through the attiny chip? Has anyone else taken this and developed it further? I'm finding it sad that there are very few solid projects on the net that will let me turn an attiny into a near midi class compliant device. There is a project on the web that converts your whole Arduino into a midi device but I don't want to do that. I want to make a cheap midi to usb adapter for a foot controller project I have in mind. Any help would be appreciated. As of now, I see my only solution is to buy one of those ultra cheap usb to midi adapters on ebay and use that instead. They only cost £3.

    ReplyDelete
    Replies
    1. Hello Grant, if I understand you correctly you just want to connect a "good old midi cable" to your computer using usb. In that case, I would go for the ebay option. Although the attiny is recognized as a standard midi compliant device by the host you connect it to, I don't think it has enough processing power left to read serial midi data (which is transmitted with about 31 kbps) on pins 3 and 6.

      Can't you just connect the potentiometer in the foot pedal to an Atmel avr mcu and also use the V-USB-MIDI firmware?

      Delete
  9. Hi Thorsten, thanks for the reply. Basically I'm obsessed with midi foot controllers. I've made them out of all kinds of things and I just keep finding new ways to create them and improve their design. I've made a foot controller from a wireless x-box 360 controller using Flowstone. Flowstone is amazing software you should check it out. Right now I'm exploring Arduino and I really like what it can do. It's not hard to learn, but it's time consuming for sure. I've invested in some cheap peizo sensors that I plan to use to make a combination midi foot controller and drum pad. I'm into loop guitar so I'll be able to trigger drums with my feet. It just seems so natural I don't know why I didn't think of it before.. Probably because I thought it was something I wouldn't be able to do unless I tore apart one o those new tiny midi keyboard/drumpad gadgets that are getting pretty popular.. and I have a thing about destroying stuff that's working..

    Anyway, I've decided to use the cheap ebay usb to midi adapter and strip it down to it's bare circuit board. I've also recently discovered something new. and that's the Arudino Nano. Not the standard one, but the one that has no usb to serial chip. they are really cheap from china at about £2 each. basically it's an Atmel 328p chip in a small chip design. you have to solder on any pins you want but they're included. So it's really economical and smart package. It will let me have several midi drum pads and several foot controllers..

    I'm also kinda interested in midi controller clothing. Sounds ludicrous I know.. but the idea I have is to have a live show in which I hand out to the audience all these midi vests that they can put on and on each of the breasts are three drum pads all connected wirelessly to a computer.. and so you hand out the first one and that person starts to make a rhythm.. and then you coax someone else to put on the next one and they start to add to the rhythm mix and maybe you hand out two more and the whole idea is that each vest has it's own vibe and is entirely different than the other vests.. one is red tartan, one is bright yellow, the other one black.. etc. I'm not sure it would go over well here in the u.k. though.. I used to live in Portland Oregon and it has a great underground art scene. i'm living on Glasgow right now and i'm not seeing much of an art scene at all.. where do you live? I'm thnking of moving to London.

    anyway, I have to run. I enjoyed this blog as it was highly informative.

    take it easy,

    Grant

    ReplyDelete