Arduino code for the Camera Slider.


Recently i have gotten some request for sharing the Arduino code for my homemade camera slider.

To start with i just want to say, I’m no master in this, so there can be bugs, and the code is still early and not complete.
Recently i haven’t had much time for these kind of projects, so it has been still for a while.

camera slider controller

 

 

You can see the serie below here.

If you like the videos please consider liking and sharing the videos, that will keep me working on these projects.

[wp_paypal_payment]

Camera_Slider.ino

#include "Timer.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include "SWTFT.h" // Hardware-specific library
#include <TouchScreen.h>

int pin02 = 11;
Timer t;

int tid=1000;
int stepspeed=1000;
int steplenght=10;
boolean stepdirection=LOW;

char buf[12];

int dirpin = 9;
int steppin = 10;

int interrupt_pin = 12;

int eventid;

bool runok = false;

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 60
#define TS_MAXX 1230
#define TS_MAXY 690



#define MINPRESSURE 10
#define MAXPRESSURE 1000

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);




SWTFT tft;

  void takeReading()
{
  runstepper();
  delay(250);
  digitalWrite(pin02, !digitalRead(pin02));
  delay(250);
  digitalWrite(pin02, !digitalRead(pin02));
}


  void runstepper()
  {
    int i;
    digitalWrite(dirpin, stepdirection);     // Set the direction.
    
   
   for (i = 0; i<steplenght; i++)       // Iterate for 4000 microsteps.
  {
    if(runok)
    {
    digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
    delayMicroseconds(steplenght);
    digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
    delayMicroseconds(stepspeed);      // This delay time is close to top speed for this
    }
    
  }  
  }


void stopall()
{
        t.stop(eventid);
        tft.setCursor(80, 100);
        tft.setTextColor(BLUE);  tft.setTextSize(2);
        tft.println("Stop");    
            
        delay(250);             
        tft.setCursor(80, 100);
        tft.setTextColor(WHITE);  tft.setTextSize(2);
        tft.println("Stop"); 
}


void InitialiseIO(){

  pinMode(A5, INPUT);    // Pin A2 is input to which a switch is connected
  digitalWrite(A5, HIGH);   // Configure internal pull-up resistor
}

void InitialiseInterrupt(){
  cli();    // switch interrupts off while messing with their settings  
  PCICR =0x02;          // Enable PCINT1 interrupt
  PCMSK1 = 0b00100000;
  sei();    // turn interrupts back on
}

ISR(PCINT1_vect) {    // Interrupt service routine. Every single PCINT8..14 (=ADC0..5) change
            // will generate an interrupt: but this will always be the same interrupt routine
  runok = false;
  if (digitalRead(A5)==0)  Serial.println("A5");
  stopall();
}




Grapichs.ino

#define BOXSIZE_S 40
#define BOXSIZE 60
#define BOXSIZE_L 80

