Photoproduction of charged pions from helium and hydrogen