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.

39 thoughts on “PIC Based USB Input Devices

  1. 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

  2. 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 :( )

  3. 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.

  4. 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.

  5. 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

  6. 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.

  7. 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.

  8. 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!

  9. 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

  10. “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

  11. 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.

  12. @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.

  13. 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.

  14. 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).

  15. 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!

  16. 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 :)

  17. 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 ?

  18. @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.

  19. 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

  20. 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.

  21. 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

  22. 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

  23. 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.

  24. 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.

Leave a Reply to exponential decayCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.