AchimPieters / ESP8266-HomeKit-Blinds

ESP8266 - HomeKit Blinds
https://www.studiopieters.nl
MIT License
19 stars 5 forks source link

ESP8266-HomeKit-Blinds #1

Closed okanduzyel closed 4 years ago

okanduzyel commented 5 years ago

Hi,

I want to use your ESP8266-HomeKit-Blinds with step motorized blind with a4988 step motor driver https://www.pololu.com/file/0J450/a4988_DMOS_microstepping_driver_with_translator.pdf

It is very basic, has direction input and step input.

When direction is 0 and step 0-1-0-1-0-1-0-1-0-1 changes it rotates one way. When direction is 1 and step 0-1-0-1-0-1-0-1-0-1 changes it rotates another way.

Direction output is very simple. I will take it from relay_up output but I need a clk output like a %50 duty pwm.

How can I add it to your example?

okanduzyel commented 5 years ago

I have created a task like that:

I have defined that to allow clk, when blinds opening or closing, I make it "1", when reached to position, I make it "0";

int allow = 0;

then, created a task like that:

xTaskCreate(step_task, "Step Task", 256, NULL, 2, NULL);

and then, my step task like that:

void step_task(void *_args) {
    while (1) {
         if(allow == 1){
            gpio_write(relay_down, 1);
            vTaskDelay(10 / portTICK_PERIOD_MS);
            gpio_write(relay_down, 0);
            vTaskDelay(10 / portTICK_PERIOD_MS);
         else{
            vTaskDelay(20 / portTICK_PERIOD_MS);
         }      
    }
}

This is my reached max frequency of clk. if I increase clk frequency, decrease ten milliseconds of each vTaskDelay(10 / portTICK_PERIOD_MS), esp8266 can not create a clk. Signal shape destroys.

How can I create around 1khz?

okanduzyel commented 5 years ago

I have solved it with maximkulkin's pwm library.

Here it is: https://github.com/maximkulkin/esp-homekit-demo/tree/master/examples/sonoff_basic_pwm

#include <pwm.h> // include pwm library
const int pwm_gpio = 13;  //pwm pin
uint8_t pins[1]; //necessary for library

inside of gpio_init:

pins[0] = pwm_gpio; 
pwm_init(1, pins, false); 
pwm_set_freq(1000);   //frequency
pwm_set_duty(UINT16_MAX);

When do you want to create a clock pulse which is 1khz execute that code: pwm_set_duty(UINT16_MAX/2);

When do you want to stop it execute that code: pwm_set_duty(UINT16_MAX);

Your example for only DC motors. You can quickly add that codes and can make them definable on top of code. For example #define mode_dc, #define mode_step etc.

Besides, your example has a big issue, that is:

If blind is opened, electric had gone and has came again. It looks closed on homekit. There is only way to fix issue that close it by hand and use it again.

I wanted to add a opened-closed switch to recognize its position but unfortunately there is no available pin to connect esp8266. The only way, It will memorize its last position and after booting, it will realize again.

AchimPieters commented 5 years ago

Good Work!