I have a Pontiac grand am,its sometimes has a rough idle when I stop. on 2002 Pontiac Grand Am

The head light on the car flashes during this rough idle. What would be the possible cause.

2 answers
have it scan tested and go from there
could be a wiring issue or battery issue. is the alt charging ok?