Ethernetshield W5100

Hi,

I wish to use the W5100 shield.
I can control 2 LED's.
When I wish to use the program to control a stepper motor, I get only one step.
Where is the problem?

//for use with W5100 based ethernet shields
 
#include <SPI.h>
#include <Ethernet.h>
#include <CustomStepper.h>
 
// was in the basiccode
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
CustomStepper stepper(5, 6, 7, 8, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 8, 4096, CW);
boolean rotate1 = false;
boolean rotatedeg = false;
boolean crotate = false;
int Wup = 0;
int Wdown = 0;
int Wstp = 0;
// pushbutton up on 9
#define up  9
// pushbutton down on 11
#define down  11
// pushbutton stp on 12
#define stp  12
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 10, 177 }; // ip in lan
byte gateway[] = { 192, 168, 10, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
int cntl = 0 ;
int white = 2 ;
int red = 3 ;
String readString;
 
//////////////////////
 
void setup(){
 
  pinMode(up, INPUT); 
  pinMode(down, INPUT); 
  pinMode(stp, INPUT); 
  
  stepper.setRPM(16);
  //sets the Steps Per Rotation, in this case it is 64 * the 283712/4455 annoying ger ratio
  //for my motor (it works with float to be able to deal with these non-integer gear ratios)
  stepper.setSPR(4096);
  
  pinMode(white, OUTPUT); //pin selected to control LED white
  pinMode(red, OUTPUT); //pin selected to control LED red
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  //the pin for the servo co
  //enable serial data print
  Serial.begin(9600);
  Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}
 
void loop(){
  // Create a client connection
  Serial.println ("cntl=");
  Serial.println (cntl);
  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("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />");
          client.println("<TITLE>Home Automation</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");
          client.println("<H1>Home Automation</H1>");
          client.println("<hr />");
          client.println("
");
         
          client.println("<a href=\"/?lightwon\"\">White light on</a>");
          client.println("<a href=\"/?lightwoff\"\">White light off</a>
");        
          client.println("
");
         
          client.println("<a href=\"/?lightron\"\">Red light on</a>");
          client.println("<a href=\"/?lightroff\"\">Red light off</a>
");        
 
          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);
          //stopping client
          client.stop();
 
          ///////////////////// control arduino pin
          if(readString.indexOf("?lightwon") >0)//checks for on
          {
            digitalWrite(white, HIGH);    // set pin 6 high
            Serial.println("Led White On");
            cntl = 1 ;
            Serial.println("here I pass ....");
            stepper.setDirection (CW) ;
            stepper.rotate(2);
          }
          else{
          if(readString.indexOf("?lightwoff") >0)//checks for off
          {
            digitalWrite(white, LOW);    // set pin 6 low
            Serial.println("Led White Off");
            cntl = 0 ;
          }
          }
          if(readString.indexOf("?lightron") >0)//checks for on
          {
            digitalWrite(red, HIGH);    // set pin 7 high
            Serial.println("Led Red On");
            cntl = 2 ;
          }
          else{
          if(readString.indexOf("?lightroff") >0)//checks for off
          {
            digitalWrite(red, LOW);    // set pin 7 low
            Serial.println("Led Red Off");
            cntl = 0 ;
          }
          }
          //clearing string for next read
          readString="";
        }
// if (cntl == 1 ) {
//   Serial.println("here I pass");
//   stepper.setDirection (CW) ;
//   stepper.rotate();
//   delay(500);
// }
      }
    }
  }
stepper.run();
}

I don't know if this is your problem, but it will cause connection problems. You are missing a parameter to the begin call.

  // change this
  Ethernet.begin(mac, ip, gateway, subnet);
  // to this
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

The first gateway is actually a placeholder for the dns server ip.

