I am using the following setup for my linear actuator system:
500mm Linear Actuator 1605 Ball Screw Motion Guide Rail
Nema 23 Bipolar Stepper Motor
TB6560 Easy Driver
Arduino Mega Board
Power supply using 12 V and .275A
I am having trouble performing a simple back and forth motion between two fixed points.
When I use this code, the linear actuator responds by going in random directions each time and not consistently going left, stop, right, stop, and etc.
Any help would be greatly appreciated.
I have attached the code here to better explain the issue:
Why do you suddenly start reading an output pin, #9. As soon as you begin that that pin is always an input and will have noise on it, I suspect. Modify you code logic.
bcturne2:
Would you mind elaborating on that? What would you suggest instead?
As soon as this code is executed:
if (digitalRead(9)==LOW) {
digitalWrite(9,HIGH);}
else {
digitalWrite(9,LOW);
pin 9 is no longer an output pin it will always be an input because you never set it to output again.
Change the logic to just have a byte variable set to 0 or one and set it to match the digital write value. Then check that variable value to see which way to set pin 9.
On very small microcontrollers, the output pins are memory locations that can be used to store binary data. On things like the ATTiny series, the packages are so small that there are many outputs on the silicon that aren't connected to pins on the package. When you are really short on memory you can use the 'pins' for storage.
So reading from an output will return what you last wrote to it and doesn't change it to INPUT mode.
analogRead() is different. That changes the pin mode.
On very small microcontrollers, the output pins are memory locations that can be used to store binary data. On things like the ATTiny series, the packages are so small that there are many outputs on the silicon that aren't connected to pins on the package. When you are really short on memory you can use the 'pins' for storage.
So reading from an output will return what you last wrote to it and doesn't change it to INPUT mode.
analogRead() is different. That changes the pin mode.
Interesting! That is so clever. Years ago some of the USART chips in PCs I was dealing with had a byte or two of memory and I could determine which chip I was talking to.
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
At this point, the code is able to translate the linear actuator back and forth, however, the actuator motor moves the actuator forward two times occasionally instead of the correct motion.
I am fairly new to Arduino code and while I appreciate all of the responses, I don't exactly understand how to implement them.
Would someone mind explaining to me what the code should look like for the actuator to go strictly back and forth for a specified distance with an integrated pause in between motions with my pin configuration (Pins 8 and 9)?