The following code is correct in original Arduino.I can control my motor in this way. But it cannot work in UDOO arduino. #include <Servo.h> #include <servo_mqx.h> Servo myservo; void setup() { Serial.beigin(115200); myservo.attach(9); } void loop() { myservo.writeMicroseconds(1700); } ----------------------- Then I just modified the loop() as: void loop() { myservo.writeMicroseconds(1700); Serial.println(myservo.attach(9)); } ----------------------- And the motor works... It makes me very confused.Is there anyone can help me to figure out why this illogical way can solve my problem??? Thank you very much!
On what Udoobuntu version are you working? If have no Neo close by at the moment but why include servo_mqx.h ? Did you try the original example that uses myservo.write instead of myservo.writeMicroseconds? It could be just a bug in the servo library, it is modified for the Neo. Code: /* Sweep by BARRAGAN <http://barraganstudio.com> This example code is in the public domain. modified 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Sweep */ #include <Servo.h> Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop() { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }
Did you solve your issue? Adding a serial.println() will slow down your sketch if you don't read the serial device from A9 so your workaround is not really functional unfortunately.
Found the problem and fried a servo in the meantime There is an error in the servo library in /usr/share/arduino/hardware/UDOO/solox/libraries/Servo/Servo.h The following declarations are wrong: Code: #define MIN_PULSE_WIDTH 544ul // the shortest pulse sent to a servo #define MAX_PULSE_WIDTH 2400ul // the longest pulse sent to a servo #define DEFAULT_PULSE_WIDTH 1500ul // default pulse width when servo is attached Should be: Code: #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached In a Linux terminal do: sudo leafpad open the servo.h file and edit the lines save. If you recompile it works. At least when i connect a led to the pin I lights up and it lights better if the value is higher. Also the Sweep example works now. It would hang my Neo. What I also learned is that I should use myservo.attach(9, 1000, 2000); as 2000 is the highest it should get. I don't know what signal my servo got first with the Sweep example but it did one movement, got really hot and died. :-( It was a cheap one so don't worry. @Andrea Rovai Could you arrange that this is fixed in the arduino-board manager repository?
Hi Andrea, When you say "Done and in the repository it's fixed." Do we get it with sudo apt-get update and apt-get upgrade? If not, how do we get it? Thanks, -Jack