void Text()
  {
    tft.fillScreen(WHITE);
    
    //  Makes white line to make a Button   
    tft.fillRect(0, 0, BOXSIZE, BOXSIZE+BOXSIZE, GREEN); //Start
    tft.drawRect(0, 0, BOXSIZE, BOXSIZE+BOXSIZE, WHITE); //Start
        tft.setCursor(20, 10);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("S");
        //Second value
        tft.setCursor(20, 30);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("T");
        //Third value
        tft.setCursor(20, 50);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("A");
        //Fifth value
        tft.setCursor(20, 70);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("R");
        tft.setCursor(20, 90);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("T");
    
    tft.fillRect(0, BOXSIZE*2, BOXSIZE, BOXSIZE+BOXSIZE, RED); //stop
    tft.drawRect(0, BOXSIZE*2, BOXSIZE, BOXSIZE+BOXSIZE, WHITE); //stop
    
        tft.setCursor(20, 140);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("S");
        //Second value
        tft.setCursor(20, 160);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("T");
        //Third value
        tft.setCursor(20, 180);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("O");
        //Fifth value
        tft.setCursor(20, 200);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("P");
    
        
    // Right Arrow Boxes *****************************************************************************
        tft.drawRect(260, 0, BOXSIZE, BOXSIZE, BLACK); // +1sec
        tft.drawRect(260, BOXSIZE, BOXSIZE, BOXSIZE, BLACK); // +1speed
        tft.drawRect(260, BOXSIZE*2, BOXSIZE, BOXSIZE, BLACK); // +1Lenght
        tft.drawRect(260, BOXSIZE*3, BOXSIZE, BOXSIZE, BLACK); // Right Direction  

        //First arrow
        tft.setCursor(280, 22);
        tft.setTextColor(RED);  tft.setTextSize(3);
        tft.println("+");
        //Second arrow
        tft.setCursor(280, 80);
        tft.setTextColor(RED);  tft.setTextSize(3);
        tft.println("+");
        //Third Arrow
        tft.setCursor(280, 142);
        tft.setTextColor(RED);  tft.setTextSize(3);
        tft.println("+");
        //Fifth arrow
        tft.setCursor(280, 200);
        tft.setTextColor(BLACK);  tft.setTextSize(3);
        tft.println(">");
        
    //******************************************************************************************************

    // Value Boxes *****************************************************************************************
//        tft.drawRect(220, 0, BOXSIZE_S, BOXSIZE, BLACK); // +1sec
//        tft.drawRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, BLACK); // +1speed
//        tft.drawRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, BLACK); // +1Lenght
//        tft.drawRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, BLACK); // Right Direction  

        //First value
        tft.setCursor(235, 22);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println(itoa(tid/1000, buf, 10));
//        tft.println("1");
        //Second value
        tft.setCursor(235, 80);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println(itoa(stepspeed/100, buf, 10));
//        tft.println("2");
        //Third value
        tft.setCursor(235, 142);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
//        tft.println("3");
        tft.println(itoa(steplenght/100, buf, 10));
        //Fifth value
        tft.setCursor(235, 200);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tft.println("L");
        
    //******************************************************************************************************

    // Left Arrow Boxes *****************************************************************************
        tft.drawRect(160, 0, BOXSIZE, BOXSIZE, BLACK); // +1sec
        tft.drawRect(160, BOXSIZE, BOXSIZE, BOXSIZE, BLACK); // +1speed
        tft.drawRect(160, BOXSIZE*2, BOXSIZE, BOXSIZE, BLACK); // +1Lenght
        tft.drawRect(160, BOXSIZE*3, BOXSIZE, BOXSIZE, BLACK); // Right Direction  

        //First arrow
        tft.setCursor(180, 22);
        tft.setTextColor(BLUE);  tft.setTextSize(3);
        tft.println("-");
        //Second arrow
        tft.setCursor(180, 80);
        tft.setTextColor(BLUE);  tft.setTextSize(3);
        tft.println("-");
        //Third Arrow
        tft.setCursor(180, 142);
        tft.setTextColor(BLUE);  tft.setTextSize(3);
        tft.println("-");
        //Fifth arrow
        tft.setCursor(180, 200);
        tft.setTextColor(BLACK);  tft.setTextSize(3);
        tft.println("<");
        
    //******************************************************************************************************

    // TEXT ************************************************************************************************
        tft.setCursor(70, 22);
        tft.setTextColor(BLACK);  tft.setTextSize(1);
        tft.println("Time / Seconds");

        tft.setCursor(70, 80);
        tft.setTextColor(BLACK);  tft.setTextSize(1);
        tft.println("Speed");

        tft.setCursor(70, 142);
        tft.setTextColor(BLACK);  tft.setTextSize(1);
        tft.println("Lenght / Travel");

        tft.setCursor(70, 200);
        tft.setTextColor(BLACK);  tft.setTextSize(1);
        tft.println("left/Right");

        tft.setCursor(70, 230);
        tft.setTextColor(BLACK);  tft.setTextSize(1);
        tft.println("V. 1.0");


















    
    


//    tft.setCursor(BOXSIZE_L+30, 23);
//    tft.setTextColor(WHITE);  tft.setTextSize(3);
//    tft.println(itoa(tid/1000, buf, 10));

    // Plus one second button text **************
      
      
    //*******************************************
    
//    tft.setCursor(0, 100);
//    tft.setTextColor(GREEN);  tft.setTextSize(4);
//    tft.println(" Pixeljunk.dk");
  

    

  
   
  }

