0

GPS data to PWM/PPM output for servo using UNO board
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Mon Mar 21, 2016 11:21 am

Hi, here is a topic that I posted also to the Arduino forum. Challenge is to get UNO feeding GPS serial data to servo as PWM....

http://forum.arduino.cc/index.php?topic=387821.0

Any specialist who could help me to get this work....

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by franklin97355 on Mon Mar 21, 2016 2:56 pm

Could you give us a circuit and the entire code you are running?

franklin97355
 
Posts: 21295
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Mon Mar 21, 2016 5:52 pm

Board is Arduino UNO, GPS is connected to pins 4/3 servo signal connected to pin 2 (I have tried also other pins). Devices have common ground and Vin connected to 5V battery. The GPS works and I'm able to see the incoming data if serial monitor is on, but the serial traffic confuses the servo PWM signal somehow.
Code: Select all | TOGGLE FULL SIZE
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Servo.h>

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

SoftwareSerial ss(RXPin, TXPin);

TinyGPSPlus gps;

Servo myservo;

void setup()
{
 Serial.begin(115200);
 ss.begin(GPSBaud);
 
 myservo.attach(2);   
}

void loop()
{
   myservo.write(gps.speed.kmph());
   delay(1000);                           
}

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by adafruit_support_bill on Mon Mar 21, 2016 6:01 pm

Serial I/O uses interrupts and heavy serial traffic will cause enough interrupt contention to affect the servo pulse width timing. One solution is to use a dedicated servo driver to offload that timing from the UNO.

https://www.adafruit.com/product/1411

adafruit_support_bill
 
Posts: 74923
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Tue Mar 22, 2016 4:08 am

Ok that might be a solution but I was still hoping to get this work with software only. I understood that UNO has few (3?) timers to be used in different processes and in this case the serial traffic and PWM generation uses same timer which causes this interruption. I was wondering if the GPS input data could be handled with the soft serial library and the PWM data with the HW UART timer that the USB connection to computer normally uses. Could this work?

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by adafruit_support_bill on Tue Mar 22, 2016 6:28 am

You might gain some improvement by switching timers. There is an old variant of the Servo library somewhere that uses Timer2.

But I suspect that the issue is more fundamental than that. The Atmega328 has only one interrupt level, so regardless of the timer that you use, you can only process one interrupt at a time. If you are processing a serial byte when a timer interrupt happens, you won't be able to process the timer interrupt until you are done with the serial byte.

adafruit_support_bill
 
Posts: 74923
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Tue Mar 22, 2016 8:29 am

Yes, I have already tried ServoTimer2 library but it didn't do the trick. Hmm....this seems to be quite difficult to solve....

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Tue Mar 22, 2016 11:50 am

I was wondering if the servo could be used via analog pins A0-A5? Would that make a difference in this case?

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Sun Mar 27, 2016 8:53 am

Here is a picture of the setup:
Attachments
GPS SPEEDOMETER.png
GPS SPEEDOMETER.png (706.15 KiB) Viewed 590 times

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by adafruit_support_bill on Sun Mar 27, 2016 11:07 am

Analog pins would not make any significant difference in the timing.

Another approach would be to use an automotive gauge stepper instead of a servo: https://www.adafruit.com/products/2424
The timing is not so critical with that motor.

adafruit_support_bill
 
Posts: 74923
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Sun Mar 27, 2016 6:09 pm

Thanks for the info Bill. Yes, that could be a solution. Can I use PRODUCT ID: 2424 directly with UNO or is the stepper driver for this mandatory? If so would this driver shield also work https://www.adafruit.com/products/1438? It says it has fully-dedicated PWM driver chip on board so I presume it could run servos or stepper motor without timing problems?

Bill what is your opinion...do you think that using bare Arduino UNO for controlling servo according to serial data is almost impossible or is there still some hope that some sort of library could handle it? What is the case if the GPS is connected to the HW serial port pins 1/0? Would it make any difference?

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Re: GPS data to PWM/PPM output for servo using UNO board

by adafruit_support_bill on Mon Mar 28, 2016 6:03 am

It is possible to run the #2424 gauge via the motor shield, or with the TB6612 breakout: https://www.adafruit.com/products/2448
It is also possible to run it directly from the Arduino pins.

What is the case if the GPS is connected to the HW serial port pins 1/0? Would it make any difference?

That might improve things a little bit. The hardware serial port will have less interrupt overhead than Software Serial, so it should have slightly less impact on servo timing.

adafruit_support_bill
 
Posts: 74923
Joined: Sat Feb 07, 2009 10:11 am

Re: GPS data to PWM/PPM output for servo using UNO board

by Bertolli on Mon May 16, 2016 2:55 pm

After two months of searching and investigating I must say that for Uno board a working PWM signal output for servo simultaneously with GPS connected via serial is nearly impossible or at least extremely difficult. No working code exists as far as I know. I wouldn't waste more time for trying to solve the case anymore. Just use Mega or some other board instead.

Bertolli
 
Posts: 8
Joined: Mon Mar 21, 2016 11:15 am

Please be positive and constructive with your questions and comments.