Think I'm overlooking something in my code... 2nd pair of eyes needed!

Hi guys

I've been working on code to control my camera on a timelapse mechanism I've made involving 2 stepper motors, and a shutter control mechanism.

When I start the sketch running the details reported to the serial monitor seem sensible enough but in practise it's behaving a little odd and I'm not sure why but then I have spent ages staring at this and made a ton of changes, so there's probably superfluous bits of code and probably duplicated lines or something!

I've made a veroboard circuit that houses 2 pololu stepper drivers, 4 potentiometers (2 for the steppers and 2 for the shutter speed and interval time). I haven't really set up math for the interval time so have manually set that in code, but the shutter speed is set with an array of predetermined values.

Now in general the sketch is trying to work, but is doing strange stepper behaviour in the following ways:

  1. The same stepper is moving from the instructions given for the pan and the rail movements - no idea how!
  2. The stepper moves every 0.3-0.5 seconds until it's done the sequence of 10 steps, then does the same for the pan axis (but still bizarrely on the same motor).
  3. The shutter on the camera isn't firing. I've had it firing before but won't now for some reason, yet I've tested that it does very briefly create continuity across the output pins, and if I touch them briefly with metal to short them it fires perfectly.

I think I'm looking to see if anyone can spot obvious stupidity that I've added in here while amending things, as it's so close to working but not fully there yet.

Appreciate any suggestions thanks!

Here's the code:

#include <LiquidCrystal.h> 
//LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
int buttonpin = A0; //Button presses from keypad - not used yet

byte directionPin1 = 0; // rail
byte stepPin1 = 1; // rail
int numberOfSteps1 = 10; // rail
int dir1 = 0; // direction flag for rail 
int stepdelay1 = 1; // the delay between steps to control the speed

byte directionPin2 = 2; // pan
byte stepPin2 = 3; // pan 
int numberOfSteps2 = 10; // pan
int dir2 = 0; // flag for pan direction 
int stepdelay2 = 1; // the delay between steps to control the speed 

byte ledPin = 13;
int sensorPin1 = A1; // input pin for rail pot
int sensorPin2 = A2; // panning pot 
int sensorPin3 = A3; // exposure
int sensorPin4 = A4; // interval

int sensorValue1 = 0;  // variable to store the value coming from the rail sensor
int sensorValue2 = 0;  // variable to store the value coming from the pan sensor
int sensorValue3 = 0;  // variable for the exposure
int sensorValue4 = 0;  // variable for the interval

int sensorValue1b = 0;  // new var to deduct 512 from rail input
int sensorValue2b = 0;  // new var to deduct 512 from pan input

int interval = 1; // Delay between pictures (in seconds)
int exposure = 1; // default exposure time (ms)
int shutterPin =11; // Shutter pin (digital)
int shutterarray[20] = {1, 2, 4, 8, 16, 33, 60, 125, 250, 500, 1000, 2000, 4000, 6000, 8000, 10000, 15000, 20000, 25000, 30000}; // create array of shutter millisecond speeds available

float newval= 0;
int roundval = 0;

