Results of a study of charged pion production in 12C+12C collisions at incident beam energies of 1A GeV and 2A GeV, and 40Ar+natKCl at 1.76AGeV, using the spectrometer HADES at GSI, are presented. We have performed a measurement of the transverse momentum distributions of pi+- mesons covering a fairly large rapidity interval, in case of the C+C collision system for the first time. The yields, transverse mass and angular distributions are compared with a transport model as well as with existing data from other experiments.