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