void setup() 
{ 
  Serial.begin(9600);  // start serial output
  lcd.begin(16, 2);  // start the lcd object
  Serial.println("Starting");
  lcd.setCursor(0,0);  
  lcd.print("Starting");
  
  sensorValue1 = analogRead(sensorPin1);    //rail
  sensorValue2 = analogRead(sensorPin2);    //pan
  sensorValue3 = analogRead(sensorPin3);    //expo
  sensorValue4 = analogRead(sensorPin4);    //intvl
  Serial.println(sensorValue1);  //rail
  Serial.println(sensorValue2);  //pan
  Serial.println(sensorValue3);  //expo
  Serial.println(sensorValue4);  //intvl
  Serial.println("");
 
  newval = sensorValue4/51.2; // roughly range of 1-20 with loads of decimals
  roundval = (int) newval; // round (actually truncate) it to a round number/integer
  exposure = shutterarray[roundval]; // will pick up the appropriate shutter speed based on input val
  Serial.println("Shutter MS =");
  Serial.println(exposure);
  Serial.println("Interval =");
  Serial.println(interval);
  
  digitalWrite(ledPin, LOW);
  delay(2000);

  pinMode(directionPin1, OUTPUT);
  pinMode(stepPin1, OUTPUT);
  pinMode(directionPin2, OUTPUT); 
  pinMode(stepPin2, OUTPUT); 

  pinMode(shutterPin, OUTPUT); // Set the shutter pin as an output
  digitalWrite(shutterPin, LOW);
  pinMode(ledPin, OUTPUT); // Set the LED pin as an output
  
  // set up how many loops:
  for (int count=0; count <= 100; count++)
                {
                // begin loop  
              
                //take pic:
                Serial.println("Fire Shutter MS=");
                lcd.setCursor(0,0); 
                lcd.print("                ");         // Blank
                lcd.setCursor(0,0);  
                lcd.print("Photostart");
                
                lcd.setCursor(0,1); 
                lcd.print("                ");         // Blank
                lcd.setCursor(0, 1); //move to second line
                lcd.print(exposure);
                Serial.println(exposure);
                
                //digitalWrite(ledPin, HIGH); // Turn on activity LED
                digitalWrite(shutterPin, HIGH); // Turn on shutter relay
                delay(exposure); // Hold the button for set time
                //digitalWrite(ledPin, LOW); // Turn off activity LED
                digitalWrite(shutterPin, LOW); // Turn off shutter relay
                
                Serial.println("Photostop");
                lcd.setCursor(0,0); 
                lcd.print("                ");         // Blank
                lcd.setCursor(0,0); 
                lcd.print("Photostop");
              	
                // begin rail ******************************
                // get the 2 analog sensor values from the rail & pan pots:
              
              	lcd.setCursor(0,1); 
              	lcd.print("                ");         // Blank
              	lcd.setCursor(0,1); 
              	lcd.print("Move...");         // Blank
              	Serial.println("Move rail = steps");
              	Serial.println(numberOfSteps1);
              	Serial.println("Move pan = steps");
              	Serial.println(numberOfSteps2);              
                sensorValue1 = analogRead(sensorPin1);    
                sensorValue1b = sensorValue1-512; // JD+
                
                sensorValue2 = analogRead(sensorPin2);    
                sensorValue2b = sensorValue2-512; 
               if 
                 (sensorValue1b < 0)
                 {
                 digitalWrite(directionPin1, HIGH); // Turn one way if the pot is turned low
                 {dir1 = 1;} // and set the direction flag
                 {stepdelay1 = sensorValue1b * -1;} // convert the minus figure to + for the speed
                 } 
               else
                 {
                 digitalWrite(directionPin1, LOW); // Turn the other way if the pot is turned high
                 {dir1 = 0;}  // and set the direction flag
                 {stepdelay1 = sensorValue1b;} //already have the speed
                 }  // and set the direction flag
               Serial.println("Rail Direction =");
               Serial.println(dir1); //report the direction flag
               
                for(int n = 0; n < numberOfSteps1; n++) 
                {
                  digitalWrite(stepPin1, HIGH);
                  Serial.println("Stepping Rail Now...");                  
                  //delay(uSbetweenSteps);
              	  delay(stepdelay1); // get the calculated figure to set the speed
                  digitalWrite(ledPin, !digitalRead(ledPin));
                }
               // end rail ******************************
              
              // begin pan******************************
               if 
                 (sensorValue2b < 0)
                 {
                 digitalWrite(directionPin2, HIGH); // Turn one way if the pot is turned low
                 {dir2 = 1;} // and set the direction flag
                 {stepdelay2 = sensorValue2b * -1;} // convert the minus figure to + for the speed
                 } 
               else
                 {
                 digitalWrite(directionPin2, LOW); // Turn the other way if the pot is turned high
                 {dir2 = 0;}  // and set the direction flag
                 {stepdelay2 = sensorValue2b;} //already have the speed
                 }  // and set the direction2 flag
               Serial.println("Pan Direction =");               
               Serial.println(dir2); //report the direction flag
               
                for(int n = 0; n < numberOfSteps2; n++) 
                {
                  digitalWrite(stepPin2, HIGH);
                  Serial.println("Stepping Pan Now...");                  
                  //delay(uSbetweenSteps);
                  delay(stepdelay2); // get the calculated figure to set the speed
                  digitalWrite(ledPin, !digitalRead(ledPin));
                }
               // end pan ******************************
               Serial.println("Photo Count =");
               Serial.println(count);
                
               lcd.setCursor(0,0); 
               lcd.print("Wait b4 next shot");
               delay(1000 * interval); // Wait interval time before next shot for stuff to move and time next frame.
               Serial.println("Wait b4 next =");    
               Serial.println(interval);   
               
               lcd.setCursor(0,1); 
               lcd.print("Count = ");
               
               lcd.setCursor(9,1); 
               lcd.print("count");
               
                lcd.setCursor(0,1); 
                lcd.print(1000 * interval);
              // end loop ******************** 
              }
 lcd.setCursor(0,0); 
 lcd.print("                ");
 lcd.setCursor(0,1); 
 lcd.print("                ");
 lcd.setCursor(0,0); 
 lcd.print("All finished");
}


