David
Sketch uses 5774 bytes (17%) of program storage space. Maximum is 32256 bytes.
Global variables use 431 bytes (21%) of dynamic memory, leaving 1617 bytes for local variables. Maximum is 2048 bytes.
The sketch seems to compile ok, but :
Using Port : COM3
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
the upload has an issue.
Can you try another USB cable and/or another USB port on your PC ?
Eric
Thanks Eric. I've gone back to basics and using the same Arduino, the same USB cable and the same port, another sketch loads ok. The is a very simple sketch to centre a servo. The error only happens when I include Serial.print in my sketch and the only reason for doing that was to determine that a particular pin was HIGH or LOW. And here's me thinking I was starting to understand - lol!
/* Arduino Servo Test sketch */ #include <Servo.h> Servo servoMain; // Define our Servo void setup() { servoMain.attach(10); // servo on digital pin 10 } void loop() { //servoMain.write(45); // Turn Servo Left to 45 degrees //delay(1000); // Wait 1 second //servoMain.write(0); // Turn Servo Left to 0 degrees //delay(1000); // Wait 1 second servoMain.write(90); // Turn Servo back to center position (90 degrees) delay(10000); // Wait 10 second // servoMain.write(135); // Turn Servo Right to 135 degrees //delay(1000); // Wait 1 second servoMain.write(180); // Turn Servo Right to 180 degrees delay(1000); // Wait 1 second //servoMain.write(90); // Turn Servo back to center position (90 degrees) //delay(1000); // Wait 1 second }
David
Oh then maybe you had a program connected to your COM port while trying to upload ? (or the SerialMonitor ? )
Eric
David
No another program but possibly the serial monitor. Do you mean that the serial monitor can't be active when you upload a sketch to the board that has the serial monitor in it?
David
You're right. I've made sure the serial monitor wasn't active and removed the // to include the Serial.print lines and it up loaded! Yay! Something new I've learnt.
David
Usually the serial monitor does not "lock" the port (actually it temporarily releases it) since it is controlled from the same main process (Arduino IDE) that launches avrdude for the actual upload.
But I had sometimes the issue nevertheless (mostly when I had multiple Arduino IDEs running)
So when that happens, I close all my IDEs, disconnect the board from USB, and restart the process...
Eric
Thanks. Sorta like closing Windows and starting again. Now all I need to do is figure out how to slow the movement of the servo horn.
David
It may be overkill, but you can have a look at ServoEasing (compatible with PCA9685), or another easing library :
Eric
Thanks I'll have a look. I've been thinking along the lines of the map command which can change the angle I want to the pulse the PWM needs. I just need to figure out how to fit it into each switchState evaluation.
David
If you want to do it without other libraries, I guess the issue will be "not to block" the loop() while moving a servo (which the commented for loops in your code would do), making the script unresponsive until the servo movement is finished.
That would probably mean managing the current vs. target angle/PWM value per servo, and using the millis() function to manage timed increments/decrements, one step per loop().
Eric
I think that's what I'm thinking of but you've put it into words ? - lol
David
I don't know if this is your problem, but just a thought.
In your code, I don't see a delay of any sort (built in or otherwise), and you're calling the Serial.print statements directly after a PWM servo move operation.
As the operation may not have actually completed it's operation yet, perhaps this might also be a problem why the communications port is not ready?
Is that why there was a delay(30) there? I thought it was superfluous so removed it. But it was there when I was having the problem. It's in the void (setup).
David