Painful sex has stopped now that I have stopped taking the pill after 6 years. Could the pill have caused this pain?

Yes. Depending on the strength of the birth control pill, very low dose pills can cause vaginal dryness leading to uncomfortable intercourse. Coming off the pill allows your ovaries to start producing higher levels of estrogen and more vaginal lubrication.