Roborock door with homeyduino ESP8266, L298N and Nema 17

Hello.
I am currently making an automated garage door for my max v6 roborock under the kitchen cabinets
I am very close but something is wrong with the code I believe.
I am using esp8266, L298N driver and a Nema 17 stepper motor.
I implement to Homey by using the Homeyduino -

include <Homey.h>

I paired it to Homey and it showes up witouht problems.
But, the motor does not behave as it should. It vibrates and tries, but dosent turn as it should.
As I am not that good at coding I hoped someone could take a look at the code and maybe see what is wrong.
I have followed this description as the hardware and wirering goes…

This is the code I used:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Homey.h>

unsigned long previousMillis = 0;
const unsigned long interval = 2000; //Interval in milliseconds for reading setpoint from Homey

#include <Stepper.h>
#define stepsPerRevolution 2040
Stepper stepper(stepsPerRevolution, 5, 14, 12, 4); //This are PIN D1 D5 D6 D2 on the ESP8266

int Relais = 13; //PIN D7 on ESP8266 Relay for put on and off stepper motor

float PositionFloat = 0; //Setpoint from Homey

int steps1; //Stepcounter
int stepsHomey; //Setpoint from Homey changed to stepper total

void wifi() { //This loop is for connecting to WiFi
if (WiFi.status() != WL_CONNECTED) {
Serial.print(“Connecting with WiFi “);
WiFi.begin(“xxxxxxxxx”, “xxxxxxxx”);
uint8_t timeout = 30;
while (WiFi.status() != WL_CONNECTED) {
delay(500); Serial.print(”.”);
if (timeout<1) break;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println(" ");
Serial.println(“Connected to WiFi!”);
}
}
}

void setup() {
Serial.begin(9600);
Homey.begin(“VacuumRobotDoor”); //The name of your project, every project needs another name!
Homey.setClass(“blinds”); //Put here the device class, in this case Blinds
Homey.addCapability(“windowcoverings_set”, ValHomey); //Put here the capability
Homey.setCapabilityValue(“windowcoverings_set”, ValHomey);
steps1 = 0;
}

void loop() {
Homey.loop();
wifi();
steppert();
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
ValHomey ();
}
}

void steppert(){
stepsHomey = (PositionFloat * 9180); //[9180] Is the total ammount of steps wich i need to be taken
if (stepsHomey != steps1){ //To activate relais before steps will be made!
digitalWrite (Relais, HIGH); //Relay activated
}

if (stepsHomey == steps1){ //To deactivate relais before when stepper motor is not in use
digitalWrite (Relais, LOW); //Relay not activated
}

if (stepsHomey > steps1){ //Circuit for turning CW
stepper.setSpeed(14); //Stepper speed
stepper.step(1); //Steps per time
steps1++; //Stepcounter
}

if (stepsHomey < steps1){ //Circuit for turning CCW
stepper.setSpeed(14); //Stepper speed
stepper.step(-1); //Steps per time
steps1–; //Stepcounter
}
}

void ValHomey (){
PositionFloat = Homey.value.toFloat(); //number 0.00 - 1.00
Serial.print ("Setpoint from the Homey: "); Serial.println(stepsHomey);
Serial.print ("Actual position of the steppermotor: "); Serial.println(steps1);
}

And here is the mechanism I am printing at work in a few days…

Trouble shoot your code without the intergration with homeyduino/homey.

Google is your best friend for this kind of projects…. https://lastminuteengineers.com/stepper-motor-l298n-arduino-tutorial/

1 Like

Thank you. I will have a look this weekend to see if I can solved it. :slight_smile: