Usually we choose the correct form by instinct.
I am a teacher. (not me)
Give that to me. (not I)
There are other times when people make mistakes with these two pronouns. I/me is difficult when it is coupled with another pronoun or with a noun. This is when you have to think about the subject/object in a sentence.
We use I as the subject of the sentence, but the object of the sentence is me.
“It was I who did the homework,” or “It was me who did the homework.”
Make the statement simpler:-
“I did the homework.” so “It was I who did the homework,” is correct.
The teacher gave the homework to my friend and me. (Not I)
!If you don’t understand why the above sentence is correct, simplify the sentence again.
Deal with the two people separately.
The teacher gave the homework to my friend.
The teacher gave the homework to me.
= The teacher gave the homework to my friend and me.