Recommendation for PIC microcontroller for HID USB Controller - Page 1
Forum section: electronics / projects

author: aiq25
author_rank: Regular Contributor
timestamp: April 25, 2017, 02:19:19 pm
content: Hello. I'm working on a portable gaming system using the Pi Zero and I want to make my own PCB for it. I never got PCB's made, so I think this might be a good experience for me (well not for hobby use anyways).I'm looking to create a USB HID controller to use with the Pi. In my prototype I directly soldered onto the Pi Zero pins. From what I understand, using a USB controller is a better option.What PIC micro would be the cheapest within an SOIC package that I can use a USB HID? I really don't feel like soldering anything smaller than SOIC. I would like at least 12 I/O pins for buttons, 1 ADC (for reading battery voltage), 2 I/O pins for driving battery indicator LED's.I'm also open to an Arduino based solution, if I can use an Arduino bootloader.Thanks!

author: Buriedcode
author_rank: Super Contributor
timestamp: April 25, 2017, 02:42:28 pm
content: The PIC16F1455 seems to be the cheapest USB capable PIC. Available as SOIC14 (there's your 12 I/O, but one is input only).You could just use pre-made playstation knock-off controllers. Cheap and cheerful.

author: tszaboo
author_rank: Super Contributor
timestamp: April 25, 2017, 03:10:45 pm
content: The Arduino Micro/ Leonardo does USB HID. Probably it is ten times easier to get it working.

author: theatrus
author_rank: Frequent Contributor
timestamp: April 25, 2017, 04:01:47 pm
content: That PIC is my go to for super-cheap-and-cheerful USB. The libraries are not terrible either.You can also look at an Arduino Teensy - it will be total overkill spec wise but is well supported.

author: aiq25
author_rank: Regular Contributor
timestamp: April 25, 2017, 06:47:36 pm
content: Thanks for the recommendations. Is there are recommendation for a 20-pin USB PIC micro? I would like to have couple of I/O's extra in case I need them for something.

author: Buriedcode
author_rank: Super Contributor
timestamp: April 26, 2017, 01:02:06 am
content: Quote from: NANDBlog on April 25, 2017, 03:10:45 pmI forgot about the Pro micro! I use that *a lot* for prototyping, and its USB libraries are stable.As for 20-in PIC's, I'm sure there are newer and cheaper ones, but I still have projects using the PIC18F14k50. 15 I/O, 16kbyte of program space, nice little job for a step above the 16F1455.Microchips libraries can be a sod to use, at least they were last time I did anything USB in earnest (MIDI, keyboard emulator etc..). That said, I ended up cheating and using an example project, and modding it. Either way, at least the IDE and libraries are free. But so are Arduinos. All depends on what you're familiar/comfortable with.

author: H.O
author_rank: Frequent Contributor
timestamp: April 26, 2017, 05:09:09 am
content: 16F1459 would be the equivalent of the 1455 but in a 20-pin package, next would be the 18F13K50 / 14K50. Those three are the only 8bit, 20-pin parts with USB peripheral- according to Microchipssearch tool.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: April 26, 2017, 09:37:48 am
content: I thought I would never find myself arguing against PIC but here we are...Depending on your application you might like to consider Teensy. I have a Thrustmaster F22 joystick and bits and pieces which I have been meaning to revitalise when I have time (a bit likehttps://forum.pjrc.com/threads/33371-Thrustmaster-T-Flight-Hotas-X-Teensy-MCU-mod-(USB-Flight-Joystick-Throttle)and for this project I need USB and I/O. Teensy seems to be a good fit.But... Also checkout...http://www.leobodnar.com/shop/index.php?main_page=product_info&products_id=204&zenid=bc971931b76a59a1848895004f293822Looks like he uses 18F2458Could you be a bit more specific about your requirement?Teensy has quite alot of USB HID support....https://www.pjrc.com/teensy/td_joystick.html

author: sanwal209
author_rank: Regular Contributor
timestamp: April 26, 2017, 09:38:28 am
content: Hello,PIC18F2450/4450 it fullfils your I/O requirements and USB. It costs 3.15 USD on Digikey.

author: aiq25
author_rank: Regular Contributor
timestamp: April 26, 2017, 01:29:38 pm
content: Quote from: NivagSwerdna on April 26, 2017, 09:37:48 amI'm looking to create a handheld Pi Zero based gaming system. I'm looking to put all the electronic components I need on one PCB. I have a prototype working but it uses various eBay modules (which I don't entirely trust either) and does not have a USB HID for the game controller. There are at least 12 buttons required for the controller (for what I want to use it for).I would like to use a micro as a HID device for the game controller. Since I will be using lithium ion batteries, I would like to also monitor the battery voltage and have couple of LED indicators to warn of low battery charge.I'm thinking I need 14 I/O's for the game buttons and the light indicator, plus one ADC at least for battery voltage monitoring.I think Teensy might be a good option. I will look into that as well.

author: aiq25
author_rank: Regular Contributor
timestamp: May 01, 2017, 07:14:11 pm
content: I'm thinking the coding might be easier with an Arduino bootloader, so I think I will go with an ATmega32U4. Will need to do more research. Seems like the Leonardo is the best option (instead of the Sparkfun's Pro Micro).

author: stj
author_rank: Super Contributor
timestamp: May 01, 2017, 07:21:16 pm
content: use an atmel and start with something like this:http://www.raphnet.net/electronique/usb_game16/index_en.phpmost of the work has been done for you!lots of good stuff on that site!

author: rfbroadband
author_rank: Unknown
timestamp: May 01, 2017, 07:23:24 pm
content: I have used the PIC32MX family many times for USB HID devices. (read the errata if you want to use the MZ series)

author: mariush
author_rank: Super Contributor
timestamp: May 01, 2017, 07:50:11 pm
content: You may also want to look at how fast ADC works on various micros. You can probably do at least 1000-2000 accurate measurements per second which should be enough for a controller, as most of the time the buttons are pressed for more than 1ms so your controller would catch them.With PICs you have 10 bit ADC and a built in voltage reference that can be configured to 1024mV, 2048mV or 4096 mV so it's straight forward to do the conversion, you'd have 1..4mV per step.So for example, it wouldn't be far fetched to have the most important/most often used 8 buttons (let's say left right up down a b x y) on an 8 bit port and set interrupt on change so that your micro would be notified instantly when a button changes, and the less important buttons could be configured to produce various voltage levels when pressed .. for example buttons like start , select (my mind goes to nintendo gamepad) could output 0.5v , 0.75v , 1v etcAssuming you may want to run the micro either from internal battery (3.7v to 4.2v) if let's say you add some bluetooth module to your controller for example, or from usb while the internal battery charges (5v), you'd probably set the internal voltage reference to 2v , but that still gives you easily enough separation for probably 8-12 buttons.. and easily done with a bunch of 1% resistors. Could potentially even run the ADC in 8 bit if you really need fast conversions.The only potential downside is that you may or may not miss when two of these less important buttons are pressed at the same time but with clever choice of resistors you could actually detect when two buttons are also pressed.This could make it possible to use the cheaper 14pin pic, reserving 8 io for most important buttons, 1-2 pins for led (maybe bi-color , amber for charging battery, green for on, or use just one pin and blink the led for charge status), 1-2 pins for adc of the less important buttons and one pic for adc of battery .. you're at less than 14 io pins.