I can get the step motor to work, but when I change the stepsPerRevolution to a higher amount, the motor just vibrates, dosen't turn. Any ideas?
// Libraries
#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <Stepper.h>
#define wifi_ssid ""
#define wifi_password ""
#define mqtt_server "192.168.1.8"
#define mqtt_user ""
#define mqtt_password ""
#define ptopic "/home"
#define ppayload ".=yes"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
WiFiClient espClient;
PubSubClient client(espClient);
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
int status_testing = 0;
Stepper myStepper(stepsPerRevolution, D5, D6, D7, D8);
char message_buff[100];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
client.subscribe("/hello");
}
// Closes curtains full amount
void closeCurtainsFull() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
}
// Opens curtains full amount
void openCurtainsFull(){
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
int i=0;
for (i=0;i<length;i++) {
Serial.print((char)payload*);*
message_buff = payload*;*
* }*
* String msgString = String(message_buff);
_ if (msgString.equals("OFF")) {
client.publish("/home/ok","acknowedging OFF");
closeCurtainsFull();
}
else if(msgString.equals("ON")){
client.publish("/home/ok","acknowedging ON");
openCurtainsFull();
}
Serial.println();
}
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network*
* Serial.println();
Serial.print("Connecting to ");_
Serial.println(wifi_ssid);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
_ delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
//Recounted*
void reconnect() {
* // Loop until we're reconnected*
* while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect*
* if (client.connect("arduinoClient")) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("openhab","himitsu sensor, reporting in");
// ... and resubscribe*
* client.subscribe("openhab/himitsu/command");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying*
* delay(5000);
}
}
}*_
void loop(){
if (!client.connected()) {
* reconnect();*
* }*
* client.loop();*
}