Loop.ino

void loop() 
{

  // Recently Point was renamed TSPoint in the TouchScreen library
  // If you are using an older version of the library, use the
  // commented definition instead.
  // Point p = ts.getPoint();
  TSPoint p = ts.getPoint();

  t.update();
  pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  pinMode(YM, OUTPUT);

  

int i;



  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) 
  {
    // scale from 0->1023 to tft.width
    p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, tft.width(), 0));
    p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
   
    if (p.z > ts.pressureThreshhold) {
   Serial.print("Y = "); Serial.print(p.y);      
   Serial.print("\tX = "); Serial.print(p.x);  //  \t= space
   Serial.print("\tPressure = "); Serial.println(p.z);
   delay(100); //just to slow down the readings a little bit
   }
    // Start Button       
    if (p.y > 0 && p.y < 60 && p.x > 0 && p.x < 110) 
      {
        runok = true;
        tft.setCursor(80, 100);
        tft.setTextColor(BLUE);  tft.setTextSize(2);
        tft.println("Start");
         eventid = t.every(tid, takeReading);                     
        delay(500);
        tft.setCursor(80, 100);
        tft.setTextColor(WHITE);  tft.setTextSize(2);
        tft.println("Start");
          
      }
      
    // Stop Button       
    if (p.y > 0 && p.y < 60 && p.x > 110 && p.x < 224) 
      {
        Serial.print("Stop");
        stopall();
      }   

    // Minus seconds Button       
    if (p.y > 170 && p.y < 230 && p.x > 0 && p.x < 50) 
      {
        tft.fillRect(220, 0, BOXSIZE_S, BOXSIZE, WHITE);
        tft.setCursor(235, 22);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tid-=1000;
        tft.println(itoa(tid/1000, buf, 10));
        Serial.println(tid);
        //delay(250);
      }   
    
    // Plus seconds Button       
    if (p.y > 270 && p.y < 335 && p.x > 0 && p.x < 50) 
      {
        tft.fillRect(220, 0, BOXSIZE_S, BOXSIZE, WHITE);
        tft.setCursor(235, 22);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        tid+=1000;
        tft.println(itoa(tid/1000, buf, 10));
        Serial.println(tid);
        //delay(250);
      }   
    
    // Minus speed button       
    if (p.y > 170 && p.y < 230 && p.x > 50 && p.x < 110) 
      {
        tft.fillRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, WHITE);
        tft.setCursor(235, 80);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        stepspeed+=100;
        tft.println(itoa(stepspeed/100, buf, 10));
        Serial.println(stepspeed);
        delay(250);
      }
      
    // Plus speed button       
    if (p.y > 270 && p.y < 335 && p.x > 50 && p.x < 110) 
      {
        tft.fillRect(220, BOXSIZE, BOXSIZE_S, BOXSIZE, WHITE);
        tft.setCursor(235, 80);
        tft.setTextColor(BLACK);  tft.setTextSize(2);
        stepspeed-=100;
        tft.println(itoa(stepspeed/100, buf, 10));
        Serial.println(stepspeed);
        delay(250);
      }
      
    // minus Lenght  button       
    if (p.y > 170 && p.y < 230 && p.x > 110 && p.x < 170) 
      {
       tft.fillRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, WHITE);
       tft.setCursor(235, 142);
       tft.setTextColor(BLACK);  tft.setTextSize(2);
       steplenght-=10;
       tft.println(itoa(steplenght/10, buf, 10));
       Serial.println(steplenght);
       delay(250);
       
      }
      
    // Plus Lenght  Button       
    if (p.y > 270 && p.y < 335 && p.x > 110 && p.x < 170) 
      {
       tft.fillRect(220, BOXSIZE*2, BOXSIZE_S, BOXSIZE, WHITE);
       tft.setCursor(235, 142);
       tft.setTextColor(BLACK);  tft.setTextSize(2);
       steplenght+=10;
       tft.println(itoa(steplenght/10, buf, 10));
       Serial.println(steplenght);
       delay(250);
      }
    
    // Right Button        
    if (p.y > 170 && p.y < 230 && p.x > 170 && p.x < 230) 
      {
       tft.fillRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, WHITE);
       tft.setCursor(235, 200);
       tft.setTextColor(BLACK);  tft.setTextSize(2);
       tft.println("R");
       stepdirection=HIGH;
       Serial.print("Right");
       Serial.print(stepdirection);
    
      }
    // Left Button       
    if (p.y > 270 && p.y < 335 && p.x > 170 && p.x < 230) 
      {
       tft.fillRect(220, BOXSIZE*3, BOXSIZE_S, BOXSIZE, WHITE);
       tft.setCursor(235, 200);
       tft.setTextColor(BLACK);  tft.setTextSize(2);
       tft.println("L");
       stepdirection=LOW;
       Serial.print("Right");
       Serial.print(stepdirection);
      }
                     
    }
  }

