Electronic – Connecting a microcontroller to the PC via USB

picusb

I'm developing a circuit on a breadboard and using PIC18F4550 microntroller (supports USB connection) but I just wonder how I can connect it to the PC.

Should I get a type A to type A cable, cut it from one side and connect the internal wires (D+ and D-) to the microcontroller?

Or is there a specific connector for that purpose? I got a male type A USB connector but looks like it can only be used with PCBs.

Best Answer

A proper device-side connector would be USB-B: USB-B (full size), mini-USB-B or micro-USB-B. Then you can use a standard USB A (computer side) to USB B (microcontroller side) cable.

There's a large amount of USB connectors.

I've never seen one made for breadboard, and that's not a coincidence:
Breadboard and USB are a bad combination. While low-speed USB might work, Full-Speed USB, which your PIC supports, is 12 Mbit/s, and that's got an analog bandwidth that really doesn't play well with breadboard.

You'll have to build a small PCB on which you solder the connector, and on which you also connect pin headers to plug into your breadboard.
In a pinch, you can of course cut any USB cable that plugs into your PC (don't buy a USB A-to-A cable - just get any thrown away USB cable). USB cables have colors that are standardized, so it's easy to solder pin headers to them.

Again, that might work, but I'd advise you to not try to do USB on breadboard, unless you really like debugging things that work sometimes and sometimes not, and stray signals all over the place.

I'd recommend buying a small microcontroller board that has the microcontroller soldered as well as a USB connector, and pin headers for plugging into breadboard underneath. For example, something like this:

Nucleo-32 eval board

(which you can buy from many places).

There's really very little reason to use a PIC18F4550 (wow, that ancient thing costs like 6€!): There's cheaper, faster, less power-hungry, more RAM, more flash devices, like the microcontroller soldered onto the board above. The whole board is 3€ more expensive than your PIC18F4550, and comes with USB, and a USB Programmer, and multiple LEDs, and honestly: Programming complex software¹for a PIC18 is really annoying compared to using FreeRTOS or mbed to develop your application on a modern, well-supported ARM microcontroller.

I can only stress how sensible it is to not implement a USB stack yourself — there's just so many things you can do wrong, and PIC18 is not really the perfect platform to learn USB handling on - especially not on breadboard, where you can't know whether it's the fault of your firmware, or of the bad signal quality, that things don't work.


¹ and you'll do that – handling USB on these RAM-minimal PIC18s isn't easy!