sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
231 stars 124 forks source link

Using the Blinds Example with a Stepper Motor #68

Closed Dragontamer333 closed 4 years ago

Dragontamer333 commented 4 years ago

So I have a general understanding of how stepper motors work with they alternate sets of magnets, and each alternation is a step. So By having an input of a number of steps it will turn that many steps/degrees. How would I use that ideology to make the blinds turn only a percentage of a completely open blinds. Open is 100 % and that equates to 100 steps, but how would it be done with the code to close the blinds to 70%.

kakopappa commented 4 years ago

Do you know how many steps you need to open or close the blinds fully?

On Sun, 31 May 2020 at 5:02 AM Dragontamer333 notifications@github.com wrote:

So I have a general understanding of how stepper motors work with they alternate sets of magnets, and each alternation is a step. So By having an input of a number of steps it will turn that many steps/degrees. How would I use that ideology to make the blinds turn only a percentage of a completely open blinds. Open is 100 % and that equates to 100 steps, but how would it be done with the code to close the blinds to 70%.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sinricpro/esp8266-esp32-sdk/issues/68, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZAZZXPITP6GGI3IENB2ULRUF67ZANCNFSM4NO327SA .

Dragontamer333 commented 4 years ago

No I do not. Does that matter? I'm not in a situation where I can know the number of steps, but I'm just trying to get the code to work and will test it out later.

kakopappa commented 4 years ago

To be honest, I have not implemented blinds with Motor control so I am just guessing here.

  1. Try to get the code working (without the Sinric Pro) integration using a library like this https://github.com/Stan-Reifel/FlexyStepper

  2. Open or Close needs different calculations and you need to keep a track of what's the current position in order to calculate the difference and move

Check out these examples. It might help you to get an idea. https://github.com/intive/patronage20-embedded/blob/e6a358c3bb3491f4fc8ed22fdd78ff7f2f7987cd/substations/01_BlindsController/01_BlindsController.ino https://github.com/intive/patronage20-embedded/blob/e6a358c3bb3491f4fc8ed22fdd78ff7f2f7987cd/libraries/BlindsController/blinds.h

https://github.com/Enygma2002/arduino-projects/blob/1f239c2428648e04947026f3d2aff9aa2bb970fd/AutomaticWindowBlinds/AutomaticWindowBlinds.ino

https://github.com/chuartdo/SolarBatterySwitch/blob/34d94802cae0e4028f885eed274ef68bad917977/BlindsMotor.ino

sivar2311 commented 4 years ago

Hi Dragontamer! Your question is very interesting, and much more complicated than the first glance thinks.

The first thing you need to know in advance is how many steps the motor has to take for the entire distance. This depends on the installation and must be calculated in advance.

The sketch must know the current position at all times. A stepper motor does not know this. Here you can use limit switches (End-Stops) on one or both sides. As soon as one of these switches is triggered, you will know the exact position (100% or 0%). If the position is unknown (e.g. when booting the ESP) you have to move to one of these positions until the limit switch is triggered (homing).

To implement the motor control I would proceed as follows: 1) Defining variables

2) Implementation of a function doStep to control the motor. This function checks if the variable stepsToDo is not equal to 0. If stepsToDo is greater than 0 a step is made in the positive direction and stepsToDo and currentPosition is increased by 1. If stepsToDo is less than 0 a step is made in the negative direction and stepsToDo and currentPosition is decreased by 1. 3) Call doSteps inside the loop function Everytime loop is called and there are steps to do, one step will be done.

4) SinricPro onSetPosition and onAdjustPosition In these functions, you must convert percentages of the variable position / positionDelta into the number of steps required and enter them in the variable stepsToDo. The rest is then processed by the function doStep

Extension: As soon as the function doStep has processed all steps, you can send the event sendPositionEvent and the current position (as percentage value) to the SinricPro server.

Dragontamer333 commented 4 years ago

Ok, thanks everyone for your help. I'm waiting on my stepper motors now, so I'll have to test your suggestions out when I get them.

erdemfirat commented 2 years ago

Guys I really need your help I am stuck:( anybody did it ?

sivar2311 commented 2 years ago

This issue is over 2 years old. You will find a stepper motor sketch in #208