Problem with mega2650 board

In Januar 2015 I found an idea from Nuts & Volts magazine. A Barndoor Tracker by Theron Wierenga.
When I had mine finished the steppermotor ran CCW, a missing ground. I have seen the motor running both CW and CCW. But in my house the barndoor code is not working. Another code I got from North Jutland only make the motor run CW.
I’m using a 57BYGH206 steppermotor.

Any help appreciated

Mogens

Barndoor_Compressed.pdf (205 KB)

forum 1.txt (6.95 KB)

forum 2.txt (3.89 KB)

mog2:
When I had mine finished the steppermotor ran CCW, a missing ground. I have seen the motor running both CW and CCW. But in my house the barndoor code is not working.

You may understand what that means, but it makes no sense to me because I don’t have your background knowledge of your project.

If you want help post your code. And please use the code button </> so your code looks like this and is easy to copy to a text editor

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

Tell us what stepper motor driver you are using.

Tell us how you are powering the motor (volts and amps).

A photo of a pencil drawing showing how everything is connected would also be useful.

…R

Thank you for reply. I used code button but got an error. Forum1.txt is the code from nuts&volts and forum2.txt is acode that mailed to me. You have the motor type. My psu gives 6v6 3A.
Back in 1993 I built a kind of barndoor tracker with a ucn5804, ne555 and some passive parts and that works.
You asked about drivers. The motor runs without.

Mogens

It looks like you just built an inefficient motor driver out of an expensive MEGA protoshield. From the small part of the article, I guess the author doesn't know much more than you.

Try again to use the code tags. I can't open those files on my iPad. Or maybe a forum regular will copy-paste for us.

Code from Original Post
forum 1.txt

#include <LiquidCrystal.h>

/*
  Barn Door Driver
  Written by Theron Wierenga
  July 18, 2014
  */

// Include the library code for LiquidCrystal display
#include <LiquidCrystal.h>
// Initialize the LiquidCrystal library with 
// the numbers of the interface pins
// needed for SainSmart LCD Keypad Shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// 4 bit stepper motor patterns for full step and half step
byte fullsteps[4] = {0x06, 0x0A, 0x09, 0x05};
byte halfsteps[8] = {0x04, 0x06, 0x02, 0x0A, 0x08, 0x09, 0x01, 0x05};
// Sidereal conversion
float sidereal_conv = 1.0/0.99726958;
// Angle in radians for three hours, or 45 degrees 
float three_hour_angle = 3.1415926 / 4.0;
// PI
float pi = 3.1415926;
// r value, distance from hinge to threaded rod
float r = 11.5; //r=29.21
// Solar time in seconds
float solar_time = 0;
// Delay value used to only change LCD readings about every half second
long lcount = 0L;
// Sidereal time in seconds
float sidereal = 0;
// Angle theta made by two boards
float theta = 0;
// Angle theta in degress for easy reading on LCD
float degangle = 0;
// Angle psi, the base angles of the triangle
float psi = 0;
// The complement of psi, 90 deg - psi or pi/2 radians - psi
float comp_psi = 0;
// The correction distance
float correction = 0;
// The value r after correction is applied
float rc = 0;
// d value, the base of the triangle
float d = 0;
// Number of steps needed to raise d,
// so that boards make an angle of theta
float steps = 0;
// Number of steps as a long integer
long isteps = 0L;
// Last value of isteps
long last_isteps = 0L;
// Up = true, down = false
boolean up = true;
// Slow (sideral rate) = true, fast slew = false
boolean slow = true;
// Value use to keep track of which step value to use next
// Used in fullstep_motor() a halfstep_motor() functions
int step_count = 0;
// Analog value used to read switches
int temp = 0;


void setup() {
  // Set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Starting");
  delay(1500);
  // Declare port C pins as outputs
  DDRC = B11111111;
  // Set port C output pins to all zero
  PORTC = B00000000;
}

