Since I'm using a sensor that communicates with the Arduino via I2C, I'm having problems trying to use the Servo library that comes by default with Arduino IDE. I know both libraries uses the same timer (No. 1), and then I tried to find out if there is other library out there that can use other timer. Then I found ServoTimer2 library, but it didn't work. The Servo was doing the same thing but slower, making the same movement step by step.
So my question is, can the Arduino Uno (ATmega 328P) work with an I2C connection and a Servo at the same time? Does the Arduino Mega have the same issue or solve this problem?
I really want to know this before implementing a board with 2 ATmegas 328P in the worst case. So, one of them can control a DC motor plus a Servo, and the other one process the information that the sensor is giving. Finally, I can comunicate them via UART.
Hi Paul, thanks for your kind answer. Sorry for not being specific. I want my servo to make a movement to an angle, so for the same thing I mean it was going crazy. In my code I'm telling the servo to make an angle, but it was doing the angle and a second later it was making another angle, and then it was making the same angle as before. So when I was using ServoTimer2 it was doing this too, but slower. Like step by step. Sorry for my bad english. And well, I'm correcting my first question. Can they work together without any problem as the one I'm getting? Because I know it is working, but not as I'm specting. Do you recommend using 2 ATmegas 328P for better performance, since the Mega have the same issue?
Can you post your code? You should be able to move the servo to a position, and have it stay there, using either Servo or ServoTimer2. If Servo interferes, because of re-purposing a timer, then ServoTimer2 can be used, and should behave the same as Servo.
The thing here is, it changes angle as I said before but step by step. For example, if I want it to be 90 degrees, it goes from 90 to 50 everytime, but step by step.
while (GPSData.available()>0){
GPS.encode(GPSData.read());
}
The encode() method returns a value of true (the last character completed a sentence) or false (the last character was not the last character in a sentence). Why are you ignoring that value?
Why are complat and complon arrays, when you only use the first element of each?
I only see where you write a position to the servo in one place. I do not see that you wait anywhere for the servo to get to that position. I do not see where you call the ServoTimer2::refresh() method anywhere.
Did you look at the examples that came with the ServoTimer2 library?
To get TinyGPS++ to work, I have to repeatedly funnel the characters to it from the GPS module using the encode() method. I'm not ignoring this value, I'm calling later the GPS object to collect the information from it.
My project it's not done yet, so I have an array to get different destinations, that's why I'm just using one. But the final project it will accept maximum 50 directions.
And yeah, you're right. I didn't add the refresh method after I made the changes. My bad, I will work on it and post my results later this night. Thank you Paul.
Hi Paul, you can read the documentation of TinyGPS, don't know why the said it's needed the encode method. On the other hand, I've been reading a lot documentation, and seems like the Software Serial Library uses timer 2 too. So I don't know if I can use another timer (seems like not). So, having two microcontrollers doesn't sound pretty crazy right now. What do you think? Any recommendations?