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
234 stars 124 forks source link

Trying to wire up motor encoder with dc motor #323

Closed tmand54 closed 1 year ago

sivar2311 commented 1 year ago

Hi @tmand54 ! I don't understand the question about the encoder in relation to SinricPro. What do you want SinricPro to do with your encoder? Can you describe your project in more detail?

sivar2311 commented 1 year ago

You are using stepper motors in your project. Therefore, the number of steps taken is known to you exactly and does not have to be reported back by an additional (rotary?)encoder. The number of steps made can be determined by simply counting the HIGH / LOW outputs.

It would be better to use a mechanical or optical limit switch that tells you exactly when the limit is reached and the blind is in a defined start or end position.

If you know the number of steps for the required distance, you could also use a custom device in SinricPro that uses a RangeController. There you can specify the number of maximum steps or a length. If you use a length specification, your Sketch would only have to convert this into motor steps.

sivar2311 commented 1 year ago

Now I understand. So you are not using stepper motors.

But if I read your original code correctly, it does not implement the behaviour you want (1000 steps per direction). Do you already have a (non SinricPro) sketch that implements your desired behaviour?

sivar2311 commented 1 year ago

Hi @tmand54

Still new at this.

What do you mean exactly? New to...

Anyway, you should start with a simple Arduino sketch that will make your project work. Once you have a working project, then start implementing convert it to SinricPro.

I'm still trying to have the encoder working so it can give me a steps count.

What have you tried so far?

I've never used a rotary encoder before, but according to these instructions it seems pretty easy. I ordered a couple of them and they should arrive next Monday.

I had some YAML code , see below.

Unfortunately I can't read YAML code. As far as I know YAML is a language for configuration files.

sivar2311 commented 1 year ago

You need to add your own state variable to the sample code ... ... as well as the implementation for the motor control.

However, I think you need to go back a few steps first, since you said you are a beginner.

Step 1: Implement the motor control with the encoder feedback as a simple Arduino sketch. Step 2: When step 1 is done and the sketch is working, transfer the implementation to the blinds example.

sivar2311 commented 1 year ago

Hi @tmand54

Are you giving up already? I was looking forward to the project and thought that we would develop it together step by step. My encoders are ordered, but they won't arrive until Monday.

sivar2311 commented 1 year ago

Hi @tmand54

My encoders arrived earlier than expected.

I saw that you have deleted all your posts. !?

As far as I can see, the direction of the encoder is irrelevant. After all, the direction is already given by the motor rotation direction. So the encoder only has to count the number of steps taken.

I have written a small library called "MotorEncoder". You can find the source code and an example here.

With the function setPosition you should be able to reach any position of the motor. The direction of rotation is automatically determined from the current position.

The library may not be complete and bug free yet. Let me know if you are still interested in the project.

Kind regards sivar2311