28byj-48 stepper motor automated blinds (tilt part only) with esphome (Youtuber: the hookup’s design) . Question about my code that was copied

Thank you all ahead of time for your expert opinion!

Hello all, I'm really not completely sure if I have posted this in the proper topics so if I need to change it, I can (if possible). I'm hoping you all can help me with some general understanding of some code I have and potentially even a better understanding of if I'm potentially going to end up breaking the stepper motor with the direction I am headed. This code/ project is esphome based utilizing a esp8266 and I originally posted this in the "home assistant" forum. There is an ongoing thread here (with very little conversation-- I think it is more "off the shelf" type conversation over there). Additionally my code is posted at the end of this thread (it is essentially a copy of the reddit link)

I'm hoping you all can help me with the information in the below paragraphs (this is a copy- paste from the home assistant forum) or could lead me to somewhere else that you think this should be posted for some help.

I am a very basic beginner with iot/ home made solutions (I can follow tutorials). So, thank you all for any guidance you can give on hopefully getting my last issue with my blinds corrected. (I have a feeling the solution may already be provided in the code, but I just want to make sure I'm not going to break something by using it)


I pretty much have this working now in terms of it/ they will close fully (I have made 2 now). I am using the slider number input helper now also.–. code updated above in first post

One issue was that I had a bad gear in one of the stepper motors. It was clicking strangely and I had a feeling that was going on. The code above was found at the link at the end of this post and the only thing I added was the input helper so that I could control the rotation more granularly to figure out if I had a gear broke etc. (it told me what I needed to know luckily).

Currently I have 2 of these built now. (One with PCB (printed circuit board) and one kind of frankensteined together using standard wire/ jumpers)

The issue I am having now is that they are both in the fully closed position but one has a stepper motor position in the slider of -197 and the other has a stepper motor postion of -422. (see below)

So I’m essentially now trying to figure out how to standardize the positions at this point (they are the same motor and same blind so I’m fairly certain, this is a problem that can be solved with some slick idea, I just don’t know what the idea is)

I’m noticing in the code (identical to linked code below) there is a “reset dining room blinds” switch—> RESET in original code. It looks like it takes the windows through a full cycle (fully open to fully closed based on the positions of 0 which is fully closed in the down direction and 1500 which is fully closed in the up postion so 750 is at mid and lets the most light in. ----> keep these values in mind with the screenshow above which is my “fully closed down”. Maybe someone smarter than me can help me correct whatever is going on.

The thing I’m concerned about is that if we overtravel them too much and they see a bunch of resistance, will it break a gear inside of the motor? I assume the answer is yes so I feel like its a balance of taking them on a reset to the point of where they begin to see a little resistance to get them both at the 0 position at the bottom. I feel like this only has to be done once and since this code seems to store the stepper position, the only time they would get out of sync was if they were manually messed with or the motor drifted somehow.

There are no limit switches?

There are not. It was my understanding that is the benefit of a stepper motor for this purpose. The steps are of known rotation angles so no need for limit switches. I am only automating the tilt and not the up and down of the blind.

That last sentence may be where I confused people, I wasn't very clear in my title. I will update it and hopefully get yourself and some other talent looking at this because I really have no clue the best way to fix this.

Can you post a schematic, not a frizzy thing with links to technical information on all the hardware device.

How do You think the system will now were the stepper is positioned when You power up? Some handy visitor might have turned the stepper.....
All stepper designs need a calibration switch, a home switch. Then You can have the fun.

A schematic? I hooked everything up identical to the provided links/ as below.

But yes, when I get back to my PC, I can link the data sheet for the 5v version of the 28byj-48 stepper motor, and drv8825 motor driver. I have also used a buck convertor and esp8266 in the project but I don't think there's anything worth adding about those.

image

@gilshultz
@Railroader

True statement. I do agree with you there. From my reading of the code, it stores the position in a variable so even after a power of, the code know where the position is. I agree with u though, if it's screwed with manually-- either with the power on or off-- the position the code thinks the motor is in will be off (Im pretty certain I mentioned this in my first post)

The biggest thing Im after answerwise or helpwise is what is in my bold/ italic font in the first post.

Calibration switch/ home switch. Ahhh, I like your thinking. So this could be driven by software also correct? This code I'm noticing has a "reset" switch which is software based (towards the end of the code in "switch" section)

You may have already read the bold/ italic area of my first post-- because your definitely hitting on what Im after trying to figure out how to do. Could you espand on my worries in that paragraph about possibly breaking things? Or am I overthinking this.

I can already tell your much more knowledgeable than I in these things. I was lucky enough to even get this thing functioning at all.

I currently have it working with a slider that sets position (first picture will show this)-- but until I get the positions kind of standardized on all of them, that's the best I can do so far.

That frizzy was in your link, that is why I asked for a schematic. You have undefined lines, pins etc. and no idea what the colors represent. With the schematic I do not have burn time between parts and pictures. I am not sure of the parts as there are several iterations of them. For example: the MP1584EN gave me at least versions of it. It is a buck converter, but does the ground pass through or the +? I have both types and if it is wrong you get to purchase most of the parts in your project again.

You said "it was my understanding" so I guess you have already learned something.

The confusion may be between servo motors and stepper motors.

With servo motors, there is no need for limit switches because those have a built-in position sensor. They always know what angle the output shaft is pointing. But they cannot rotate more than 180 or maybe 270 degrees, and they are not as precise as servo motors.

With stepper motors, they can be positioned very precisely, but they are not aware of their own position and rely on the micro controller and limit switches to guide them to the required output shaft angle.

Stores data where? After a power out all data is lost. Using EEPROM memory will kill the EEPROM pre early.
Usually a home switch is used and during startup the stepper is commanded to find the home switch. Then the position is known for sure during all circumstanses.

Do all You can to avoid that. It puts stress to the mechanics. Mostly the stepper stalls and make a buzzing sound. However, if the stepper is more powerful than the obstacle, things will get damaged.

How to sense that? Forget about it. There's no way to sense that unless using a complicated sensor arrangement. Not worth even thinking about.

No. Think about a controller loss of power....

I know a little bit but only from my reading etc. Definitely not as much as most people here I believe.

I follow you here. Yeah, the code in the first post essentially "remembers" the last known position for the stepper (in the software). It could definitely be thrown off and made invalid if someone came up to the blinds and moved them but I'm willing to accept that risk. (I removed the little spinny thing that works the tilt function and I'm sure it will happen anyway but again, that's a risk I'm willing to accept)

I've heard if I wanted to use a servo motor for this that they would tend to want to drift and possibly reposition all day long in an effort to hold their "known" position. This is why I went with the "dumber" stepper. Maybe I am wrong on this, I have just been following some home automation people on youtube and they all seem to have went this way after attempting to use servos in their first attempt. They all seem to have went to steppers for tilt or a standard dc motor with limit switch for the up/ down of the blinds. In my instance I'm not interested in the up/ down, I am only interested in getting the tilt automated.

@Railroader Thank you for your responses. You all are very knowledgeable and I can tell my way of thinking is way off with most here.

It is being stored inside of a sensor in my home assistant instance which is running on a raspberry pi. So essentially my esp8266 is the microcontroller that is running the blinds. This microcontroller reports back to home assistant os the information about "its" device (the blinds). I am storing the position in a variable within home assistant. In my first post, if you'll take a look at the bottom of my first picture. Both of the blinds are using the same hardware and both of the blinds are currently in their lowered (closed) position but are showing different (-) stepper positions. I'm trying to figure out a way to get those to be the same. I imagine they are different because like you all have said, I really don't have a hardware component giving me a true position. I have a piece of software giving me "what it thinks the last know position was based on its known stepped movement". And of course if someone came up and yanked on the tilt, it wouldn't "know" about this. I am ok with that though, I'm really just trying to figure out a way to equate them for now.

And in the future will expand the hardware to take into account if someone manually messes with them.

Just out of curiosity, what would be the way to handle that situation, if I were to add or change hardware. I've heard a servo can be annoying because it will be wanting to adjust position (due to drift etc.) all day since its kind of active at all times.

I like the way you talk. I didn't notice this part until I had already fully typed the above. A calibration switch. Can you expand on this for my situation. How could I go about this with the space available. Thank you all for being helpful to me. I'm sorry, I don't know the right way to talk about all of this stuff.

Ahh, I had a feeling this was a bad idea. Well dang. I was hoping to find a cheap way out of this for the short term.

I follow you. Thank you for not sending me down a crappy path.

I think I responded to this in my first couple of paragraphs. (microcontroller sends info to home assistant etc.)

Below is an example of the style of blinds I have. I essentially 3d printed some components and they are up in the top part where the tilt rod mechanism is. I essentially followed this video verbatim. I have linked a clip of it below. (1 minute snippet of the video so you can see the space available)

@gilshultz

I'm running into all kinds of issues replying to your post. (I have it saved to a word document for now.--> I guess I could upload that and that would probably work, worst case?)

Where I'm a new user, I could only add 2 links before it said I couldn't post with more than 2 links.

And so I took those all out and went with screenshots and then it said I could only post 1 media component in a post.

Do you know anyway around these issues? (I think I have everything you need now)

You may end up seeing something in one of my other replies that makes you not want the datasheets etc. so if you happen to skim through those and think we need to go another direction, just let me know.

Thank you ahead of time for any help you can provide on the issues above.

Servo motors are analog devices and can "twitch" because of noise in their position sensors. But you can easily stop that. Servos are controlled by sending them pulses, normally around 50 per second. The length of the pulse tells the servo what angle to turn to. If you stop sending the pulses, the servo freezes. So when you want the blinds to move you can send pulses for a few seconds to allow time for movement, then stop the pulses.

28BYJ-48 is a unipolar motor with 5 wires, won't work with a bipolar chopper type driver without modification.

@JCA34F thank you for your input. It has been modified as you are thinking. Do you have any thoughts on the bold/ italicized section of my first post?

Thank you again for your comment. That will help others if they stumble upon this post.

The stepper was modified by cutting the center trace under the blue sheathing and cutting the red wire as @JCA34F is eluding to.

@PaulRB thank you for sharing your knowledge on this subject. Oh, you must me careful with the YouTubers it sounds like. One was "Dr z" and one was "the hookup" and they both ran away from the servo. It sounds like they should've came here first for some discussion.

Thank you again @PaulRB. If I were to reattempt this project with a servo, that would be one of my requirements to not hear it whining to refind it's position. I would want it to freeze/ lock until it got it's next command.

Wouldn't this make it get hot where it is holding a torque all day?-- I have the stepper set to sleep between command by jumpering the sleep and reset pins together on the stepper driver. (From the tutorial)

And lastly would the servo be small enough to fit in the little 2"x2" area that holds the mechanics for the blind. (The 1minute YouTube clip shows the area im working with. Could you suggest a servo that may fit if so?

Thank you again @PaulRB

A servo? No, if you send no pulses, the motor will not run. Unlike some stepper motors, you don't need to excite the coils to keep the position fixed. The built-in gearbox won't easily turn under external torque.

There are many micro servos commonly available like this one

Dimension: 23×12.2x27mm

Look for metal geared versions for longer life. The nylon geared ones wear out quite quickly, I'm told. Don't know about carbon fibre gears.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.