void loop() {
  if (slow)
  {
      // Get the solar time in seconds
      solar_time = float(millis())/1000.0;
      // Convert solar time to sidereal time
      sidereal = solar_time * sidereal_conv;
      // Advance lcount, each 400 times through the loop it 
      // will update the LCD display
      lcount = lcount + 1L;
      if (lcount == 400)
      {
        // Set the cursor to column 0, line 1
        // Line 1 is the second row, since counting begins with 0
        lcd.setCursor(0,0);
        // Display sidereal time in seconds
        lcd.print("Sid'eal="); lcd.print(sidereal);
        lcd.setCursor(0, 1);
        // Display number of steps
        lcd.print(isteps);
        lcd.setCursor(10, 1);
        // Display the angle made by the two boards in degrees
        lcd.print(degangle);
        // Reset the counter
        lcount = 0;
      }
      // Calculate the angle theta needed at this time
      theta = (sidereal / 10800.0) * three_hour_angle;
      // Do a safety check if left unattended
      // Stop after angle = three_hour_angle or 45 degrees
      // About as high as it goes with 12 inch threaded rod
      if (theta >= three_hour_angle)
      {
        // Turn off current to all motor windings
         PORTC = 0;
         while(true)
         {
            // do nothing, reset to restart)
         }
      }
      // Convert this angle from radians to degrees 
      // for easy reading on the LCD display
      degangle = theta * 180.0/ pi;
      // Calculate the angle psi, knowing theta
      psi = (pi - theta) / 2.0;
      // Calculate the complement of psi
      comp_psi = (pi / 2.0) - psi;
      // Calculate the correction distance
      correction = 1.25 * tan(comp_psi);
      // Apply the corection value to r
      rc = r - correction;
      // Calculate d, the distance the threaded rod needs to travel
      d = (rc *sin(theta)) / sin(psi);
      // Calculate the number of steps needed to 
      // have the threaded rod travel distance d
      // Change 200.0 to 400.0 if using halfstep_motor()
      steps = d * 20.32 * 400.0;
      // Convert steps to a long integer
      isteps = long(steps + 0.5);
      // We need to add a step, or more, to have isteps correct
      while (last_isteps < isteps)
      {
         // halfstep_motor() can be used here, 
         // steps formula will need changing above
      //   fullstep_motor(up);
         last_isteps = last_isteps + 1L;
      }
  }
  else
  {
       // If slow = false, then slew fast
       // halfstep_motor() can be used here, 
       // steps formula will need changing above
     //  fullstep_motor(up);
       // Let stepper motor settle, this may need to be adjusted
       // for other stepper motors to get maximum speed 
       delay(5); 
  }
  // Read switches
  temp = analogRead(0);

  //if (temp > 1000) {}                               // LCD board, no button pushed
  if ((temp > 710) && (temp < 750)) {slow = true;}    // LCD board, Select pushed, run at sideral rate
  if ((temp > 490) && (temp < 510)) {slow = false;}   // LCD board, Left pushed,   run at slew rate
  if ((temp > 320) && (temp < 340)) {up = false;}     // LCD board, Down pushed,   run down
  if ((temp > 140) && (temp < 160)) {up = true;}      // LCD board, Up pushed,     run up
  //if (temp < 30) {}                                 // LCD board, Right pushed


}

void halfstep_motor(boolean forward)
{
  switch (step_count)
  {
     case 0: PORTC = halfsteps[0];
             break; 
     case 1: PORTC = halfsteps[1];
             break; 
     case 2: PORTC = halfsteps[2];
             break; 
     case 3: PORTC = halfsteps[3];
             break; 
     case 4: PORTC = halfsteps[4];
             break; 
     case 5: PORTC = halfsteps[5];
             break; 
     case 6: PORTC = halfsteps[6];
             break; 
     case 7: PORTC = halfsteps[7];
             break; 
  }
  if (forward)
  {
    step_count = step_count + 1;
    if (step_count > 7)
    { 
       step_count = 0;
    }
    return; 
  }
  else
  {
    step_count = step_count - 1; 
    if (step_count < 0)
    {
       step_count = 7; 
    }
    return;
  }
}