Setup.ino

  void setup() 
  {
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));
  pinMode(dirpin, OUTPUT);
  pinMode(steppin, OUTPUT);
  pinMode(pin02, OUTPUT);
  digitalWrite(pin02, HIGH);
  tft.reset();
  uint16_t identifier = tft.readID();
  Serial.print(F("LCD driver chip: "));
  Serial.println(identifier, HEX);
  tft.begin(identifier);
  tft.setRotation(1);
  Text();

  InitialiseIO();
  InitialiseInterrupt();

  }

 

You can download them here in a rar file.

Camera_slider

 

Libraries i use is.

http://srmonk.blogspot.com/2012/01/arduino-timer-library.html

SWTFT-Shield

https://github.com/ehubin/Adafruit-GFX-Library

Touch-Screen-Library-master

 

I am working on a new version, but at the moment it is far away from finished.

I hope this can help someone 🙂  Please leave a comment if you have any suggestion or correction to the code, or want to help build the new version for the camera slider

 

 

logo

Related posts

Camera Gimbal Update.

Camera Gimbal Update.


Camera Gimbal Update.

Update I released the next part of the Camera Gimbal build. https://youtu.be/OFVIN5ThFhM It's taken a little while longer to build that i anticipated, i haven't had much time for this project but it is moving forward slowly. I need to build the handle, and mount the electronics properbly...

Camera Slider Schematics

Camera Slider Schematics


Camera Slider Schematics

Wiring diagram for My camera Slider build. The stepper motors wiring is dependent on witch stepper motor you use, so for that you have to examine how the wire it to the EasyDriver. Also the relay is wired but how you wire it to your camera is also something you have to examine to your...

Making a Concrete Table.

Making a Concrete Table.


Making a Concrete Table.

Homemade Concrete table. I was looking for a new coffee table for my living room, because the old one was well used, but i could find one i like, or could afford. So what to do ?  Well i decided to build my own and it went quite well i think :) I wanted something with a rustic look, so...

Battery Pack From Old Laptop

Battery Pack From Old Laptop


Battery Pack From Old Laptop

Make a 3S battery from old Laptop Battery I needed a battery for my gimbal, and wanted to make it as small as possible and still have enough power to run the gimbal properly. The top bar of the gimbal is an old carbon bike handlebar. And I thought it would be cool to have the battery inside...

Camera Slider – Controlled by Arduino

Camera Slider - Controlled by Arduino


Camera Slider - Controlled by Arduino

Camera Slider Build. This article is about how i made my own smart camera slider, i wanted to build my own camera slider that would be used for both video and timelapse photography. I spend a lot of time looking for parts for the build, and found the most of the parts i used in China, and i...

Mostly Printed CNC(MPCNC) Project

Mostly Printed CNC(MPCNC) Project


Mostly Printed CNC(MPCNC) Project

