Author Topic: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3  (Read 1154 times)

jrpixley

  • New Member
  • *
  • Posts: 5
    • View Profile
Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« on: October 22, 2015, 08:11:38 AM »
I would like to use, SunTracking Heliostat Program v098, IDE 1.06 , to run my project. I am using Arudino uno  with a Adafruit Motor/Stepper/Servo Shield for Arduino v2.3 and stepper motors. The part I am having is how change the program
from the way it is to use the motor shield that is i2c ? Any help would would be great.


Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 648
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #1 on: October 23, 2015, 05:36:01 PM »
Hi jrpixley,

I don't have any experience with the Adafruit Motor shield, but if you can get some example code working you should be able to add it to the Sun Harvester Program by modifying the following functions.

The first is the moveToPosition functions located under the functions tab. You would have to input the altsteps and azsteps into the code for the motor shield to get the correct motion. I would probably ignore / remove any of the other code in the function for the sake of simplicity.

You will also have to modify the findLimits function located a bit further down the functions tab.
You will basically have to replace this code...
     digitalWrite(stepPin, HIGH);
     delayInMicroseconds(MotorDelay);         
     digitalWrite(stepPin, LOW);
     delayInMicroseconds(MotorDelay);
with code that moves the stepper motor one step.

I think that will get you started (and hopefully I didn't leave anything out), but let me know if you have any other questions.
Good luck!





jrpixley

  • New Member
  • *
  • Posts: 5
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #2 on: October 28, 2015, 09:03:31 AM »
I would like to use, SunTracking Heliostat Program v098, IDE 1.06 , to run my project. I am using Arudino uno  with a Adafruit Motor/Stepper/Servo Shield for Arduino v2.3 and stepper motors. The part I am having is how change the program
from the way it is to use the motor shield that is i2c ? Any help would would be great.
    I have got it to move with the programing.

I can't understand why program keeps giving neg. az
 my lat 33.00, lon -94.33   

sunearthtools = 115az & 12.76 elev for 8:41

When I run program this is the results.
why am I getting a neg. az?

Time:8:41:02 10/28/15 Day of week:4
sun's Alt: 12.963
Sun's Az: -65.106
Number of Machines 1
Machine Number 0
Machine's alt: 12.963
Machine's az: -65.102
move exceeds bounds

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 648
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #3 on: October 28, 2015, 09:15:17 AM »
If you subtract 180 from 115, you get -65. It looks like the sunearthtools is taking the north = 0 degrees where as the Sun Harvester program takes south as the zero degree measurement. They are just two different standards of taking bearings. It looks like you have the program set up fine. :)

jrpixley

  • New Member
  • *
  • Posts: 5
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #4 on: October 28, 2015, 09:27:03 AM »
Do I need to input info as south = 0?


Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 648
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #5 on: October 28, 2015, 09:45:50 AM »
I'm not sure I understand the question, but all of the settings assume that you are using south = 0. There is the useNorthAsZero setting, but you don't need to worry about that sense you are north of the equator. Just leave it on the default 0.

jrpixley

  • New Member
  • *
  • Posts: 5
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #6 on: October 28, 2015, 06:49:21 PM »
Thanks for your help. I may need some more help being I am poor at code. Your code is way  over my head! I have gotten Adafruit Motor/Stepper/Servo Shield for Arduino v2.3 in as far as the first part of moveToPosition functions  with the following.....
 //Code to use Adafruit motor shield library 
  altMotor->setSpeed(altSpeed);
  azMotor->setSpeed(azSpeed);
 
  if (azsteps<0){azMotor->step(abs(azsteps),BACKWARD,MICROSTEP);}
  else {azMotor->step(azsteps,FORWARD,MICROSTEP);}
   
  if (altsteps<0){altMotor->step(abs(altsteps),BACKWARD,MICROSTEP);}
  else {altMotor->step(altsteps,FORWARD,MICROSTEP);}

but when I looked, to modify the findLimits function and tried to understand, I knew I was over my head. I have looked at this for two days. if i get the project working I will show it to you. i hope this is enough tease to get your interest.

     digitalWrite(stepPin, HIGH);
     delayInMicroseconds(MotorDelay);         
     digitalWrite(stepPin, LOW);
     delayInMicroseconds(MotorDelay);

Thanks
 Joe

Gabriel

  • Administrator
  • Hero Member
  • *****
  • Posts: 648
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #7 on: November 06, 2015, 07:23:07 AM »
Hi jrpixley,

Sorry about the delayed reply. I have had a very busy week.

It looks like you have the right idea so far.

Basically this code...


     digitalWrite(stepPin, HIGH);
     delayInMicroseconds(MotorDelay);         
     digitalWrite(stepPin, LOW);
     delayInMicroseconds(MotorDelay);

Just tells a motor to move one step towards the limit switch, so you need to replace it with the motor shield code that moves a stepper motor one step. The tricky-ish part though is that you need to specify which motor need to do the moving. So you could so something like this...

if (stepPin == azimuthStepPin){ //code to move azimuth motor one step
}
if (stepPin == altitudeStepPin){ //code to move altitude motor one step
}

I don't know if you have modified the motor code that is already present, but if not I think this should work without any other modifications.

Let me know if you need more clarifications.

My busy week isn't finished yet so I don't have much time for this post Ha ha

jrpixley

  • New Member
  • *
  • Posts: 5
    • View Profile
Re: Adafruit Motor/Stepper/Servo Shield for Arduino v2.3
« Reply #8 on: November 08, 2015, 07:30:38 PM »
Thanks for your help. I put this in the bottom of the void loop and it resets both az & alt and starts tracking. Also added

  float stop_1 = false;
  float stop_2 = false;


  ///////////////////////////////////////////////////////////////////
  //Send azMotor to it's HOME position when wait for input

   while (digitalRead(LimitPin) == HIGH && !stop_1)
    azMotor->step(1, FORWARD, MICROSTEP);

  if (digitalRead(LimitPin) == LOW)
  {
    stop_1 = true;
    azMotor->step(8, BACKWARD, MICROSTEP);
    altMotor->release();
  }
  /////////////////////////////////////////////////////////////////////
  //Send altMotor to it's HOME position when wait for input

delay (1000);

  while (digitalRead(LimitPin) == HIGH && !stop_2)
    altMotor->step(1, BACKWARD, MICROSTEP);

  if (digitalRead(LimitPin) == LOW)
  {
    stop_2 = true;
    altMotor->step(8, FORWARD, MICROSTEP);
    altMotor->release();
  }