void fullstep_motor(boolean forward)
{
  switch (step_count)
  {
 //    case 0: PORTC = fullsteps[0];
 //            break; 
 //    case 1: PORTC = fullsteps[1];
 //            break; 
  //   case 2: PORTC = fullsteps[2];
  //           break; 
  //   case 3: PORTC = fullsteps[3];
  //           break; 
  }
  if (forward)
  {
    step_count = step_count + 1;
    if (step_count > 3)
    { 
       step_count = 0;
    }
    return; 
  }
  else
  {
    step_count = step_count - 1; 
    if (step_count < 0)
    {
       step_count = 3; 
    }
    return;
  }  
}

…R

Code from Original Post
forum 2.txt

// Include the library code for LiquidCrystal display
#include <LiquidCrystal.h>
// Initialize the LiquidCrystal library with 
// the numbers of the interface pins
// needed for SainSmart LCD Keypad Shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

byte count = 3;
int steps = 0;
boolean frem = false ;

void setup() {
  // Set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Starting");
  analogWrite(10, 0);
  pinMode(34, OUTPUT);
  pinMode(35, OUTPUT);
  pinMode(36, OUTPUT);
  pinMode(37, OUTPUT);
  digitalWrite(34, LOW);
  digitalWrite(35, LOW);
  digitalWrite(36, LOW);
  digitalWrite(37, LOW);
  
}

void drej8()
{
  switch (count)
  {
     case 1:  digitalWrite(34, HIGH);
              digitalWrite(35, LOW);
              digitalWrite(36, LOW);
              digitalWrite(37, LOW);
             break; 
     case 2:  digitalWrite(34, HIGH);
              digitalWrite(35, HIGH);
              digitalWrite(36, LOW);
              digitalWrite(37, LOW);
             break; 
     case 3:  digitalWrite(34, LOW);
              digitalWrite(35, HIGH);
              digitalWrite(36, LOW);
              digitalWrite(37, LOW);
             break; 
     case 4:  digitalWrite(34, LOW);
              digitalWrite(35, HIGH);
              digitalWrite(36, HIGH);
              digitalWrite(37, LOW);
             break; 
     case 5:  digitalWrite(34, LOW);
              digitalWrite(35, LOW);
              digitalWrite(36, HIGH);
              digitalWrite(37, LOW);
             break; 
     case 6:  digitalWrite(34, LOW);
              digitalWrite(35, LOW);
              digitalWrite(36, HIGH);
              digitalWrite(37, HIGH);
             break; 
     case 7:  digitalWrite(34, LOW);
              digitalWrite(35, LOW);
              digitalWrite(36, LOW);
              digitalWrite(37, HIGH);
             break; 
     case 8:  digitalWrite(34, HIGH);
              digitalWrite(35, LOW);
              digitalWrite(36, LOW);
              digitalWrite(37, HIGH);
             break; 
  }
}
void drej4()
{
  switch (count)
  {
     case 1:  digitalWrite(34, HIGH);
              digitalWrite(35, LOW);
              digitalWrite(36, LOW);
              digitalWrite(37, LOW);
             break; 
     case 2:  digitalWrite(34, LOW);
              digitalWrite(35, HIGH);
              digitalWrite(36, LOW);
              digitalWrite(37, LOW);
             break; 
     case 3:  digitalWrite(34, LOW);
              digitalWrite(35, LOW);
              digitalWrite(36, HIGH);
              digitalWrite(37, LOW);
             break; 
     case 4:  digitalWrite(34, LOW);
              digitalWrite(35, LOW);
              digitalWrite(36, LOW);
              digitalWrite(37, HIGH);
             break; 
  }
}