My newest project is building the mostly printed CNC machine. Created by vicious1 My goal with this is to share what I experienced with this build so other maybe benefit from it. I am certainly not an expert on CNC machines. and all of this has been a learning experience for me. I choose...

18 Comments

  1. Adam Hults June 22, 2016
    Reply

    i cant get the swyft-sheild to work because its a rar

  2. clemens August 22, 2016
    Reply

    i have a big problem…. i can’t run the adurino with the code u give us

    it said #include // Core graphics library

    pls can u send me all file that i need in a rar datei pls

  3. Paw Pedersen August 23, 2016
    Reply

    Hello Clemens
    I will look into it tonight, can you send a screenshot of the error ?

  4. Manousos October 12, 2016
    Reply

    hello from greece, i get this error when upaloading to arduino

    ” C:\Users\Manosos-PC\Desktop\arduino-1.6.12\libraries\Adafruit-GFX-Library-master\glcdfont.c:9:23: error: variable ‘font’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

    static unsigned char font[] PROGMEM = {

    ^

    exit status 1
    Error compiling for board Arduino/Genuino Uno. ”

    please advise

  5. Paw Pedersen October 12, 2016
    Reply

    Hello Manousos

    My project is here, you can try this.
    https://1drv.ms/f/s!Amn2Eegz7CpXgp0BK2RLFfDzRdizmw

  6. Manousos October 12, 2016
    Reply

    Downloaded and uploaded to arduino but no graphics

    https://www.dropbox.com/s/8udf34jkrt89020/2016-10-12%2015.18.29.jpg?dl=0

    why?

  7. Manousos October 13, 2016
    Reply

    need help. got other code to work but not yours.

  8. manousos October 16, 2016
    Reply

    Hello again from Greece. Found a solution to make the code work. replaced the swtft part of the code with another tft code. required some work to make it work but ok. if anyone is interested i will upload the code. will come back with photos or video of the working project. thank you Paw Pedersen for the idea.

    • khaled November 30, 2016
      Reply

      Hi, I have same your problem
      can you tell me how you solve it.

  9. Paw Pedersen October 17, 2016
    Reply

    Sounds good you got it working, if you want to share it here you can send it to me. i’m looking forward to seeing some pictures of your project.

  10. Rogier Hoogmolen February 12, 2017
    Reply

    Hellow Paw Pedersen, I really like your project so i bought all the parts for the arduino, but when i install the code and the correct libraries i only get a blank screen no buttons whatsever.

  11. Rogier Hoogmolen February 14, 2017
    Reply

    Hello Paw, I’ve got every thing working except the display on the tft screen the touchscreen is working but i don’t get any graphics shown. can you please give a hand? I’m not really familiar with coding u see. https://www.elecrow.com/wiki/index.php?title=2.8%27%27_TFT_Touch_Shield#Pins_usage_on_Arduino is the tft screen used but i’m not able to get it working with your code. How can i check what pins to use for the graphics and so on. if you could give me a push in the right direction.

  12. Ján Jenča February 16, 2017
    Reply

    Hello, I’ve done everything as it should be but the touch is a mirror . What should I do ??

  13. Jesus Lorenzo January 26, 2018
    Reply

    Hello your code gives me this error, please help.

    Arduino:1.8.4 (Mac OS X), Tarjeta:”Arduino/Genuino Uno”

    Opciones de compilación cambiadas, reconstruyendo todo
    /Users/jesus/Documents/Arduino/libraries/SWTFT-Shield/SWTFT.cpp: In member function ‘void SWTFT::drawLine3Byte(int16_t, int16_t, int16_t, int16_t, uint8_t, uint8_t, uint8_t)’:
    /Users/jesus/Documents/Arduino/libraries/SWTFT-Shield/SWTFT.cpp:629:16: error: ‘swap’ was not declared in this scope
    swap(x0, y0);
    ^
    /Users/jesus/Documents/Arduino/libraries/SWTFT-Shield/SWTFT.cpp:634:16: error: ‘swap’ was not declared in this scope
    swap(x0, x1);
    ^

Leave a Reply