Introduction: Timelapse Slider With VB

The aim of this first integration test with visual basic is to understand the basics. So, we are just going to make a small test application to control one motor and the camera shutter. You can download all project files and sketches here: http://timeblocks.wordpress.com/

Step 1: Download Visual Basic 2010 Express

Let´s start by downloading Visual Basic Express here.

Step 2: Open Visual Basic

Picture of Open Visual Basic

Follow the steps until you successfully install VB and then open it:

Step 3: New Project.

Picture of New Project.

Click new project, then click Windows Forms Application followed by ok:

Step 4: Buttons

Picture of Buttons

Drag four buttons from the toolbox into form1:

Step 5: Serial Port

Picture of Serial Port

Drag SerialPort element from toolbox into form1 :

Step 6: VB Code

Copy the following code:

Imports System.IO

Imports System.IO.Ports

Imports System.Threading

Public Class Form1

Shared _continue As Boolean

Shared _serialPort As SerialPort

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

SerialPort1.Close()

SerialPort1.PortName = “com3″ ‘change com port to match your Arduino port IMPORTANT

SerialPort1.BaudRate = 9600

SerialPort1.DataBits = 8

SerialPort1.Parity = Parity.None

SerialPort1.StopBits = StopBits.One

SerialPort1.Handshake = Handshake.None

SerialPort1.Encoding = System.Text.Encoding.Default

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button1.Click

SerialPort1.Open()

SerialPort1.Write(“1″)

SerialPort1.Close()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

SerialPort1.Open()

SerialPort1.Write(“0″)

SerialPort1.Close()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

SerialPort1.Open()

SerialPort1.Write(“3″)

SerialPort1.Close()

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
SerialPort1.Open()

SerialPort1.Write(“4″)

SerialPort1.Close()

End Sub

End Class

Step 7: Arduino Sketch

Upload the following code to the arduino board:

# define PIN_M1_DIRECTION_FW 7 // m1 forward

# define PIN_M1_DIRECTION_RV 8 // m1 reverse

# define PIN_M1_SPEED 5 // m1 speed

# define PIN_FOCUS 6 // focus

# define PIN_SHUTTER 9 // shutter

void setup() {

Serial.begin(9600);

pinMode(PIN_M1_DIRECTION_FW, OUTPUT);

pinMode(PIN_M1_DIRECTION_RV, OUTPUT);

pinMode(PIN_M1_SPEED, OUTPUT);

pinMode(PIN_FOCUS, OUTPUT);

pinMode(PIN_SHUTTER, OUTPUT);

}

void loop(){

while (Serial.available() == 0);

int val = Serial.read() – ‘0’;

f (val == 1) {

analogWrite(PIN_M1_SPEED, 255);

digitalWrite(PIN_M1_DIRECTION_FW, HIGH);

digitalWrite(PIN_M1_DIRECTION_RV, LOW);

}

else if (val == 0){

analogWrite(PIN_M1_SPEED, 0);

digitalWrite(PIN_M1_DIRECTION_FW, LOW);

digitalWrite(PIN_M1_DIRECTION_RV, LOW);

}

else if (val == 3) {

analogWrite(PIN_M1_SPEED, 255);

digitalWrite(PIN_M1_DIRECTION_FW, LOW);

digitalWrite(PIN_M1_DIRECTION_RV, HIGH);

}

else if (val == 4) {
digitalWrite(PIN_FOCUS, HIGH);

delay(100);

digitalWrite(PIN_SHUTTER, HIGH);

delay(100);

digitalWrite(PIN_FOCUS, LOW);

digitalWrite(PIN_SHUTTER, LOW);

delay(100);

}

else
{

}

Serial.println(val);

Serial.flush();

}

Step 8: Testing

Picture of Testing

Connect the camera and motor to tb.shield, push play in vb and test it.Now its time to play. Enjoy it.

Comments

MsSweetSatisfaction (author)2014-08-16

Nice, hope you got some cool shots. Thanks for sharing!

:-) Thanks. I´m working on it.