PIC based USB input devices

USB is convenient and that makes it desirable in many many projects. [Simon Inns] has the process down and is sharing it with his recent PIC based USB tutorial. Prompted by requests for help on the matter after having published a post about his Commodore 64 interface, he set out to detail the particulars when it comes to using the PIC 18F family as USB input devices. This example uses a PIC 18F4550 with the circuit built on a breadboard. There’s not much required here, an oscillator, a few passives, and a USB B connector. The magic really happens in the code. Take a look at this well-written guide and give it a try with your next project.

Don’t need USB? [Simon's] game hack, the Ultimate Simon is always worth another look too.

Comments

  1. M4CGYV3R says:

    You rock, Hack-a-Day. This is the sort of thing I love to see on here and keeps my hope for this site alive.

  2. Rizla++ says:

    Ok, nice post and pure open source too. But I can’t help it, I have to say that a better approach was posted around 3 years ago at Elektor mag.
    http://www.elektor.com/magazines/2007/november/usb-data-acquisition-card.271706.lynkx

    You won’t find a schematic on the site,unfortunately, which makes this hack even more valuable. But if you can get your hands on that article, do it! Building that board was my own first contact with usb protocol! Since then, I just love PIC’s :D

  3. jwt says:

    bah, C. I’d love to see something like this for mpasm.

  4. rob says:

    Sweet. I’ve been wanting to try using USB but always been to daunted to try it. Here comes an article using both the PIC currently in one of my breadboards and my fav compiler, nice one.

    (should’ve been a Hi-Tide project though and it’d have been perfect :D Speaking of Hi-Tide, why the f is Microchip nuking it? It makes me sad :( )

  5. So its V-USB for PIC

  6. Whatnot says:

    Hate to niggle but: A crystal is not the same as an oscillator, it’s part of one.

    Now that we are past that, nice clear site and nice to have such a explanation available, kudos.

  7. DLC says:

    Nothing new, everything they put was exactly from the Microchip USB applications, probably they just renamed some functions, but they didn’t add anything to the solution already provided.

  8. Chris says:

    The computer side source code here is 29Mb… to connect a soft button to usb device.

  9. Simon says:

    There was a file missing from the mplab zip (pointed out by a hackaday user – thanks!). This is now corrected and there is an updated zip on the site.

    @DLC – The article states what it’s based on. I ported the USB stack code to HiTech C, and restructured it to make it easier to understand. I also targeted it to the breadboard USB device so you don’t need to buy an expensive PIC DEM FS USB board to try it. It’s not supposed to be original, just easier for a complete USB beginner.

    I hope that makes the intention clearer.

    /Simon

  10. fartface says:

    Why use a xtal plus caps? resonators are far cheaper and easier to deal with. Cripes no caps needed at all and unless you need insane accurate timing skip a Xtal and buy a bag full of resonators and make PIC design even easier.

    P.S.: This is the stuff that needs to be on hack-a-day more often. This one rocks, and is hack a day uber-worthy. If you don’t release the code and schematics, then you are a poser wannabe and should NOT be on hack-a-day.

  11. osgeld says:

    pic, expensive tools, close source software, windows only

    sigh

  12. rj says:

    fartface: Resonators are accurate to maybe 1000ppm. Crystals are accurate, without trying, to 20ppm or better. If your code can tolerate jitter of 0.1% instruction to instruction — what resonators are known for — great! Use that part. But in my experience, the cost of a crystal and two 10-30pF caps is the same as a resonator anyway, and is better in every way.

    osgeld: Have you even looked at any of the thousands of “make your own programmer” projects for PICs? For pic18s, Broccoli18 was perfect.

  13. skipper says:

    One of the better posts I have read in a long time! Well documented and crystl clear. I’ve long wanted to dip my toe into the USB tank but now I think I’ll just jump on in Thanks!

  14. adam says:

    if this worked on a mac it would make that 1984 apple case mod from a few weeks back even better.

    also lol @jwt’s comment first everyone complains about the arduinos now C in general is bad and you need assembly.

    asm is too time intensive (coding and debugging) for hobby level projects, if this was being mass produced or you were really pushing the micro to its limits then it might be a good idea to look into

  15. Osgeld says:

    “osgeld: Have you even looked at any of the thousands of “make your own programmer” projects for PICs? For pic18s, Broccoli18 was perfect.”

    yes ive seen the programmers, but it doesn’t solve the other problems

    my main deal with the homebrew programmers is the sheer volume of them, and usually the OP makes no attempt to say what they will do, so to me as an outsider to the pic world, It seems that either I buy a universal programmer, or I spend the rest of my life making programmers for different chips

  16. Thank you thank you thank you for posting this… I’ve wanted to build something like this and get my feet wet with USB for a while. The PicKit2 programmer is a really nice beginners programming too, I bought one ages ago and it’s easily the most heavily used programmer in my workshop.

  17. John Smith says:

    @Osgeld The poster of the article doesn’t owe you anything. If you want to use Linux, great – you figure it out. If you want open source software, great – you figure it out. If you want to be a nice guy, you would create an article about it. But then jerks will complain that yours doesn’t use Windows and closed source.

  18. Osgeld says:

    where the fuck did that come from troll?

    I never said they owed me anything here is an idea for you

    FUCKING READ BEFORE OPENING YOUR TRAP

  19. sneakypoo says:

    And here’s a tip for you Osgeld. If you want people to take you seriously drop a few curse words and avoid the caps.

    Also, A Pickit2 will program and do ICD for the vast majority of chips you’ll ever play around with and it costs about $30. You can hardly call that expensive. The actual chips themselves are also dirt cheap.

    The official IDE/compiler runs fine under Wine from what I hear. As for open source alternatives, I’m not sure, as I’ve never felt the need to look them up.

  20. exponential decay says:

    Thumbs up simon

  21. I’m pretty sure there’s OSS PIC programmers. Look in your repository for hecks sake.

    IN other news, if i had a PIC this would be one of the first things i’d use. Get rid of the gameport and move to USB (which is more portable and stronger).

  22. Dan says:

    Nice article Simon! I made a webpage about the “CREATE USB Interface” awhile back (2005 if I recall correctly), and this is a nice update on the state of the toolchain for the ’18F series.

    http://www.create.ucsb.edu/~dano/CUI/

  23. racist says:

    Thanks Simon! I also tried to make a create interface, but I could never get the USB connection to work… I was using the 4450, but for some reason, couldn’t get it to go. Your tutorials are fantastic, and should help me get my project going in no time!

  24. Simon says:

    Thanks for all the encouraging comments! I know that there are a number of great PIC USB projects out there but, from my experience, the hard bit of USB is just ‘doing’ it in the first place. Best of luck to you all in your own projects :)

  25. therian says:

    Osgeld are you a time traveler ? If you like I can guide you on resent change in past 10 years, just tell me more about you journeys, how far can you go into future is it limited by you life span? will we have synthetic AI by 2050?and does this mean we erase limits of flesh by coping our ego into silicon and gaining immortality ?

  26. Simon says:

    Hi

    I’ve just completed a generic class for USB HID communication which greatly simplifies writing the Windows host applications and deals with all the USB specific communication for you:

    http://www.waitingforfriday.com/index.php/Open_Source_Visual_C%2B%2B_Class_for_USB_Generic_HID_Communication

    I hope this proves to be a big improvement over the original windows example.

  27. georgz says:

    Nice and simple application but it would be nice to have one written in assebly.

  28. DarwinSurvivor says:

    @osgeld I am personally using a PICKit2 programmer on linux (arch) using the sdcc compiler (open source) and pk2cmd (open source) to burn the chips.

    Microchip may not offer “support” for linux, but I’ll take the linux forums & IRC over Microchip anyday.

  29. dave68cat says:

    Hi,

    Great project, best I have found. going to use your interface to control my telescope auto focuser.

    Up to now I have been using the MPLAB C18 compiler. It there a code image for this compiler. If not, how much of a headache is it to port. Prob a school boy question – hope you can help ?

    Cheers, Dave

  30. Simon Inns says:

    Please check out my website for all the project details and you are welcome to ask any questions on the forum there.

    if you want to use microchip’s compiler you have to use their Generic HID firmware, however the C# library for Windows works with either firmware.

  31. min2max says:

    hello Simon,

    Thanks for the great article for beginners. I’m building and testing it but the device just didn’t work as expected.

    As reader Jason of your article on WFF has pointed out, the crystal oscillator could not necessarily be 20MHz. I have a 24MHz at hands and I’m using it. I’ve already changed the following line in main.c

    __CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & CPUDIV1 & PLLDIV5);

    to

    __CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & CPUDIV1 & PLLDIV6);

    to take into account the different oscillator frequency.

    I’m wondering if I should use different capacitors in lieu of the 15pF as you are using? Is this what made my device not function?

    And here’s another issue I’m stuck to -
    I have tried registering in the WFF forum. I’ve completed the process except for the activation. It seems some thing wrong because I cannot receive the activation email from your site.

    My user name is min2max and the email used is loadcom@sina.com. I’m wondering if you could do me a favor and activate this account manually at your side?

    Thanks

    Max

  32. min2max says:

    I’ve eventually got the device run.

  33. min2max says:

    Simon,

    I tried signing up the WFF forum with another user name and different email (yahoo), but I did not receive the activation email neither.

    Any help would be appreciated.

    Max

  34. Simon Inns says:

    The forum issue should now be fixed; please try registering again. Sorry for the issues!

  35. min2max says:

    Simon,

    Thank you for fixing the forum issues. It now works.

    Max

  36. AG says:

    It never works for me. Always windows says – USB device not recognized.
    I am using MPLAB / C18 pro compiler for the hex file. And then using EasyPIC5 board and mikroProg suite to load the hex file onto 18F4550.

  37. min2max says:

    It once worked for me. But at present it does not work. I get an PICKit2Error0028 while I try to simulate with a PICKit2 (red button version)

  38. min2max says:

    It once worked for me. But at present it does not work. I get an PICKit2Error0028 while I try to simulate with a PICKit2 (red button version)

    I have not changed anything either of hardware or software.

    It’s quite weird.

  39. zelda007 says:

    Hi,

    It is possible to have an USB example with Hi-tech C compiler ?
    All examples found are with Microship C18 Compiler…

    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s