How to connect PIC32MX470F512L to a micro usb connector?
As with so many things in electronics, you start with background knowledge and add the specifics of whatever you are dealing with.

In your case, background includes understanding how USB works.

The "Signaling" section of the wikipedia article explains that the signals are bidirectional and differential.  This scuppers your idea of using optoisolators.

The signal levels are also defined, and have little to nothing to do with the 5V power present on the cable - it therefore doesn't matter to the signals whether your PIC operates at 3.3V or 5V.

The next stop is the datasheet for the chip you want to use.

Page 114 shows you that it has built in hardware for USB.  Anything you just randomly add will interfere with its proper operation.

Page 114:



Page 113 of the datasheet refers you to Section 27. “USB On-TheGo (OTG)”  (DS60001126) of the PIC documentation.  Available here.  It gives you the gory details of actually controlling the USB functions through the PIC. It also refers you to details in the USB specifications.

A quick run through shows the actual electrical connection to be rather trivial - unless the pins of the PIC are located more than just a few millimeters from the pins of the USB connector.  In that case, you get to take a "quick" lesson in designing impedance matched PCB traces and RF design.

Once you have things electrically connected, you get to deal with the software side and with the regulatory side (USB IDs, and intellectual property concerns if you are making a commercial product.)



I wish you luck.  You're going to need it, and a whole lot of perseverance to reach a point where you can successfully implement your own USB device.