Thanks for the reply.
I have changed.
The motor still give 1 step.
The LED's are working through a webpage.
I want, when I choose 'White light on', that the stepper is rotating. Now I got 1 step =(

CustomStepper stepper(5, 6, 7, 8, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 8, 4096, CW);

I'm surprised that this even compiles. Define the array correctly, and pass the array to the constructor.

          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>");

Regardless of what the client asked for, send the same response. Why?

            stepper.rotate(2);

How many steps is this supposed to cause the stepper to take?

A link to the non-standard library would be useful.

Hi,

I have made the program for the motorcontrol with pushbuttons and everyting worked fine.
I have made a program for LED control, webbased, and everyting worked fine
But the combination of the two programs don't work.

Rotate (2) means Two revolutions and that is 4096 x 2 = 8192 steps.

When I execute the program , the result is 1 step =(

How can I solve, so the stepper steps more than 1 step...
(see also 28byj-48 with ethernet? - Motors, Mechanics, Power and CNC - Arduino Forum )

If this is an Uno, you will have problems with these.

// pushbutton down on 11
#define down  11
// pushbutton stp on 12
#define stp  12

D11 and D12 are SPI data lines. The w5100 is SPI. You can't use D10 to D13 for anything but SPI on an Uno.

I have disabled the pins but nothing is changed
I'll be mad ]:slight_smile:

I have disabled the pins but nothing is changed

You shouldn't be disabling the pins, whatever that means. You need to just stop using them for other than SPI purposes. Post your current code!

//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually DOES NOT WORK.
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605
 
#include <SPI.h>
#include <Ethernet.h>
#include <CustomStepper.h>
 
// was in the basiccode
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
CustomStepper stepper(5, 6, 7, 8, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 8, 4096, CW);
boolean rotate1 = false;
boolean rotatedeg = false;
boolean crotate = false;
int Wup = 0;
int Wdown = 0;
int Wstp = 0;
// pushbutton up on 9
//#define up  9
// pushbutton down on 11
//#define down  11
// pushbutton stp on 12
//#define stp  12
 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 10, 177 }; // ip in lan
byte gateway[] = { 192, 168, 10, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
int cntl = 0 ;
int white = 2 ;
int red = 3 ;
String readString;
 
//////////////////////
 
void setup(){
 
 // pinMode(up, INPUT); 
 // pinMode(down, INPUT); 
 // pinMode(stp, INPUT); 
  
  stepper.setRPM(16);
  //sets the Steps Per Rotation, in this case it is 64 * the 283712/4455 annoying ger ratio
  //for my motor (it works with float to be able to deal with these non-integer gear ratios)
  stepper.setSPR(4096);
  
  pinMode(white, OUTPUT); //pin selected to control LED white
  pinMode(red, OUTPUT); //pin selected to control LED red
  //start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  //the pin for the servo co
  //enable serial data print
  Serial.begin(9600);
  Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}
 
void loop(){
  // Create a client connection
  Serial.println ("cntl=");
  Serial.println (cntl);
  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("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />");
          client.println("<TITLE>Home Automation</TITLE>");
          client.println("</HEAD>");
          client.println("<BODY>");
          client.println("<H1>Home Automation</H1>");
          client.println("<hr />");
          client.println("
");
         
          client.println("<a href=\"/?lightwon\"\">White light on</a>");
          client.println("<a href=\"/?lightwoff\"\">White light off</a>
");        
          client.println("
");
         
          client.println("<a href=\"/?lightron\"\">Red light on</a>");
          client.println("<a href=\"/?lightroff\"\">Red light off</a>
");        
 
          client.println("</BODY>");
          client.println("</HTML>");
 
          delay(1);
          //stopping client
          client.stop();
 
          ///////////////////// control arduino pin
          if(readString.indexOf("?lightwon") >0)//checks for on
          {
            digitalWrite(white, HIGH);    // set pin 6 high
            Serial.println("Led White On");
            cntl = 1 ;
            Serial.println("here I pass ....");
            stepper.setDirection (CW) ;
            stepper.rotate(2);
          }
          else{
          if(readString.indexOf("?lightwoff") >0)//checks for off
          {
            digitalWrite(white, LOW);    // set pin 6 low
            Serial.println("Led White Off");
            cntl = 0 ;
          }
          }
          if(readString.indexOf("?lightron") >0)//checks for on
          {
            digitalWrite(red, HIGH);    // set pin 7 high
            Serial.println("Led Red On");
            cntl = 2 ;
          }
          else{
          if(readString.indexOf("?lightroff") >0)//checks for off
          {
            digitalWrite(red, LOW);    // set pin 7 low
            Serial.println("Led Red Off");
            cntl = 0 ;
          }
          }
          //clearing string for next read
          readString="";
        }
// if (cntl == 1 ) {
//   Serial.println("here I pass");
//   stepper.setDirection (CW) ;
//   stepper.rotate();
//   delay(500);
// }
      }
    }
  }
stepper.run();
}

What is the indication of the fail? Does it just not rotate the stepper as far as expected? Does it freeze? Does it display the webpage again? What does it display on the serial monitor?

You are still using the incorrect Ethernet.begin() call.

I would like, when I press the button on the webpage, that the stepper rotate until I press on the other button on the web page.
Now, if I press the steppermotor do 1 step. When I press another time, the motor rotate 1 step......
(there are 4096 steps in 1 rotation)
It's make me mad, pfff

I would like, when I press the button on the webpage, that the stepper rotate until I press on the other button on the web page.

What is the problem? When the GET request indicates that the stepper should start stepping, start it stepping.

Then, independently, check if the stepper needs to step again. That part has nothing to do with the client making a request.

I'd get the stepper motor operating as desired using commands via the serial monitor first. Then you should be able to use the same commands via a web page GET request.