FunduMoto Shield und Servo.h läuft nicht ?

Hallo Gemeinde,
ich habe ein Fundumoto Shield L298P im Einsatz um einen 12VDC Motor laufen zu lassen.
Sobald ich die Servo.h benutze, fkt. mein Motor nicht mehr ?
D.h… die Servo überlagert mit die Pin 10(Speed) und 12(Dir) ??

  #include <Servo.h>
  Servo CMServo_1;

Setup
CMServo_1.attach(O_CMServo_1);

der Aufruf im Setup killt mir die Steuerung zum Motor

Bitte um Hilfe.

(deleted)

4711:
D.h.. die Servo überlagert mit die Pin 10(Speed) und 12(Dir) ??

Ich geh mal davon aus, dass es um einen UNO geht? ( Du bist eigentlich lang genug dabei, um zu wissen welche Infos notwendig sind ).
Vermutlich stellst Du die Speed am Pin 10 per analogWrite ein. Dabei wird der Timer 1 genutzt. Den will die servo.h aber auch nutzen -> Timerkonflikt.

super, mein Beitrag wurde wieder mal nicht gespeichert… erneut >:(

  const unsigned int cuiDelay = 0; //
  // CASE FEEDER
  const unsigned int cuiCFMotorSpeedForward = 254;
  const unsigned int cuiCFMotorSpeedBackward = 254;
  const unsigned int cuiCFFaultTimeCPR = 2000; // [ms] Fehlerzeit 
  const unsigned int cuiCFTimeBackward = 1500; // [ms] Verzögerungszeit
  const unsigned int cuiCFTimeRun = 20000; // [ms] Laufzeit
  const unsigned int cuiCFTimeStandby = 10000; // [ms] Standby
  const unsigned int cuiCFTimePowerON = 5000; // [ms] Startverzögerung
  const unsigned int cuiCMShowTime = 1000; //
// ----------------------------------------------------
// GLOBALE I/O ----------------------------------------
// ----------------------------------------------------
  const unsigned int I_ON = A5; //
  // CASE FEEDER
  const unsigned int I_CFSensorPlate = A2; // 
  const unsigned int I_CFSensorCase = A3; //
  const unsigned int O_CF_Motor_Dir = 12;
  const unsigned int O_CF_Motor_Speed = 10;
  const unsigned int O_CF_Motor_Brake = 0;
  // CM -----------------------------------------------
  const unsigned int I_CMSensor1_1 = 0; // A4 Eingang vom Sensor 1 = Erkennung der Hülse
  const unsigned int I_CMSensor2_1 = 0; // A5 Eingang vom Sensor 2 = korrekte Höhe
  const unsigned int O_CMServo_1 = 0; // 9 PWM
  const unsigned int O_CMLaser1 = 0;  // 2
  const unsigned int O_CMLaser2 = 0;  // 3
// ----------------------------------------------------
// GLOBALE MERKER ------------------------------------- 
// ----------------------------------------------------
  bool bON; //     
  // CASE FEEDER
  bool bCFSensorPlate = LOW; //  
  bool bCFSensorCase = LOW; // 
  bool bCFForward = LOW; //
  bool bCFBackward = LOW; //
  bool bCFlastSensorPlateState = LOW; //
  bool bCFPlateStopped = LOW; //
  bool bCFStandBy = LOW; //
  bool bCFPowerON = LOW; //
  unsigned long uliCFErrorTimeCheckPlate = 0; //
  unsigned long uliCFTimeBackward = 0; //
  unsigned long uliCFTimeRun = 0; //
  unsigned long uliCFTimeStandby = 0; //
  unsigned long uliCFTimePowerON = 0; //
  //
  unsigned long uliCM1GoodCase = 0; //
  unsigned long uliCM1BadCase = 0; //
  unsigned long uliCM1ZHclosed = 0; //
  unsigned long uliCM2GoodCase = 0; //
  unsigned long uliCM2BadCase = 0; //
  unsigned long uliCM2ZHclosed = 0; //
  unsigned long uliCMGoodCases = 0; //
  unsigned long uliCMBadCases = 0; //
  unsigned long uliCMZHclosed = 0; //
  unsigned long uliCMShowTime = 0; //
  // ERROR
  bool bError = LOW; // Merker für Fehlerausgabe
  unsigned int uiError = 0; // Error
// ----------------------------------------------------
// Bibliotheken ---------------------------------------
// ----------------------------------------------------
  #include <Servo.h>
  Servo CMServo_1;
// ----------------------------------------------------
// INIT -----------------------------------------------
// ----------------------------------------------------
 void setup() {
  // CASE FEEDER
//  pinMode (I_CFSensorPlate, INPUT_PULLUP);
//  pinMode (I_CFSensorCase, INPUT_PULLUP);
  pinMode (O_CF_Motor_Dir, OUTPUT); 
  pinMode (O_CF_Motor_Speed, OUTPUT); 
  pinMode (O_CF_Motor_Brake, OUTPUT); 
  // Define Serial Output to display machine status ---
  Serial.begin (9600); // Datenrate 9600 bps
  while (!Serial) {;// wait for serial port to connect. Needed for native USB port only
  }
  // Servo --------------------------------------------
  // Servo --------------------------------------------
  // CMServo_1.attach(O_CMServo_1);
}
// ----------------------------------------------------
// MAIN - CODE ----------------------------------------
// ----------------------------------------------------
void loop() 
{ // INPUT / OUTPUT -----------------------------------
    if (analogRead (I_ON) > 600) { bON = LOW; }
    else { bON = HIGH; }
    // CASE FEEDER ------------------------
    if (analogRead (I_CFSensorPlate) > 600) { bCFSensorPlate = LOW; }
    else { bCFSensorPlate = HIGH; }
//    bCFSensorPlate = !digitalRead(I_CFSensorPlate);
//    Serial.print("CF_Plate_Sensor: ");Serial.println(bCFSensorPlate);
    if (analogRead (I_CFSensorCase) > 600) { bCFSensorCase = LOW; }
    else { bCFSensorCase = HIGH; }
//    bCFSensorCase = !digitalRead(I_CFSensorCase);
//    Serial.print("CF_Case_Sensor: ");Serial.println(bCFSensorCase);

    if (bCFForward) {digitalWrite (O_CF_Motor_Dir,LOW);}
    else if (bCFBackward) {digitalWrite (O_CF_Motor_Dir,HIGH);}
    if (bCFForward) {analogWrite (O_CF_Motor_Speed,cuiCFMotorSpeedForward);}
    else if (bCFBackward) {analogWrite (O_CF_Motor_Speed,cuiCFMotorSpeedBackward);}
    else {analogWrite (O_CF_Motor_Speed,0);}
    digitalWrite (O_CF_Motor_Brake,LOW);
  // --------------------------------------------------
  // ERROR --------------------------------------------
  // --------------------------------------------------
    if (uiError != 0)
     { if (!bError)
       { Serial.print("!!! ERROR : "); Serial.print(uiError); 
         Serial.println(" !!! Call your Distributor for HELP ;) ");
         bError = HIGH;
         bCFForward = LOW;
         bCFBackward = LOW;
       }
     }
  // --------------------------------------------------
  // MACHINE ------------------------------------------
  // --------------------------------------------------
    if (!bError) // && bON == HIGH)
    { CaseFeeder();
    }
    else 
    {  bCFForward = LOW;
       bCFBackward = LOW;
    }
  // --------------------------------------------------
  // INFO ---------------------------------------------
  // --------------------------------------------------
    if ((millis() - uliCMShowTime) > cuiCMShowTime)
    {
      Serial.print("I-Case: ");Serial.print(bCFSensorCase);
      Serial.print(", I-Plate: ");Serial.print(bCFSensorPlate);
      Serial.print(", O-Forward: ");Serial.print(bCFForward);
      Serial.print(", O-Backward: ");Serial.print(bCFBackward);
      Serial.print(", Error: ");Serial.println(bError);
      
      uliCMShowTime = millis();
    }
}
// ----------------------------------------------------
// CASE FEEDER ----------------------------------------
// ----------------------------------------------------
void CaseFeeder() 
{ // Power ON
  if (!bCFPowerON){ bCFPowerON = HIGH; uliCFTimePowerON = millis();}
  if ((millis() - uliCFTimePowerON) > cuiCFTimePowerON)
  {
  // Standby ------------------------------
  if (bCFSensorCase || !bCFForward)
  { uliCFTimeRun = millis();    
  }
  if (bCFForward && !bCFStandBy && (millis() - uliCFTimeRun) > cuiCFTimeRun
  && cuiCFTimeRun > 0)
  { uliCFTimeStandby = millis();
    bCFStandBy = HIGH;
    Serial.println("CF/ Standby activated");
  }
  if (bCFStandBy && (millis() - uliCFTimeStandby) > cuiCFTimeStandby)
  { bCFStandBy = LOW;  
    uliCFTimeRun = millis();  
    Serial.println("CF/ Standby deactivated");
  }
  // Rotation -----------------------------
  if (bCFBackward && ((millis() - uliCFErrorTimeCheckPlate) > cuiCFTimeBackward))
  { bCFForward = LOW; 
    bCFBackward = LOW;
    bCFPlateStopped = LOW;
  }
  if (bCFForward == LOW && bCFBackward == LOW)
  { uliCFErrorTimeCheckPlate = millis();
  }
  else if ( bCFSensorPlate != bCFlastSensorPlateState
            && bCFForward)
  { bCFPlateStopped = LOW;
    uliCFErrorTimeCheckPlate = millis();
    bCFlastSensorPlateState = bCFSensorPlate;
    Serial.println("CF/ Rotation detected");      
  }
  else if ((millis() - uliCFErrorTimeCheckPlate) > cuiCFFaultTimeCPR)
  { bCFPlateStopped = HIGH;  
    uliCFErrorTimeCheckPlate = millis();
    Serial.println("CF/ Rotation stopped");      
  }
  // Feed ---------------------------------
  if (!bCFStandBy 
      && !bCFSensorCase)
   { if (!bCFPlateStopped)
      { bCFForward = HIGH; 
        bCFBackward = LOW;
      }
      else 
      { bCFForward = LOW; 
        bCFBackward = HIGH;
      }
  }
  else {
    bCFForward = LOW;
    bCFBackward = LOW;
  }
  // Power ON
  } else
  {
    bCFForward = LOW;
    bCFBackward = LOW;    
  }
}

UNO mit Shield FunduMoto und Shield - Steckverbinder

ext. Stromversorgung auf allen Schields und UNO

4711:
super, mein Beitrag wurde wieder mal nicht gespeichert… erneut >:(

  const unsigned int cuiDelay = 0; //

// CASE FEEDER
 const unsigned int cuiCFMotorSpeedForward = 254;
 const unsigned int cuiCFMotorSpeedBackward = 254;
 const unsigned int cuiCFFaultTimeCPR = 2000; // [ms] Fehlerzeit
 const unsigned int cuiCFTimeBackward = 1500; // [ms] Verzögerungszeit
 const unsigned int cuiCFTimeRun = 20000; // [ms] Laufzeit
 const unsigned int cuiCFTimeStandby = 10000; // [ms] Standby
 const unsigned int cuiCFTimePowerON = 5000; // [ms] Startverzögerung
 const unsigned int cuiCMShowTime = 1000; //
// ----------------------------------------------------
// GLOBALE I/O ----------------------------------------
// ----------------------------------------------------
 const unsigned int I_ON = A5; //
 // CASE FEEDER
 const unsigned int I_CFSensorPlate = A2; //
 const unsigned int I_CFSensorCase = A3; //
 const unsigned int O_CF_Motor_Dir = 12;
 const unsigned int O_CF_Motor_Speed = 10;
 const unsigned int O_CF_Motor_Brake = 0;
 // CM -----------------------------------------------
 const unsigned int I_CMSensor1_1 = 0; // A4 Eingang vom Sensor 1 = Erkennung der Hülse
 const unsigned int I_CMSensor2_1 = 0; // A5 Eingang vom Sensor 2 = korrekte Höhe
 const unsigned int O_CMServo_1 = 0; // 9 PWM
 const unsigned int O_CMLaser1 = 0;  // 2
 const unsigned int O_CMLaser2 = 0;  // 3
// ----------------------------------------------------
// GLOBALE MERKER -------------------------------------
// ----------------------------------------------------
 bool bON; //    
 // CASE FEEDER
 bool bCFSensorPlate = LOW; //  
 bool bCFSensorCase = LOW; //
 bool bCFForward = LOW; //
 bool bCFBackward = LOW; //
 bool bCFlastSensorPlateState = LOW; //
 bool bCFPlateStopped = LOW; //
 bool bCFStandBy = LOW; //
 bool bCFPowerON = LOW; //
 unsigned long uliCFErrorTimeCheckPlate = 0; //
 unsigned long uliCFTimeBackward = 0; //
 unsigned long uliCFTimeRun = 0; //
 unsigned long uliCFTimeStandby = 0; //
 unsigned long uliCFTimePowerON = 0; //
 //
 unsigned long uliCM1GoodCase = 0; //
 unsigned long uliCM1BadCase = 0; //
 unsigned long uliCM1ZHclosed = 0; //
 unsigned long uliCM2GoodCase = 0; //
 unsigned long uliCM2BadCase = 0; //
 unsigned long uliCM2ZHclosed = 0; //
 unsigned long uliCMGoodCases = 0; //
 unsigned long uliCMBadCases = 0; //
 unsigned long uliCMZHclosed = 0; //
 unsigned long uliCMShowTime = 0; //
 // ERROR
 bool bError = LOW; // Merker für Fehlerausgabe
 unsigned int uiError = 0; // Error
// ----------------------------------------------------
// Bibliotheken ---------------------------------------
// ----------------------------------------------------
 #include <Servo.h>
 Servo CMServo_1;
// ----------------------------------------------------
// INIT -----------------------------------------------
// ----------------------------------------------------
void setup() {
 // CASE FEEDER
//  pinMode (I_CFSensorPlate, INPUT_PULLUP);
//  pinMode (I_CFSensorCase, INPUT_PULLUP);
 pinMode (O_CF_Motor_Dir, OUTPUT);
 pinMode (O_CF_Motor_Speed, OUTPUT);
 pinMode (O_CF_Motor_Brake, OUTPUT);
 // Define Serial Output to display machine status —
 Serial.begin (9600); // Datenrate 9600 bps
 while (!Serial) {;// wait for serial port to connect. Needed for native USB port only
 }
 // Servo --------------------------------------------
 // Servo --------------------------------------------
 // CMServo_1.attach(O_CMServo_1);
}
// ----------------------------------------------------
// MAIN - CODE ----------------------------------------
// ----------------------------------------------------
void loop()
{ // INPUT / OUTPUT -----------------------------------
   if (analogRead (I_ON) > 600) { bON = LOW; }
   else { bON = HIGH; }
   // CASE FEEDER ------------------------
   if (analogRead (I_CFSensorPlate) > 600) { bCFSensorPlate = LOW; }
   else { bCFSensorPlate = HIGH; }
//    bCFSensorPlate = !digitalRead(I_CFSensorPlate);
//    Serial.print("CF_Plate_Sensor: ");Serial.println(bCFSensorPlate);
   if (analogRead (I_CFSensorCase) > 600) { bCFSensorCase = LOW; }
   else { bCFSensorCase = HIGH; }
//    bCFSensorCase = !digitalRead(I_CFSensorCase);
//    Serial.print("CF_Case_Sensor: ");Serial.println(bCFSensorCase);

if (bCFForward) {digitalWrite (O_CF_Motor_Dir,LOW);}
   else if (bCFBackward) {digitalWrite (O_CF_Motor_Dir,HIGH);}
   if (bCFForward) {analogWrite (O_CF_Motor_Speed,cuiCFMotorSpeedForward);}
   else if (bCFBackward) {analogWrite (O_CF_Motor_Speed,cuiCFMotorSpeedBackward);}
   else {analogWrite (O_CF_Motor_Speed,0);}
   digitalWrite (O_CF_Motor_Brake,LOW);
 // --------------------------------------------------
 // ERROR --------------------------------------------
 // --------------------------------------------------
   if (uiError != 0)
    { if (!bError)
      { Serial.print("!!! ERROR : “); Serial.print(uiError);
        Serial.println(” !!! Call your Distributor for HELP :wink: ");
        bError = HIGH;
        bCFForward = LOW;
        bCFBackward = LOW;
      }
    }
 // --------------------------------------------------
 // MACHINE ------------------------------------------
 // --------------------------------------------------
   if (!bError) // && bON == HIGH)
   { CaseFeeder();
   }
   else
   {  bCFForward = LOW;
      bCFBackward = LOW;
   }
 // --------------------------------------------------
 // INFO ---------------------------------------------
 // --------------------------------------------------
   if ((millis() - uliCMShowTime) > cuiCMShowTime)
   {
     Serial.print("I-Case: “);Serial.print(bCFSensorCase);
     Serial.print(”, I-Plate: “);Serial.print(bCFSensorPlate);
     Serial.print(”, O-Forward: “);Serial.print(bCFForward);
     Serial.print(”, O-Backward: “);Serial.print(bCFBackward);
     Serial.print(”, Error: ");Serial.println(bError);
     
     uliCMShowTime = millis();
   }
}
// ----------------------------------------------------
// CASE FEEDER ----------------------------------------
// ----------------------------------------------------
void CaseFeeder()
{ // Power ON
 if (!bCFPowerON){ bCFPowerON = HIGH; uliCFTimePowerON = millis();}
 if ((millis() - uliCFTimePowerON) > cuiCFTimePowerON)
 {
 // Standby ------------------------------
 if (bCFSensorCase || !bCFForward)
 { uliCFTimeRun = millis();    
 }
 if (bCFForward && !bCFStandBy && (millis() - uliCFTimeRun) > cuiCFTimeRun
 && cuiCFTimeRun > 0)
 { uliCFTimeStandby = millis();
   bCFStandBy = HIGH;
   Serial.println(“CF/ Standby activated”);
 }
 if (bCFStandBy && (millis() - uliCFTimeStandby) > cuiCFTimeStandby)
 { bCFStandBy = LOW;  
   uliCFTimeRun = millis();  
   Serial.println(“CF/ Standby deactivated”);
 }
 // Rotation -----------------------------
 if (bCFBackward && ((millis() - uliCFErrorTimeCheckPlate) > cuiCFTimeBackward))
 { bCFForward = LOW;
   bCFBackward = LOW;
   bCFPlateStopped = LOW;
 }
 if (bCFForward == LOW && bCFBackward == LOW)
 { uliCFErrorTimeCheckPlate = millis();
 }
 else if ( bCFSensorPlate != bCFlastSensorPlateState
           && bCFForward)
 { bCFPlateStopped = LOW;
   uliCFErrorTimeCheckPlate = millis();
   bCFlastSensorPlateState = bCFSensorPlate;
   Serial.println(“CF/ Rotation detected”);      
 }
 else if ((millis() - uliCFErrorTimeCheckPlate) > cuiCFFaultTimeCPR)
 { bCFPlateStopped = HIGH;  
   uliCFErrorTimeCheckPlate = millis();
   Serial.println(“CF/ Rotation stopped”);      
 }
 // Feed ---------------------------------
 if (!bCFStandBy
     && !bCFSensorCase)
  { if (!bCFPlateStopped)
     { bCFForward = HIGH;
       bCFBackward = LOW;
     }
     else
     { bCFForward = LOW;
       bCFBackward = HIGH;
     }
 }
 else {
   bCFForward = LOW;
   bCFBackward = LOW;
 }
 // Power ON
 } else
 {
   bCFForward = LOW;
   bCFBackward = LOW;    
 }
}

im Setup ist der Servo-Aufruf auskommentiert, damit fkt. die Ansteuerung des Motors dann.
kann ich diesen “Timerkonflikt” lösen ?

und manchmal steht man sich selbst im Weg, hab jetzt den Motor an den 2. Klemmen angeschlossen und mit Pin 11/13 fkt. das Ganze jetzt.

Aber, könnte man das lösen? bei meinen älteren Anlagen hatte ich das Thema nicht.

(deleted)

4711:
UNO mit Shield FunduMoto und Shield - Steckverbinder

ext. Stromversorgung auf allen Schields und UNO

Was für ein Shield ist das ? Poste mal einen Link.
Sollte dir eigentlich bekannt sein.

wozu, hat damit nix zu tun, aber bitteschön

und noch die ext. Spannungsversorgung...

ach du meinst das Motorboard.... OK!

4711:
wozu, hat damit nix zu tun, aber bitteschön
.......

Warum hat das Shield nichts damit zu tun ?
Hast du es verbaut, oder nicht ?

4711:
ach du meinst das Motorboard… OK!

ja, genau…das meinte ich.

Allerdings wenn es jetzt funktioniert, ist doch gut.
Und mit anderen Pins ist es wohl ein Timerproblem.

4711:
und manchmal steht man sich selbst im Weg, hab jetzt den Motor an den 2. Klemmen angeschlossen und mit Pin 11/13 fkt. das Ganze jetzt.

Aber, könnte man das lösen? bei meinen älteren Anlagen hatte ich das Thema nicht.

Der UNO hat nur einen 16-Bit Timer, und den braucht die Servo-Lib nunmal. PWM an Pin 11 läuft über den Timer2 (8-Bit), deshalb funktioniert es da.
Was an deinen älteren Anlagen anders war, kann ich natürlich nicht beurteilen, aber PWM an Pin 10 gleichzeitig mit der Servo-Lib geht auf einem UNO einfach nicht .
P.S. gilt genauso für PWM an Pin 9 - das nutzt auch den Timer 1.

Naja, so sehe ich das nicht.
Bei anderen Motorboards fkt. der Pin sehrwohl.

Wie Du das so siehst ist unerheblich. In der Form wie Du den Pin nutzt geht es nicht, das ist technisch nicht möglich. Natürlich kannst Du den Pin für andere Aufgaben verwenden, aber eben nicht mit analogWrite.

Ich nutze den Pin mit anslogWrite mit anderen Motorboards und es funktioniert einwandfrei.
Also unerheblich.... wie du meinst.

Auch zusammen mit der servo.h - und auf einem UNO - also genau so wie hier?