Help with Arduino code
#21
I'm confusing myself with posts on 2 forums about this.
I got my meter out and in trying to set the 4x4 keypad sketch to step in one direction or another, I discovered that the driver board has 5vdc on the dir pin with nothing connected. Evidently the Dir output from the Arduino is not changing or sinking the current on the driver Dir pin.. If I force the driver Dir input low, by connecting it to ground from the Arduino, the direction reverses. The sketch is having no affect on direction.
I verified this by putting my meter on the dir pin output of the Arduino and running the sketch without the driver connected. The output does not change from .001vdc with either choice of direction.
Just to reiterate, I use the driver board with another Arduino running Chuck F's sketch from his post on HMEM with no changes. I am trying to add the ability to enter # of divisions from a 4x4 keypad rather than X # of button pushes for X # of steps.

Chuck
Micromark 7x14 Lathe, X2 Mill , old Green 4x6 bandsaw
The difficult takes me a while, the impossible takes a little longer.
Reply
Thanks given by:
#22
Chuck,

Is the code in your first post still the code you're working with?

Ed
Reply
Thanks given by:
#23
Sounds like he'll need a pull up on the arduino to make this measurement. Ed, didn't you use the same code?
Logan 200, Index 40H Mill, Boyer-Shultz 612 Surface Grinder, HF 4x6 Bandsaw, a shear with no name, ...
the nobucks boutique etsy shop  |  the nobucks boutique
Reply
Thanks given by:
#24
(04-06-2015, 03:47 PM)Vinny Wrote: Sounds like he'll need a pull up on the arduino to make this measurement.  Ed, didn't you use the same code?

He shouldn't need a pullup. The Arduino outputs are not open collector and they're capable of driving 40mA. The input to the driver is about an 18mA load.
I did use mostly the same code. I had to strip out all of the LCD and keyboard stuff and do some hard coding of variables.

Ed
Reply
Thanks given by:
#25
Chuck,

Try this code as a test.

Code:
/*

Test that turns the stepper motor in one direction for about 3 seconds and then reverses it for 3 seconds in a continuous cycle. Digital pin 12 is the step signal and 13 is the direction signal.

*/

#include <Wire.h>

//setup vars
const int stp = 12;  //connect pin 12 to step
const int dir = 13;  // connect pin 13 to dir
const int StepsPerRotation = 200; //Set Steps per rotation of stepper
const int TableRatio = 90; //ratio of rotary table
const int Multiplier = (StepsPerRotation * TableRatio)/360;
const int stepdelay = 1;
float Degrees = 0;                //Degrees from Serial input
float ToMove = 0;                 //Steps to move
int Direction = 1;
int repeat = 0;


void setup()
 {

   pinMode(stp, OUTPUT);
   pinMode(dir, OUTPUT);
 
 }
 

void rotation(float tm, int d)
 {  
   if(d == 0)
     {
       digitalWrite(dir, LOW);
     }
 else
   {
     digitalWrite(dir, HIGH);
   }
 
 for(int i = 0; i < tm; i++)  
  {    
   digitalWrite(stp, HIGH);  
   delay(stepdelay);              
   digitalWrite(stp, LOW);  
   delay(stepdelay);
  }
}


void loop()
{
   if(repeat == 0)
   {
     Degrees = 30;
   }
   
   Degrees = Degrees * Direction;

   if(Degrees < 0)
   {
     ToMove = (Degrees*Multiplier)*-1;
     rotation(ToMove,0);
   }
   else
   {
     ToMove = Degrees*Multiplier;
     rotation(ToMove,1);
   }
   
  if (Direction == 1)
    Direction = -1;
  else
    Direction = 1;
     
}

All it does is to turn the stepper motor in one direction for about 3 seconds and then reverses the direction for about 3 seconds and repeats the cycle until power is removed. Digital pin 12 is the step and 13 is the direction.

Ed
Reply
Thanks given by:
#26
So the output puts out 5v when hi?
Logan 200, Index 40H Mill, Boyer-Shultz 612 Surface Grinder, HF 4x6 Bandsaw, a shear with no name, ...
the nobucks boutique etsy shop  |  the nobucks boutique
Reply
Thanks given by:
#27
(04-06-2015, 05:41 PM)Vinny Wrote: So the output puts out 5v when hi?

Yup, they're push/pull outputs.

Ed
Reply
Thanks given by:
#28
Spins in one direction continuous, Ed. I did change the output pins to 2 and 3, as that is how it was currently wired. But. I will set it up with 12 and 13 if you want. I think the main idea was to test if Dir was effecting a change, yes?

Chuck
Micromark 7x14 Lathe, X2 Mill , old Green 4x6 bandsaw
The difficult takes me a while, the impossible takes a little longer.
Reply
Thanks given by:
#29
I hope you guys don't think I'm jerking you around, I'll post pics if necessary. I can't do video.
And yes, I'm still working with the original code of this thread, with the keypad.

Chuck
Micromark 7x14 Lathe, X2 Mill , old Green 4x6 bandsaw
The difficult takes me a while, the impossible takes a little longer.
Reply
Thanks given by:
#30
I did set the connections for step and Dir to 12 and 13 as your code said, and results are the same. Spins continuously in one direction. Just to show I'm doing what you suggest. I also put my multimeter on the Dir input to the stepper driver. It read 4.40 vdc.

Chuck
Micromark 7x14 Lathe, X2 Mill , old Green 4x6 bandsaw
The difficult takes me a while, the impossible takes a little longer.
Reply
Thanks given by:




Users browsing this thread: 7 Guest(s)