void keyboard(){
 // Read switches
int  temp = analogRead(0);
analogWrite(10, 255);
lcd.setCursor(0,1);
lcd.print(temp);
lcd.print("    ");
  //if (temp > 1000) {}                               // LCD board, no button pushed
//  if ((temp > 710) && (temp < 750)) {slow = true;}    // LCD board, Select pushed, run at sideral rate
//  if ((temp > 490) && (temp < 510)) {slow = false;}   // LCD board, Left pushed,   run at slew rate
//  if ((temp > 320) && (temp < 340)) {up = false;}     // LCD board, Down pushed,   run down
//  if ((temp > 140) && (temp < 160)) {up = true;}      // LCD board, Up pushed,     run up
  //if (temp < 30) {}                                 // LCD board, Right pushed

}

void loop() {
   keyboard();
   steps++;
   if ( steps > 2050 ) 
     { frem = !frem;
     steps = 0;  }
   
   if (frem==true) {
   count++;
   if ( count > 4 ){count = 1;} }
   else
   {  count--;
   if ( count < 1 ){count = 4;} }
//   lcd.setCursor(0, 1);
        // Display number of steps
//        lcd.print(count);
   drej4();
   delay( 20 );
}

...R

mog2:
You have the motor type.

Maybe. But I asked you to post a link to the datasheet. I am not taking the trouble to find it.

You asked about drivers. The motor runs without.

I doubt it. Maybe that is why you are having no success.

You cannot power a motor from the Arduino I/O pins.

Help us to help you - we don't charge for our services.

...R

One of the problems is that I got my right eye damaged during surgery in hospital. Along with this post are the pages from nuts & volts as pdf. I will try to find what this website can tell about stepper drivers.
The arduino language is hard. Before that it was called basic! And Z80.

Mogens

Barndoor_Compressed.pdf (880 KB)

mog2:
One of the problems is that I got my right eye damaged during surgery in hospital.

I'm sorry to hear that, I would not like it to happen to me.
However I don't see what relevance it has to this Thread or my questions.

On page 4 of that PDF there is a picture of the prototype-shield that the author has used to mount Mosfets for the purpose of driving his stepper motor. That is the driver he is using. Something like that is essential.

However a much simpler solution is to use a specialized stepper motor driver. You need to get the datasheet for the motor you are using before you can figure out a suitable driver. If the motor takes 1.5 amps or less a Pololu DRV8825 should be suitable.

Have a look at Stepper Motor Basics

...R

I think you know what binoculars are. Monoculars is for me.

MEGA2650 + displayboard on top. From output 34 - 35 - 36 - 37 to a powerboard and from here to the motor. Take a look at the pdf.
First coil pair: sort - grøn (black - green), second coil pair: rød - blå (red - blue)
The second code you saw did turn the motor but the buttons on the display board did not Work. I disconnected the first coil pair and then the motor turned CCW. Something is working except the real barndoor code.
Is it now this tread shall be closed?

Mogens

Power.brd.pdf (37.6 KB)

You're really using IRF540 MOSFETs? Not IRL? The difference is the "L" is for logic levels like 5v. The IRF ones are just barely starting to work at 5V on the gate.

1k is also an unusual choice for gate resistor. It will be further restricting the MOSFETs from working properly. 220 or less might be better but it really doesn't matter when you have the wrong MOSFETs to start.

I don't have your hardware and I did not know that design existed until you told us about it. I don't have a simple answer to your question such as "You need to connect the zebra-striped wire to the mushroom shaped button".

However if you want to explore how your code and your hardware work so that you can figure out a solution I will try to help. But you need to be prepared to answer questions - even if they eventually happen to be irrelevant questions. At the moment I don't know what may be relevant or irrelevant.

Over to you.

...R

Robin and Morgan thanks for your last post. Now I will heat my solder iron and change the four 1k resistors to around 200R and then try the setup Again.
I found the pdf from WantaiMotors.

Mogens

Wantai Motors.pdf (400 KB)

No wonder, the PC could see the MEGA board.
Bye Arduino!

Mogens

mog2:
No wonder, the PC could see the MEGA board.

That is normal with my Mega.

...R