School project, steppermoter with encoder

Helle there,

Im busy with my school project that is a exam.
My school project is to make cardboardframes out of a cardboard rol.

My intention is that you can put in 2 variables and the number of frames it have to maken and that it comes out of the machine. Like 600 x 400 and 3 times. then the machine starts maken those frames 600x400mm 3 times.
We chose for a controllino. in case you dont knew this is a plc that runs on a arduino.
Im totaly new to arduino and programming.
im learning the basics at the moment. But i have a stepper motor with encoder ( I thought they call this a closed loop ) in my project. I searched on the internet for stuff like this and it is really complicated for me to understand and write a program that fit to my intentions.

So my question is can some of you help me out with programming this stepper motor with encoder in arduino IDE.?

I have pictures of my project sketches and pictures of my stepper with encoder. But it wont let me place them. so i can send them to u if you want for clearity
if you have any question ask me.

I hope u can help me out
kind regards,
Pedro S.

Please post a link to the datasheet for your stepper motor.

Is there a particular reason why you are using a stepper motor with an encoder. It seems unusual for a school project. Most stepper motors don't have encoders and just rely on the fact that the stepper motor is properly sized and does not miss steps - for example in 3D printers.

...R
Stepper Motor Basics
Simple Stepper Code

My school project is to make a machine for a company.
I chose for this motor because it has to have almost none tolerance. The totolal lengte of the cardboard frame can't devaite frome the input values.
I also posted a picture under this message so you can see where my steppermotor with encoder is attached to.
I bought the NEMA 34 with 12.5N.m HB860H + 86HB250-156B 86
I bought it on aliexpress here is a link to the stepper with encoder=

An obvious first step would be to hook up the stepper driver to the Arduino and external power and write something that steps the motor. Once that's functioning, read the encoder too.

Sooner or later you have to put actual numbers to "almost no tolerance".

Understand that both the stepper motor and the encoder are digital devices. They do things and report things in descrete increments. They will never be in step all the time. They also have error ranges of the exact step taken or reported.

Paul

Hey paul,

I thought the encoder would fix it if the stepper motor makes a mistake. the tolerance where thinking about now is that the total lenght can't be more then the given lenght but can be 1mm les. So total lengte +0 -1mm

can u help me out with programming?

wildbill:
An obvious first step would be to hook up the stepper driver to the Arduino and external power and write something that steps the motor. Once that's functioning, read the encoder too.

This would work is gues. but im new to this programming. So programming this would be really hard for me at the moment. So im looking for someone who can help me out with doing this.

pedrosn:
This would work is gues. but im new to this programming. So programming this would be really hard for me at the moment. So im looking for someone who can help me out with doing this.

Then the obvious solution is for you to overcome being new to programming. Just like any other school learning, one step at a time!!! Begin with fundamentals and use all the sample code that come with the Arduino IDE. The really difficult is designing the "logic" that your program needs, not the exact code itself.
Paul

pedrosn:
So total lengte +0 -1mm

That sort of accuracy should be easy to achieve without needing an encoder. My cheap 3D printer is accurate to 0.012mm without any encoders.

If the stepper motor misses steps then it is almost certainly because it is not powerful enough for the job or it is being driven beyond its capabilities. For example it is important to accelerate up to and down from higher speeds.

Reading an encoder without missing any encoder pulses is hard work for a microprocessor. And if the encoder pulse count and the stepper motor step count disagree how do you know which of them is correct?

I suggest you ignore the encoder to start with - that will make the learning much simpler. And you may find that the encoder is not necessary.

...R

How did you get into this situation? This project doesn't seem very suitable for you if you have no programming experience, especially if it's part of an exam.

Another factor to consider is slippage in the drive rollers. If you really need high precision on the cut piece, you will need a separate encoder or some other measurement device on the length beyond the shear.

As Robin2 says, if you need measurement beyond counting steps, your project is much more complex.

im new to this programming. So programming this would be really hard for me at the moment. So im looking for someone who can help me out with doing this.

Is there some way to talk to your instructor and turn this into a team project with another student who is more familiar with coding and less familiar with the mechanics than you are? That way you could both learn.

