Arduino motor shield und ethernet shield

Hallo,

Ich hab ein Arduino Uno rev3, Ethernet Shield und Motor Shield von Arduino. Ich kann beide Shields problemlos kontrollieren, aber beides zusammen funkioniert nicht. Der Schrittmotor (nema 14 bipolar) ruckelt, aber das war es auch. Die B+ Led am Motor Shield leuchtet auch nie auf, im Gegensatz zu den anderen.
Bin schon langsam am verzweifeln. Kann mir jemand sagen, wo mein Fehler im Code ist?

/*
 Created by Rui Santos
 Visit: http://randomnerdtutorials.com for more arduino projects

 Arduino with Ethernet Shield
 */

#include <SPI.h>
#include <Ethernet.h>




byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x2A, 0x25 };  //physical mac address
byte ip[] = { 10, 0, 1, 196 };                     // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
EthernetServer server(80);                             //server port     
String readString;

                    #define DirA  12
                    #define DirB  13
                    #define BrakeA  9
                    #define BrakeB  8
                    #define PWMA  3
                    #define PWMB  11
                    
                    int delaylegnth = 1000;


void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
    
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());


                        pinMode(DirA, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
                        pinMode(DirB, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???
                        
                        //establish motor brake pins
                        pinMode(BrakeA, OUTPUT); //brake (disable) CH A
                        pinMode(BrakeB, OUTPUT); //brake (disable) CH B


}


void loop() {
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {   
      if (client.available()) {
        char c = client.read();
     
        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
         }

         //if HTTP request has ended
         if (c == '\n') {          
           Serial.println(readString); //print to serial monitor for debuging
     
           client.println("HTTP/1.1 200 OK"); //send new page
           client.println("Content-Type: text/html");
           client.println();     
           client.println("<HTML>");
           client.println("<HEAD>");
           client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
           client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
           client.println("<TITLE>Stepper Control</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>Stepper Control</H1>");
           client.println("<hr />");
           client.println("
");  
           client.println("
");  
           client.println("<a href=\"/?button1on\"\">ON</a>");
           client.println("<a href=\"/?button1off\"\">OFF</a>
"); 
           client.println("
"); 
           client.println("</BODY>");
           client.println("</HTML>");
     
           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           
           if (readString.indexOf("?button1on") >0){
                for(int stepp = 0; stepp < 200; stepp++)  
                { 

                                digitalWrite(BrakeA, LOW);  //ENABLE CH A
                                digitalWrite(BrakeB, HIGH); //DISABLE CH B
                              
                                digitalWrite(DirA, HIGH);   //Sets direction of CH A
                                analogWrite(PWMA, 255);   //Moves CH A
                                
                                delay(delaylegnth);
                                
                                digitalWrite(BrakeA, HIGH);  //DISABLE CH A
                                digitalWrite(BrakeB, LOW); //ENABLE CH B
                              
                                digitalWrite(DirB, LOW);   //Sets direction of CH B
                                analogWrite(PWMB, 255);   //Moves CH B
                                
                                delay(delaylegnth);
                                
                                digitalWrite(BrakeA, LOW);  //ENABLE CH A
                                digitalWrite(BrakeB, HIGH); //DISABLE CH B
                              
                                digitalWrite(DirA, LOW);   //Sets direction of CH A
                                analogWrite(PWMA, 255);   //Moves CH A
                                
                                delay(delaylegnth);
                                  
                                digitalWrite(BrakeA, HIGH);  //DISABLE CH A
                                digitalWrite(BrakeB, LOW); //ENABLE CH B
                              
                                digitalWrite(DirB, HIGH);   //Sets direction of CH B
                                analogWrite(PWMB, 255);   //Moves CH B
                                
                                delay(delaylegnth);                  
                  
                } 
           }
           if (readString.indexOf("?button1off") >0){
                    
                                           
                                
                   
           }
            //clearing string for next read
            readString="";  
           
         }
       }
    }
}
}

Vielen Dank
Harald

Die beiden Shields können nicht gemeinsam benutzt werden, da beide Gebrauch von den Pins 11, 12 und 13 machen. Beim Ethernet Shield für den SPI-Bus, beim Motor Shield für Drehrichtung (12, 13) bzw. PWM (11).

Danke für die Antwort.

Die Arduino Seite sagt aber, dass nur pin4 und pin 10 nicht benutzt werden können?!?

13, 12, und 11 sind der SPI Bus. Dazu braucht es noch ein Pin der das Device selektiert und das sind 10 für des Etehrnet Chip und 4 für die SD-Karte.

Auszug aus der Beschreibung:

Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card.

Grüße Uwe

Verstehe, aber ich könnte über ein breadboard die pins 5, 6, 7 vom uno zum 11, 12, 13 vom motorshield jumpern und dann sollte alles funktionieren, oder?

Vielen dank für die Hilfe und Entschuldigung für die blöden Fragen. Bin erst am Anfang meiner Microcontroller-Karriere. :slight_smile:

Ja, Du kannst das Motor-Shield über Kabel anschließen. Eine sichere Verbindung ist das aber nur bedingt.

Grüße Uwe

Danke für die Antwort. Werd ich mal versuchen