void loop() // *****************************************************************
{ 
}
byte directionPin1 = 0; // rail
byte stepPin1 = 1; // rail

Those are hardware serial pins. They are used by the Serial instance.

int sensorPin1 = A1; // input pin for rail pot
int sensorPin2 = A2; // panning pot 
int sensorPin3 = A3; // exposure
int sensorPin4 = A4; // interval

You didn't order generic sensors from Mouser, did you? Don't use generic names, then,

               if 
                 (sensorValue1b < 0)

Why is
this spread
across multiple
lines?

                 {dir1 = 1;} // and set the direction flag
                 {stepdelay1 = sensorValue1b * -1;} // convert the minus figure to + for the speed

{Why} {are} {these} {in} {curly} {braces} {with} {no} {spacing}?

Use Tools + Auto Format to fix your crappy indenting.

Yep. I think PaulS has it cracked. Whenever you do a serial print, you're inadvertently sending signals to other things. Pick some different pins.

Ok I did actually find one silly error which is the wrong sensor was being read for the shutter speed - should be 3 instead of 4 so I fixed that and the camera now fires on all but the very fastest of shutter speeds. It seems to fail, or at least fire intermittently at very fast speeds where it's only a few milliseconds, so around 1/1000-10/1000 of a second maybe. I can live without it doing 1/1000 of a second but I'd need it to at least work in the 100s.

Also, I've found that when I change the number of steps to 0 instead of 10 the motor moves in one motion instead of 10 separate tiny moves, but what I don't get, is why it's moving more than a tiny amount (1.8 degrees for a single step) if this should be a single step? It's turning more like 90 degrees, and still turning one motor for the sections of code that should be changing from one to the other???

Thanks for the replies guys! Didn't realise there was an autoindent - great!!!! :smiley:

I'll review the other comments and advise cheers.

PaulS:
Why is
this spread
across multiple
lines?

                 {dir1 = 1;} // and set the direction flag

{stepdelay1 = sensorValue1b * -1;} // convert the minus figure to + for the speed



{Why} {are} {these} {in} {curly} {braces} {with} {no} {spacing}?

Sorry to sound dumb but I'm not sure what you mean about the spacing in regard to this?

Ok, so my code is tidier now, but after changing the pins to 12 and 13 respectively my stepper now does nothing. I've swapped to these and changed the code accordingly.

To elaborate I'm using the LCD Keypad Shield which uses 4,5,6,7,8,9,10 and Analog 0
So I've got stepper 1 - direction = on D2, step on D3,
stepper 2 - direction = on D12, step on D13

D11 is used for the Shutter control pin

Analog 1, 2, 3, 4 are used for the 4 potentiometers that give the input values.

Actually, the stepper is trying to do something but isn't actually turning. I suspect this might be down to the setting of the vref potentiometer on the Pololu driver board as I realised I haven't set those specifically so the stepper might be getting the wrong amount of current. Will tweak and see what happens.

What I'm really at a loss with though most of all, is why the first stepper is trying to move the steps that are being sent for two separate motors, with two separate driver boards. Doesn't make sense.
The only thing shared on the driver boards is the 5v & gnd feed from the arduino, and the 12v & gnd feed to send power for the stepper motors. Both come from the same sources respectively but then they sort of have to, so I can't see how that would affect its behaviour.

Ok, so my code is tidier now

You can see that. We can't.

I'll post it up once I've changed a couple of things.

