Hello Arduino guys!
I am very new in this amazing area!
I am trying to control a stepper with 2 potentiometers, but I want the motor to move only if new value from either potentiometer comes. If anybody can help me. Thanks in advance So I think that I should make it with "while" loop, but always gives me an error:
In function 'void loop()':
Stepper:44:18: error: request for member 'newwriteValue1Received' in 'potPin1', which is of non-class type 'int'
while(!potPin1.newwriteValue1Received()){
^~~~~~~~~~~~~~~~~~~~~~
Stepper:46:24: error: request for member 'parseInt' in 'potPin1', which is of non-class type 'int'
readValue1=potPin1.parseInt();
^~~~~~~~
Stepper:49:17: error: request for member 'newwriteValue2Received' in 'potPin2', which is of non-class type 'int'
while(!potPin2.newwriteValue2Received()){
^~~~~~~~~~~~~~~~~~~~~~
Stepper:51:24: error: request for member 'parseInt' in 'potPin2', which is of non-class type 'int'
readValue2=potPin2.parseInt();
^~~~~~~~
F:\Projects\Arduino Segov\Stepper\Stepper.ino: At global scope:
Stepper:57:2: error: expected unqualified-id before 'while'
while(!potPin1.newwriteValue1Received()){
^~~~~
Stepper:62:2: error: expected unqualified-id before 'while'
while(!potPin2.newwriteValue2Received()){
^~~~~
exit status 1
request for member 'newwriteValue1Received' in 'potPin1', which is of non-class type 'int'
posting code is very easy
You can post code by using this method that adds the code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps
press Ctrl-T for autoformatting your code
do a rightclick with the mouse and choose "copy for forum"
My exercise must be to control a stepper with 2 potentiometers, but the task in my mind is the stepper to move only when a new value of either pot1 or pot2 comes and not to move if the value still same. I tried to do some while loop but I know that what I typed inside is incorrect.
You wrote that you are new to coding.
This means there is a chance to have some mis-conceptions about how programming works.
you should write a pure functional description what the stepper-motor shall do.
Pure functional means avoiding any kind of programming terms. Describe the wanted function with normal everyday words.
I connect an extra powersupply to my stepper-motor
then I connect power to my arduino
The stepper-motor shall .......
If I turn potentiometer "A" to a new position the stepper-motor shall do....
if I turn potentiometer "B" to a new position the stepper-motor shall do....
etc. etc.
as a first step we the other users need a clear picture of what you want to do.
only if the wanted functionality is clear further advice can be given.
this means you have to do a compare of "old" value to actual value.
This means after stepper has moved the values must be stored in two additional variables
and then you have to code comparing
if oldValue1 != actualValue1
and
if oldValue2 != actualValue2
if this condition is true move stepper
and make
oldValue1 = actualValue1
oldValue2 = actualValue2
the behaviour will be
you can turn pot1 to any other position nothing yet happends
as soon as you turn pot2 just a little bit
if oldValue2 != actualValue2 evaluates to true
stepper moves clockwise for value1 steps
stepper moves anticlockwise for 1 step
only one step because as soons as actualValue2 deviates by 1 the condition becomes true
after moving this one step stepper stops again
if you go on turning pot2 nothing will happen. Only if you turn pot1 you get the same behavoiur
moving actualValue2 steps ccw and one step cw
I guess this is not what you want to have.
So you have to describe with even more precision what you want to have
#include <Stepper.h>
int stepsPerRevolution = 2048;
int motSpeed = 10;
int dt1 = 100;
int dt2 = 250;
int potPin1 = A0;
int potPin2 = A1;
int readValue1;
int readValue2;
int writeValue1;
int writeValue2;
int actualValue1;
int actualValue2;
int oldValue1;
int oldValue2;
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(potPin1, INPUT);
pinMode(potPin2, INPUT);
myStepper.setSpeed(motSpeed);
}
void loop() {
// put your main code here, to run repeatedly:
actualValue1=readValue1;
actualValue2=readValue2;
oldValue1=actualValue1;
oldValue2=actualValue2;
Serial.println(writeValue1);
delay(75);
Serial.println(writeValue2);
delay(75);
readValue1 = analogRead(potPin1);
delay(dt1);
readValue2 = analogRead(potPin2);
delay(dt1);
writeValue1 = (2048. / 1023.) * readValue1;
delay(dt1);
writeValue2 = -(2048. / 1023.) * readValue2;
delay(dt1);
if (oldValue1!=actualValue1) {
myStepper.step(writeValue1);
}
if (oldValue2!=actualValue2) {
myStepper.step(writeValue2);
}
}
Could you please tell me how to store old data. Because what I did in the "If loop" of course doesn't work because I did it the old to be equal to the new... And I do not know how to describe witch is the old and to compare with the new.
has to be coded after moving the stepper
which means it has to be below the commands that move the stepper
There is a very old programmer-wisdom:
Your code does always what you have coded. If the code does something different than you expected you don't yet understand what you have coded.
programming means to
analyse
very very VERY precisely what functionality you want to have.
To be able to do this you have to
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.
without any hysterisis, doesn't this cause a lot of jitter?
is the pot intended to be the desired position or the distance to move?
how do you change the direction of the stepper motor or is there a command to move it to a specific position instead of some # of steps?
Actually this is just a task in my mind, because I want to learn arduino but in the same time to do some task wich has some purpose. I imagine how this Stepper is engaged with a shaft lets say to open and close but also to have not only open and close positions but to smoothly control a flow thru some pipe or whatever is needed. So my thoughts about those potentiometers are like they simulate some sensors.