The restaurant test
A quick mental check: if you're in a restaurant and you "ask" for something, you use pedir. If the waiter "asks" you what you want, he pregunta. One is a question; the other is a request.
Preguntar por
Note the common construction preguntar por = to ask about / to ask after someone: Tu amigo preguntó por ti (your friend asked after you). This is not the same as asking for something.
Pedir vs preguntar in indirect speech
In indirect speech, the distinction is especially clear: Me pidió dinero (he asked me for money) vs Me preguntó si tenía dinero (he asked me whether I had money).