I have found the problem re' the stepper movement I think. I have omitted code that I previously used on an earlier version of stepper control where it was necessary to convert the input to a suitable number for the step delays. As it stands I'm just feeding an un tamed figure in for this so I need to copy those calcs over.

I'll do this shortly though as I have a banging headache and my kids are driving me bananas with the amount of noise they're making!!! :slight_smile:

Gah!

I keep getting an error with no reference to the line number.

Error: invalid suffix "if" on integer constant.

I've got a few if statements and can't see why they're wrong. I did get this exact error earlier and fixed it but my brain is so fried right now I can't recall what the problem was earlier. Annoying that it doesn't show the line number though.

If it's stating that the "if" is the problem then would that suggest I have left something incorrectly formatted/syntaxed on the previous line to one of the if statements perhaps?

I've changed a lot of code but not finished yet so am loathe to post it up as it won't make much sense currently.

Annoyingly, the autoformat has shifted curly brackets onto separate lines again when I've used it after I tidied them earlier. I guess that's how they got like that in the first place now.

I haven't renamed those sensors yet btw... will do though.

If someone could advise what I'm doing wrong with this sodding error though I'd be grateful, thanks.

// Useful - http://arduino-info.wikispaces.com/LCD-Pushbuttons
// button presses are through A0 using "int read_LCD_buttons()"
#include <LiquidCrystal.h> 
//LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
int buttonpin = A0; //Button presses from keypad


byte directionPin1 = 12; // rail
byte stepPin1 = 13if; // rail
int numberOfSteps1 = 3; // rail
int dir1 = 0; // direction flag for rail 
int stepdelay1 = 0; // the delay between steps to control the speed
int stepdelaytime1b = 0;
int stepdelaytime1c = 1;
int delaytime1 = 1;


byte directionPin2 = 2; // pan
byte stepPin2 = 3; // pan 
int numberOfSteps2 = 3; // pan
int dir2 = 0; // notional serial output flag for direction 
int stepdelay2 = 0; // the delay between steps to control the speed 
int stepdelaytime2b = 0;
int stepdelaytime2c = 1;
int delaytime2 = 1;

byte ledPin = 13;
//int uSbetweenSteps = 5; // microseconds
int sensorPin1 = A1; // input pin for rail pot
int sensorPin2 = A2; // panning pot 
int sensorPin3 = A3; // exposure
int sensorPin4 = A4; // interval

int sensorValue1 = 0;  // variable to store the value coming from the rail sensor
int sensorValue2 = 0;  // variable to store the value coming from the pan sensor
int sensorValue3 = 0;  // variable for the exposure
int sensorValue4 = 0;  // variable for the interval

int sensorValue1b = 0;  // new var to deduct 512 from rail input
int sensorValue2b = 0;  // new var to deduct 512 from pan input

int interval = 3; // Delay between pictures (in seconds)
int exposure = 1; // default exposure time (ms)
int shutterPin =11; // Shutter pin (digital)
int shutterarray[20] = {
  1, 2, 4, 8, 16, 33, 60, 125, 250, 500, 1000, 2000, 4000, 6000, 8000, 10000, 15000, 20000, 25000, 30000}; // create array of shutter millisecond speeds available

float newval= 0;
int roundval = 0;

