He became addicted to opiates after receiving morphine for medical reasons. It's easily done.
He also got clean for a long time - not so easily done.
Like I said, if you achieve half of what he did, you'll have done very well indeed. Of course, that's unlikely, because if you refuse to study the writings of anyone who ever made a mistake or showed human weakness in any of it's myriad forms, you're going to find your reading material quite limited.