NewPing library or Ultrasonic sensor interfering with other pins

I am building an obstacle avoidance robot with a Fundumoto shield which has specified pins to control 2 motors (pins 10,11,12,13 ) and set pins for plugging in an Ultrasonic sensor. (pin7,8). My motors work perfectly with my code until I start using the ultrasonic sensor. As soon as I use the sensor (with or without the newping.h library) the right wheel (B) which uses pins 11 and 13 can only go in one direction (reverse, which is LOW)

int SpeedA = 10;
int DirectionA = 12;
int SpeedB =11;
int DirectionB = 13;

I can't figure out what is happening!
I thought perhaps the newPing code was using the pin 13 for some timing purpose (some documentation on the web seems to suggest this), but then I used other code to run my Ultrasonic sensor (which does not need the newping.h or any other library) and the problem persists.

I attach my code in case this can help solve my problem. The real issue here is that I CAN'T change my motor pins as the shield does not allow that, so I MUST use pin13 (if that is the problem)

Is this my problem, and if so, is there another way around it (another library that uses different background timer pins or something like that)?
I also attach the picture of the shield I am using in case this helps.

I would really appreciate some help here, as I have tried so many things, but my understanding of what happens in the libraries and with the timers is too limited.
I use another library, the statemachine library called SM.h which could also be adding to my problem. :confused:

Testing_ObstacleAvoidanceWithFundumotoShield.ino (7.54 KB)

NewPing does not use pin 13. What it does use is a timer interrupt to check for the return pulse, so your code doesn't block waiting for the echo.

Since there are a limited number of timers, and PWM uses one timer for each pair of PWM pins, when NewPing uses the timer, PWM can't. So, you lose the ability to control the speed of motors connected to two pins. Which two, you'd need to experiment to determine.

I don't think that your problem is that you can change the direction of a motor. It's that you can't change the speed of the motor.

Thanks for your response Brattain

How do I see which pin is being used for timing, and will it only use that pin while it is taking a distance measurement, or does it keep the pin busy all the time?