void setup() 
{ 
  Serial.begin(9600);  // start serial output
  lcd.begin(16, 2);  // start the lcd object
  Serial.println("Starting");
  lcd.setCursor(0,0);  
  lcd.print("Starting");

  sensorValue1 = analogRead(sensorPin1);    //rail
  sensorValue2 = analogRead(sensorPin2);    //pan
  sensorValue3 = analogRead(sensorPin3);    //expo
  sensorValue4 = analogRead(sensorPin4);    //intvl
  Serial.println(sensorValue1);  //rail
  Serial.println(sensorValue2);  //pan
  Serial.println(sensorValue3);  //expo
  Serial.println(sensorValue4);  //intvl
  Serial.println("");

  newval = (sensorValue3/51.2); // roughly range of 1-20 with loads of decimals
  roundval = (int) newval; // round (actually truncate) it to a round number/integer
  exposure = shutterarray[roundval]; // will pick up the appropriate shutter speed based on input val

  Serial.println("newval =");
  Serial.println(newval);
  Serial.println("roundval =");
  Serial.println(roundval);

  Serial.println("Shutter MS =");
  Serial.println(exposure);
  Serial.println("Interval =");
  Serial.println(interval);

  digitalWrite(ledPin, LOW);
  delay(2000);

  pinMode(directionPin1, OUTPUT);
  pinMode(stepPin1, OUTPUT);
  pinMode(directionPin2, OUTPUT); 
  pinMode(stepPin2, OUTPUT); 

  pinMode(shutterPin, OUTPUT); // Set the shutter pin as an output
  digitalWrite(shutterPin, LOW);
  pinMode(ledPin, OUTPUT); // Set the LED pin as an output

  // set up how many loops:
  for (int count=0; count <= 100; count++)
  {
    // begin loop  

    //take pic:
    Serial.println("Fire Shutter MS=");
    lcd.setCursor(0,0); 
    lcd.print("                ");         // Blank
    lcd.setCursor(0,0);  
    lcd.print("Photostart");

    lcd.setCursor(0,1); 
    lcd.print("                ");         // Blank
    lcd.setCursor(0, 1); //move to second line
    lcd.print(exposure);
    Serial.println(exposure);

    //digitalWrite(ledPin, HIGH); // Turn on activity LED
    digitalWrite(shutterPin, HIGH); // Turn on shutter relay
    delay(exposure); // Hold the button for set time
    //digitalWrite(ledPin, LOW); // Turn off activity LED
    digitalWrite(shutterPin, LOW); // Turn off shutter relay

    Serial.println("Photostop");
    lcd.setCursor(0,0); 
    lcd.print("                ");         // Blank
    lcd.setCursor(0,0); 
    lcd.print("Photostop");








    // get the 2 analog sensor values from the rail & pan pots:

    lcd.setCursor(0,1); 
    lcd.print("                ");         // Blank
    lcd.setCursor(0,1); 
    lcd.print("Move...");         // Blank
    Serial.println("Move rail = steps");
    Serial.println(numberOfSteps1);
    Serial.println("Move pan = steps");
    Serial.println(numberOfSteps2);              
    sensorValue1 = analogRead(sensorPin1);    
    sensorValue1b = sensorValue1-512; // JD+

    sensorValue2 = analogRead(sensorPin2);    
    sensorValue2b = sensorValue2-512; 


    // begin rail ******************************    
    if 
      (sensorValue1b < 0)
    {
      digitalWrite(directionPin1, HIGH); // Turn one way if the pot is turned low
      { 
        dir1 = 1;
      } // and set the direction flag
      {
        stepdelay1 = (sensorValue1b * -1); 
      }  // convert the minus figure to + for the speed
    } 
else
{  
  digitalWrite(directionPin1, LOW); // Turn the other way if the pot is turned high
  {
    dir1 = 0;
  } // and set the direction flag
  {
    stepdelay1 = sensorValue1b;
  } //already have the speed
} 

Serial.println("Rail Direction =");
Serial.println(dir1); //report the direction flag
//************************
//************************

stepdelaytime1b = sqrt(stepdelay1)/3; // of the knob output and reduce the range of delay
if 
  (stepdelaytime1b == 0) // a value of zero causes the code to stop so we weed this out for now with default 1
  {stepdelaytime1c = 1;}
else
  {stepdelaytime1c = stepdelaytime1b;}

delaytime1 = 22/stepdelaytime1b; // this is to invert the speed control about its centre point.
// 11 is the max value thus dividing into it gives the inverse and the speed control goes the right way now

for(int n = 0; n < numberOfSteps1; n++) 
{
  digitalWrite(stepPin1, HIGH);
  Serial.println("Stepping Rail Now...");                  
  delay(delaytime1);
  digitalWrite(ledPin, !digitalRead(ledPin));
}
// end rail ******************************





// begin pan******************************
if 
(sensorValue2b < 0)
{
  digitalWrite(directionPin2, HIGH); // Turn one way if the pot is turned low
  {
    dir2 = 1;
  } // and set the direction flag
  {
    stepdelay2 = (sensorValue2b * -1);
  } // convert the minus figure to + for the speed
} 
else
{  
  digitalWrite(directionPin2, LOW); // Turn the other way if the pot is turned high
  {
    dir2 = 0;
  } // and set the direction flag
  {
    stepdelay2 = sensorValue2b;
  } //already have the speed
}  
Serial.println("Pan Direction =");               
Serial.println(dir2); //report the direction flag

for(int n = 0; n < numberOfSteps2; n++) 
{
  digitalWrite(stepPin2, HIGH);
  Serial.println("Stepping Pan Now...");                  
  //delay(uSbetweenSteps);
  delay(stepdelay2); // get the calculated figure to set the speed
  digitalWrite(ledPin, !digitalRead(ledPin));
}
// end pan ******************************






Serial.println("Photo Count =");
Serial.println(count);

lcd.setCursor(0,0); 
lcd.print("Wait b4 next shot");
delay(1000 * interval); // Wait interval time before next shot for stuff to move and time next frame.
Serial.println("Wait b4 next =");    
Serial.println(interval);   

lcd.setCursor(0,1); 
lcd.print("Count = ");

lcd.setCursor(9,1); 
lcd.print("count");

lcd.setCursor(0,1); 
lcd.print(1000 * interval);
// end loop ******************** 
}
lcd.setCursor(0,0); 
lcd.print("                ");
lcd.setCursor(0,1); 
lcd.print("                ");
lcd.setCursor(0,0); 
lcd.print("All finished");
}