I've just spent a few minutes googling the controllino. First off to get more help we need to know which controllino (mini, mega, etc.) exactly that you are using. I would recommend looking up the guide on their website for that device and following the guide they have. There is some pretty clear and step by step software installation stuff there, that'll get you much closer to the actual project. After we know exactly what devices you're using we might be able to help more, and you definitely want to have the datasheets and manuals for the devices you're using (and read over them).

I have to ask how you chose the controllino and stepper motor; from what I read the controllino is a pretty high current PLC. Do you know the torque you expect the motor to be outputting? The current it'll be drawing? You might not need such a bulky expensive device (I only ask since you mentioned you were new).

I'd concur with the previous posts; if you're using a stepper motor you really don't need an encoder. Encoders are usually used with non-stepped motors. Stepper motors work by moving in discrete steps (hence the name). They only slip when overloaded, under powered, or when driven too quickly. If you don't expect the motors to slip (and I really don't think they should be slipping; if they are, you probably could fix the problem with a change to the hardware or a bigger stepper motor) then there's no need to worry about the encoder. Especially for a beginner that'll make things much simpler.

Finally, I haven't used a controllino but a little searching suggests that you can use the arduino Stepper.h library, which will do most of the work for you. I'd look up that library and read how it works. From the demos I've seen, you will just program the controllino as though it were an arduino using a USB connection to your PC. The stepper.h library lets you control a stepper by telling it how many steps per turn, which pins it's connected to, and how fast you want to drive it. Try to put some of that together and ask again if you run into more problems or get stuck.

By the way that machine you've set up looks pretty cool, seems like an interesting project!

Robin2:
That sort of accuracy should be easy to achieve without needing an encoder. My cheap 3D printer is accurate to 0.012mm without any encoders.

If the stepper motor misses steps then it is almost certainly because it is not powerful enough for the job or it is being driven beyond its capabilities. For example it is important to accelerate up to and down from higher speeds.

Reading an encoder without missing any encoder pulses is hard work for a microprocessor. And if the encoder pulse count and the stepper motor step count disagree how do you know which of them is correct?

I suggest you ignore the encoder to start with - that will make the learning much simpler. And you may find that the encoder is not necessary.

...R

Allright maybe i will start with only the steppermotor. My project must be build and working around 5 february. So i have a lot of time to learn. i bought a starters kit and built some stuff allready.
Only i have to program on the controllino that i bought. And there are not a lot of vids about that.

cattledog:
Another factor to consider is slippage in the drive rollers. If you really need high precision on the cut piece, you will need a separate encoder or some other measurement device on the length beyond the shear.

As Robin2 says, if you need measurement beyond counting steps, your project is much more complex.

Is there some way to talk to your instructor and turn this into a team project with another student who is more familiar with coding and less familiar with the mechanics than you are? That way you could both learn.

I dont think it will slip because the steel axes will be covered with rubber. Im doing this project with a other student. he also doesn't know how to program this. Teachers learned us to program a little on LOGO PLC. And siemens logo 7 i thought. but the basics. No one of our students learned to programm in C language. because our education is technical engineer. And not programmer

wildbill:
How did you get into this situation? This project doesn't seem very suitable for you if you have no programming experience, especially if it's part of an exam.

i thought the controllino had a lot of options when we are talking about steppermotors with encoders. so i thought that was the way to go and i allready bought one. and also the stepper motor with encoder.

tarnarmour:
I've just spent a few minutes googling the controllino. First off to get more help we need to know which controllino (mini, mega, etc.) exactly that you are using. I would recommend looking up the guide on their website for that device and following the guide they have. There is some pretty clear and step by step software installation stuff there, that'll get you much closer to the actual project. After we know exactly what devices you're using we might be able to help more, and you definitely want to have the datasheets and manuals for the devices you're using (and read over them).

I have to ask how you chose the controllino and stepper motor; from what I read the controllino is a pretty high current PLC. Do you know the torque you expect the motor to be outputting? The current it'll be drawing? You might not need such a bulky expensive device (I only ask since you mentioned you were new).

I'd concur with the previous posts; if you're using a stepper motor you really don't need an encoder. Encoders are usually used with non-stepped motors. Stepper motors work by moving in discrete steps (hence the name). They only slip when overloaded, under powered, or when driven too quickly. If you don't expect the motors to slip (and I really don't think they should be slipping; if they are, you probably could fix the problem with a change to the hardware or a bigger stepper motor) then there's no need to worry about the encoder. Especially for a beginner that'll make things much simpler.

Finally, I haven't used a controllino but a little searching suggests that you can use the arduino Stepper.h library, which will do most of the work for you. I'd look up that library and read how it works. From the demos I've seen, you will just program the controllino as though it were an arduino using a USB connection to your PC. The stepper.h library lets you control a stepper by telling it how many steps per turn, which pins it's connected to, and how fast you want to drive it. Try to put some of that together and ask again if you run into more problems or get stuck.

By the way that machine you've set up looks pretty cool, seems like an interesting project!

Hey tarnarmour,

Its to late to change plc. I bought the controllino MEGA pure. i had to be sure that a have enought in and outputs etc.
Data sheet controllino

The stepper puts out 12.5 Newton.meters
I will try using only steps and let the encoder to what it is. maybe if i the machine doesn't work properly without i will try and get that in aswell. there are a lot of vids about steppers so i guess i will succeed programming that. The Stepper.h will help me with that i think and i have to include the CONTROLLINO.h libary aswel but i have to find out what is in there.

I only have one problem that i keep thinking about. When running a programmer it should not skip operations. what i experienced by using IF is that if it is false it just skips that part of the program. But that can't happen in a plc programm. do you have a option to avoid that? like he the programm has to wait for every condition to be true to continu. Is this possible by using while loops or something?

Thanks, i hope we will be able to make everything in time despite corona.

I only have one problem that i keep thinking about. When running a programmer it should not skip operations. what i experienced by using IF is that if it is false it just skips that part of the program. But that can't happen in a plc programm. do you have a option to avoid that? like he the programm has to wait for every condition to be true to continu. Is this possible by using while loops or something?

The Arduino program is continually looping. Why do you want to avoid skipping over a part of the program if the condition to run it is false? The code does not wait for the condition to become true, but keeps on running and looping. It will execute the block if and when the condition is true.

cattledog:
The Arduino program is continually looping. Why do you want to avoid skipping over a part of the program if the condition to run it is false? The code does not wait for the condition to become true, but keeps on running and looping. It will execute the block if and when the condition is true.

A lot of PLC stuff operates that way. Every part of the machine is dependent on the part before, and you must finish one cycle before starting a new one.

For this, I would personally use flags. Set some boolean variables and check with if or switch statements. Everytime something is accomplished, change the flags around, and evaluate again. Most likely there's gonna be a better solution, but I think this is the simplest it can get. Also, doing it this way is basically writing a ladder diagram, which most traditional PLC uses anyways.

pedrosn:
what i experienced by using IF is that if it is false it just skips that part of the program.

We must assume that that is what the programmer intended to happen, Otherwise, why would there be an IF statement?

YOU have to design the logic of the program to do what YOU want.

Before you start writing code it's a good idea (it's almost essential) to write down a very detailed list of the actions you want the program. Write each action on a new line. Computers are completely stupid so you have figure out all the little details of what needs to happen.

...R

cattledog:
The Arduino program is continually looping. Why do you want to avoid skipping over a part of the program if the condition to run it is false? The code does not wait for the condition to become true, but keeps on running and looping. It will execute the block if and when the condition is true.

I want this because the stapper can't start running before a couple of cilinders in my project are in. Im gonna put 2 sensors on each cilinder. But the machine has to do multiple operation in order. So it can't skip a step and move on to the next one if the one before isn't done.
You understand?
My emglish isn't the best so if you don't understand what im trying to say just tell me
Yo

pedrosn:
So it can't skip a step and move on to the next one if the one before isn't done.

If you write the program correctly that won't happen.

Don't expect the program to be perfect first time. Develop it in small parts and test it regularly.

...R

linearity64:
For this, I would personally use flags. Set some boolean variables and check with if or switch statements. Everytime something is accomplished, change the flags around, and evaluate again. Most likely there's gonna be a better solution, but I think this is the simplest it can get. Also, doing it this way is basically writing a ladder diagram, which most traditional PLC uses anyways.

Hey,
Can you can explain how i use those commands? Or writhe a example for me? Im new to coding. Or can you recommend my some vids where they explain this clearly?