Guten Tag liebes ArduinoVolk!
Wir haben ein Problem ... Wir haben nun ein stehendes Progamm welches einen kleinen Servo (Vilros SG90 Micro Serve 9g) bei Tastendruck (Taster1) in einer Wiederholung laufen lässt und mit einem Tastendruck (Taster2) dies beendet und anschließend in eine Ausgangsstellung fährt.
Nun benötigen wir aber für unser Projekt einen stärkeren Servo. Daher haben wir uns bei Amazon den Carson Model Sport (Reflex Racing Servo) (http://www.amazon.de/Carson-500502015-CS-3-Servo-3KG/dp/B0037Y93CW/ref=pd_sim_21_1?ie=UTF8&refRID=0PZP3C6ZNC82H18F3Z7H ) bestellt.
Der Beschreibung zu entnehmen ist, dass dieser Servo mit einer Spannung von 5V (Arduino Uno) betrieben werden kann.
Nun ist aber das Problem das während der kleine Servo dieses Programm fröhlich und munter abspielt, zuckt der große ein paar mal rum ( Dreht sich vielleicht 2-3° in einzelnen Schritten)
Woran kann dies alles liegen ?
Anbei schreibe ich den ProgrammCode und die Ausgabe des Monitors rein:
#include <Servo.h>
#define BUTTONMODE INPUT // use INPUT or INPUT_PULLUP
#define NUMBUTTONS 2
const byte buttonPins[NUMBUTTONS]= {2,3};
byte buttonState[NUMBUTTONS];
byte buttonPressed[NUMBUTTONS];
Servo myServo;
boolean servoActive;
unsigned long servoActiveSince;
int servoPos=0;
void input()
{
memset(buttonPressed,0,sizeof(buttonPressed)); // clear buttonPressed array
for (int i=0;i<NUMBUTTONS;i++)
{
byte currentState=digitalRead(buttonPins[i]);
if (BUTTONMODE==INPUT) currentState=!currentState; // inverted logic with INPUT_PULLUP
if (currentState && !buttonState[i]) buttonPressed[i]=true;
buttonState[i]=currentState;
}
}
void processing()
{
if (buttonPressed[0]) // first button is pressed ==> activate Servo
{
Serial.println("Button pressed - Servo active");
servoActive=true;
servoActiveSince=millis();
servoPos=0;
}
if (buttonPressed[1]) // second button pressed ==> abort / deactivate Servo
{
Serial.println("Cancel Button pressed");
servoActive=false;
servoPos=0;
}
if (servoActive) // servo is currently active with rotating
{
long activeTime=millis()-servoActiveSince;
#define DURATION 5000
activeTime= activeTime%DURATION; // modulo arithmetik: activeTime alsways starts from 0 and counts up
servoPos= 180*activeTime/DURATION; // rotate as time goes by
}
else servoPos=00; // servo not active
}
void output()
{
static int oldServoPos=-1;
if (servoPos==oldServoPos) return;
oldServoPos= servoPos;
myServo.write(servoPos);
Serial.println(servoPos);
}
void setup() {
Serial.begin(9600);
Serial.println("Good night and good luck!");
for (int i=0;i<NUMBUTTONS;i++)
{
pinMode(buttonPins[i], BUTTONMODE);
}
myServo.attach(9);
}
void loop() { // round-robin-scheduling of three tasks: input, processing, output
input();
processing();
output();
delay(5); // kleines Delay zur Verhinderung von Tasterprellen
}
}
Jetzt kommt die MonitorAusgabe wie sie sein sollte ( mit angeschlossenem kleinen Servo )
Gok!
Button pressed - Servo active
Cancel Button pressed
0
Good night and good luck!
Button pressed - Servo active
Cancel Button pressed
0
Button pressed - Servo active
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Cancel Button pressed
0
Sobald der große Servo dran ist... Habe ich keinen Zugriff mehr auf das Arduino Uno Board.....
Woran liegt das alles?