void loop() // *****************************************************************
{ 
}
if 
(sensorValue2b < 0)
{

It was strongly hinted that you fix this crap.

      {
        dir2 = 1;
      } // and set the direction flag
      {
        stepdelay2 = (sensorValue2b * -1);
      } // convert the minus figure to + for the speed

The curly braces here are useless. All they do is scream clueless.

sketch_oct19a.ino:8:17: error: invalid suffix "if" on integer constant

Line 8:

byte stepPin1 = 13if; // rail

Well, sure enough. What the hell is the if doing there?

I did remove those brackets first time round and it stopped working.

So I put them back. They're on different lines because the autoformat put them there after I tidied them onto the same lines as the code they surround. Like I say, I tried removed them and it failed as a result so they went back in.

As for that "if" I swear down that wasn't there before. Goddamit (thanks).

Cretster:
If someone could advise what I'm doing wrong with this sodding error though I'd be grateful, thanks.

Can you describe in plain language how the code is supposed to work because I an too lazy to try to reverse-engineer it.

...R

Some minor stuff 
Take a look at this sequence , it steps on itself a little.
Generally using lcd.Clear() reduces the clutter.

Also using  lcd.print in sequence without lcd,setCursor works.

lcd.print("Counter  ");
lcd.print(count);


[codeSerial.println("Photo Count =");
Serial.println(count);

lcd.setCursor(0,0); 
lcd.print("Wait b4 next shot");
delay(1000 * interval); // Wait interval time before next shot for stuff to move and time next frame.

Serial.println("Wait b4 next =");    
Serial.println(interval);   

lcd.setCursor(0,1); 
lcd.print("Count = ");

//lcd.setCursor(9,1); 
lcd.print(count);        // should this be variable and not "Count"? 
lcd.setCursor(0,1); 
lcd.print(1000 * interval); // steps over "Count" 

delay(5000);
]

Thanks Robin

Paul spotted the error that I completely failed to see, which was the erroneous "if" that had somehow got into the stuff right at the top. Grrr! And yeah, it seems I'm guilty of failing to spot the reference to the line number in the error - I'd glanced at that and seen the filename and hastily dismissed it as a timestamp or something cobbled on the filename. Duh.

And re' the bracket thing, I've removed them now without a fail so I guess I had missed something else at the time.

In my defense, I've had 2 kids driving me absolutely mental while I've been trying to do this, with a slight hangover, and a massive headache. Concentration has been night on impossible so i hope the gods of arduino coding can forgive my pitiful noob fails on this occasion, providing I learn from them. Is that fair?

Thanks for the suggestions vaclav - I will read through them and see what's what.

Appreciate the input mate.

Robin - re' what the code is doing, I've got a circuit I made with 4 potentiometers as inputs (I'll be replacing them with encoders at some point), 2 pololu stepper drivers going to a stepper motor each, and a small circuit to control a DSLR camera shutter.
Also have the 16x2 LCD display.

2 pots are used to control the steppers by messing with the analog values to provide a negative or positive val for forward or reverse direction, then the number is tamed down to give a usable figure for the delay between each step the motor does.
One for moving along the main axis of the timelapse rail and the other to pan the camera.

The 3rd pot is to set the camera exposure/shutter time, using an array of common shutter speeds to correlate with.
The 4th one is to set the interval between shots. I've not stipulated the maths for that yet in order to link the value in the code with the pot output.

The code then loops through a set number of photos and stops.

What I'll be doing next is to use the LCD to display quickly refreshed values of the pots so I can actually see what's selected on each before pressing a button to confirm/start the sequence with the chosen values. At the moment it's a bit random how as I can't see the values until I run the code, then they can't be changed of course.

I've already written a separate sketch that auto updates the LCD with changing values of the pots, but haven't added it to this yet as I didn't get it yet to exit correctly with a button press and keep the values at that point.

Hope that makes some sense! :slight_smile:

Vaclav - re' your kind suggestions, I take it the LCD just puts successive print commands to the next character on the display?
The reason I have all the set cursor lines is to position printed output onto specific positions although I can see now that I can avoid that in many places, thanks.

I like the clear command but really need to be able to apply it to a single line and I couldn't see a way of doing that, other than some stuff I found that was a library someone did for a different kind of display to the one I have.

Yes, the count number ideally should be an input variable. I think I just have enough input left to add this with another potentiometer, but I've just manually set it for now as it's the least important input in respect of being able to change it.
For now, I'll set it as a high number then if the timelapse needs fewer images I just stop it prior to that point.

So it's all getting a bit better now, but some things need further investigation.

The first stepper is enegising when it should, but does not actually turn. I've changed the vref setting on the pololu driver but something relating to the speed/steps/delay settings I think is upsetting things. Not yet sure what. I've had this on the previously functional but basic rail I built, when the microstepping was not set 'just so'. I have a suspicion the steppers I have are not well suited to this due to something (I forget offhand) from their spec which apparently makes them a bad choice. Long story but they're from a half built reprap printer I bought from a friend, then found the motors weren't the right ones for it.

The second stepper does nothing at all. I think the pololu driver for it might actually be dead. I'll check with the multimeter if I can detect a pulse going to either the step or direction inputs on it. If there are, then I think it'd confirm it's faulty maybe. I should have bought a load since they're cheap as I've had one fail before on my printer. What I don't understand though about this stepper thing, is the fact that the instructions to the second one are being enacted by the first. Could understand the second motor not working but not the first one carrying out its instructions as a result. I think there could be a wiring fault or short somewhere else I can't see how this could happen.

Below is some code I wrote a few days ago as a standalone sketch to continually refresh the display each second with the input values (so the right values can be seen and selected before running the main process). I think it worked but I need to get it to exit loop with the appropriate values when a button is pressed, and hadn't achieved that yet. I think maybe it needs a "while" loop or something but like I say, hadn't got that far yet. Any useful suggestions on this gratefully received:

// This is to give a live readout of the 4 sensor values as they change while being set up, before confirming.

#include "LiquidCrystal.h";
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );
int sensorPin1 = A1;    // Exp
int sensorPin2 = A2;	// Intvl
int sensorPin3 = A3;	// Track
int sensorPin4 = A4;	// Pan

int Exp = 0;
int Intvl= 0;
int Track= 0;
int Pan= 0;


void setup() 
{
Serial.begin(9600);
lcd.begin (16, 2);

}

void loop() 
{
// thisloop is to constantly poll for values and update lcd until confirm button is pressed to break loop and allocate the vals to variables
Exp = analogRead(sensorPin1);  
Intvl = analogRead(sensorPin2);  
Track = analogRead(sensorPin3);  
Pan = analogRead(sensorPin4);  

lcd.setCursor(0,0);
lcd.print("Ex");
lcd.setCursor(3,0);
lcd.print(Exp);
//lcd.print("-");
lcd.setCursor(8,0);
lcd.print("In");
lcd.setCursor(11,0);
lcd.print(Intvl);

lcd.setCursor(0,1);
lcd.print("Sp");
lcd.setCursor(3,1);
lcd.print(Track);
//lcd.print("-");
lcd.setCursor(8,1);
lcd.print("Pn");
lcd.setCursor(11,1);
lcd.print(Pan);

delay(1000);
}