create account

Building a photography macro rail for focus stacking (Part 3 - Control with Blynk) by markangeltrueman

View this thread on steemit.com
· @markangeltrueman ·
$9.75
Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)
Hi and welcome to the third part in this series where I try not to electrocute myself or set fire to things in order to do some funky photography stuff.

Part 1 is [here](/@markangeltrueman/building-a-photography-macro-rail-for-focus-stacking-part-1-planning)
Part 2 is [here](@markangeltrueman/building-a-photography-macro-rail-for-focus-stacking-part-2-prototyping).

This is one of the coolest bits of this project - working out how to control the stepper motor with Blynk. Blynk (available from [https://blynk.io](https://blynk.io)) is an app that allows you to connect up with an absolute ton of IoT platforms and devices, one of which is the Arduino.

It's a bit hard to judge how much detail to put into posts like these so will give an overview and if you have any questions, please feel free to ask in the comments

#### Installation and configuration

<div class="pull-right">

![IMG_8FBDF3AE931A1.jpeg](https://files.steempeak.com/file/steempeak/markangeltrueman/jhhZUcC5-IMG_8FBDF3AE931A-1.jpeg)

</div>
The Blynk app in my project connects to a laptop on the same wifi network as my phone. The laptop is running a Blynk server which in turn connects over USB to the Arduino. The Arduino in-turn connects to the electronics on the breadboard as shown in the previous post and tells the motor to change direction or spin.

It's pretty easy to install Blynk to work on a local network with wifi; you need the app on your mobile device and the associated libraries on the server machine

I'm not going to go into detail about installation etc. as all of that detail is available on the Blynk site. What I will say is that getting the Blynk server to run on my mac was a bit of a pain to start with as it kept choosing the wrong port and device by default. The command I have to run from the `scripts` folder is

`sudo ./blynk-ser.sh -c /dev/cu.usbmodem14201 -p 9443`

This runs a local blynk server on port `9442` using device `cu.usbmodem14201` which is the USB port that my Arduino is plugged into. Once you have the running you end up with the below output.

![Screenshot 20191015 at 13.51.11.png](https://files.steempeak.com/file/steempeak/markangeltrueman/MXM4Ab0b-Screenshot202019-10-1520at2013.51.11.png)

<hr/>



So let's move onto creating the Blynk app and telling it how to get the Arduino to do things. 

The basic functionality that I want the app to do in the first version is

* Move the guide rail forwards and backwards 
* Have a manual mode where you set the distance you want to move forward and the number of photos you want to take 
* Have an auto mode where you set the start and end positions of the rail and the number of photos you want to take and the Arduino works out the distance and steps automatically

<div class="pull-right">

![IMG_5BE74E3684881.jpeg](https://files.steempeak.com/file/steempeak/markangeltrueman/9jTz20JK-IMG_5BE74E368488-1.jpeg)

</div>

To the right here you can see my Blynk app in "design mode". It's created using a drag and drop UI on the phone. You add buttons and other widgets and then assign them with "Virtual Pins" that can be communicated with from the Arduino code. For example, V0 is the button I'm using to move the motor forward and in the Arduino code this is handled like this

```
/*
   move forward
*/
BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
  if (pinValue == 1)
  {
    moveForward = true;
  }
  else
  {
    moveForward = false;
  }
}
```
So all im doing is setting a variable called `moveForward` to be `true` or `false` depending on if this button is pressed. It is the main Arduino loop that is constantly checking this value to see if it needs to move the motor forwards or not as shown in this code snippet here. the `loop()` is called continually from within the Arduino. You can also see the `moveBackward` variable check which calls `move(false)` to move the motor backwards and a `runIt` variable that is set by the "GO" button which calls `runProcess()` and does all the clever work.

```
void loop()
{

  Blynk.run();

  if (moveForward)
  {
    move(true);
  }

  if (moveBackward)
  {

    move(false);
  }

  if (runIt)
  {
    runIt = false; // stop it running more than once
    runProcess();
  }
}
```
The `move()` function is called for both move backwards or move forwards as well as the `runProcess()` clever stuff to move things around and looks like this.

```
void move(bool forwards)
{
  if (forwards)
    digitalWrite(dirPin, HIGH);
  else
    digitalWrite(dirPin, LOW);

  digitalWrite(stepPin, HIGH);
  delay(10);
  digitalWrite(stepPin, LOW);
  delay(10);

  if (forwards)
    currentStep++;
  else
    currentStep--;
}
```

It checks the direction passed into the function and then tells the Arduino to in turn tell the stepper motor driver to set the direction by setting `HIGH` or `LOW` on the `dirPin`. Then it sets the `stepPin` to `HIGH` and `LOW` to move the motor one step. The last bit keeps track of the current step position. I keep a track of step position so that I know where the start and end points are in full auto mode.

So for all of the controls on the page, a variable in the Arduino code is set and the loop does things depending on those variable values. I really don't want to go into every single bit of code. I'd rather just demonstrate what the system does at the moment. If you want to look at the code in its current state, you can check it out on github at [https://github.com/markptrueman/ArduinoMacroRail](https://github.com/markptrueman/ArduinoMacroRail)

Here is a video demonstration of some of the UI features and the system working in AUTO mode. I've added in an LED to simulate the camera shutter being fired.

https://www.youtube.com/watch?v=TKfMvZH_pg0&feature=youtu.be

The next step is to get hold of the guide rail and get this all set up with the stepper motor that comes with that. It could take a few weeks to get here from the USA.

Thanks for reading. Looking forward to getting this hooked up to an actual rail very soon. I'll be back to posting photos for the next few weeks.

Mark


👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 256 others
properties (23)
post_id80,910,954
authormarkangeltrueman
permlinkbuilding-a-photography-macro-rail-for-focus-stacking-part-3-control-with-blynk
categorycreativecoin
json_metadata{"app":"steempeak\/1.17.1","format":"markdown","tags":["creativecoin","steemstem","photography","arduino","macrophotography","diy","engineering","science","technology","electronics"],"users":["markangeltrueman"],"links":["\/@markangeltrueman\/building-a-photography-macro-rail-for-focus-stacking-part-1-planning","https:\/\/@markangeltrueman\/building-a-photography-macro-rail-for-focus-stacking-part-2-prototyping","https:\/\/blynk.io","https:\/\/github.com\/markptrueman\/ArduinoMacroRail"],"image":["https:\/\/files.steempeak.com\/file\/steempeak\/markangeltrueman\/jhhZUcC5-IMG_8FBDF3AE931A-1.jpeg","https:\/\/files.steempeak.com\/file\/steempeak\/markangeltrueman\/MXM4Ab0b-Screenshot202019-10-1520at2013.51.11.png","https:\/\/files.steempeak.com\/file\/steempeak\/markangeltrueman\/9jTz20JK-IMG_5BE74E368488-1.jpeg"]}
created2019-10-15 17:18:00
last_update2019-10-15 17:18:00
depth0
children8
net_rshares31,962,994,931,254
last_payout2019-10-22 17:18:00
cashout_time1969-12-31 23:59:59
total_payout_value4.965 SBD
curator_payout_value4.789 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length6,055
author_reputation38,705,954,145,809
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (320)
@c-squared ·
c-squared-comment
<div class="pull-left">https://cdn.steemitimages.com/DQmaSUWYsJ3AMUEMRqCSaoKJVNvtsbKm4fNAtmTidr8Uggc/C%20Squared%20Logo%20Transparency%20200px.png</div><br>This post was shared in the <a href="https://discord.gg/B8JFmJ4">Curation Collective Discord community</a> for curators, and upvoted and resteemed by the @c-squared community account after manual review.<br/>@c-squared runs a <a href="https://steemit.com/witness/@c-cubed/announcing-the-launch-of-the-new-c-squared-witness">community witness</a>. Please consider using one of your witness votes on us <a href ="https://steemconnect.com/sign/account-witness-vote?witness=c-squared&approve=true">here</a>
properties (22)
post_id80,918,580
authorc-squared
permlink20191015t233753130z
categorycreativecoin
json_metadata{"tags":["c-squared"]}
created2019-10-15 23:46:30
last_update2019-10-15 23:46:30
depth1
children0
net_rshares0
last_payout2019-10-22 23:46:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length658
author_reputation4,761,872,663,008
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@carlgnash ·
nice progress, hopefully you don't get the same delivery driver delivering the rail as your camera :joy:  @tipu curate
👍  
properties (23)
post_id80,941,236
authorcarlgnash
permlinkre-markangeltrueman-pzhe2x
categorycreativecoin
json_metadata{"tags":["creativecoin"],"app":"steempeak\/1.18.0"}
created2019-10-16 18:59:24
last_update2019-10-16 18:59:24
depth1
children1
net_rshares92,765,306,369
last_payout2019-10-23 18:59:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length118
author_reputation61,188,057,575,182
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@tipu ·
<a href="https://tipu.online/curator?carlgnash" target="_blank">Upvoted &#128076;</a>
properties (22)
post_id80,941,244
authortipu
permlinkre-re-markangeltrueman-pzhe2x-20191016t185941
categorycreativecoin
json_metadata{}
created2019-10-16 18:59:42
last_update2019-10-16 18:59:42
depth2
children0
net_rshares0
last_payout2019-10-23 18:59:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length85
author_reputation43,763,405,635,383
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@digitalis ·
awesome project :) i did bought a mini cnc from ebay, 2 years ago. that uses nema17 too i think. it has A4988 driver too. minimum resolution it can do is 0.01mm.
👍  
properties (23)
post_id80,962,197
authordigitalis
permlinkpzitap
categorycreativecoin
json_metadata{"app":"steemit\/0.1"}
created2019-10-17 13:25:39
last_update2019-10-17 13:25:39
depth1
children0
net_rshares92,636,694,199
last_payout2019-10-24 13:25:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length161
author_reputation47,375,690,794,265
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)
@steemstem ·
re-markangeltrueman-building-a-photography-macro-rail-for-focus-stacking-part-3-control-with-blynk-20191017t145354309z
<div class='text-justify'> <div class='pull-left'> <center> <br /> <img width='200' src='https://res.cloudinary.com/drrz8xekm/image/upload/v1553698283/weenlqbrqvvczjy6dayw.jpg'> </center>  <br/> </div> 

This post has been voted on by the **SteemSTEM curation team** and voting trail. It is elligible for support from @curie and @minnowbooster.<br /> 

If you appreciate the work we are doing, then consider supporting our witness [@stem.witness](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=stem.witness). Additional witness support to the [curie witness](https://steemconnect.com/sign/account_witness_vote?approve=1&witness=curie) would be appreciated as well.<br /> 

For additional information please join us on the [SteemSTEM discord]( https://discord.gg/BPARaqn) and to get to know the rest of the community!<br />

Please consider using the <a href='https://www.steemstem.io'>steemstem.io</a> app and/or including @steemstem in the list of beneficiaries of this post. This could yield a stronger support from SteemSTEM.
properties (22)
post_id80,964,679
authorsteemstem
permlinkre-markangeltrueman-building-a-photography-macro-rail-for-focus-stacking-part-3-control-with-blynk-20191017t145354309z
categorycreativecoin
json_metadata{"app":"steemstem-bot"}
created2019-10-17 14:53:57
last_update2019-10-17 14:53:57
depth1
children0
net_rshares0
last_payout2019-10-24 14:53:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,050
author_reputation214,343,891,436,406
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steemitboard ·
<center>[![](https://steemitimages.com/175x175/http://steemitboard.com/@markangeltrueman/level.png?201910182039)](https://steemitboard.com/@markangeltrueman)
**Congratulations @markangeltrueman**!
You raised your level and are now a **Minnow**!</center>

###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
properties (22)
post_id81,002,272
authorsteemitboard
permlinksteemitboard-notify-markangeltrueman-20191018t213536000z
categorycreativecoin
json_metadata{"image":["https:\/\/steemitboard.com\/img\/notify.png"]}
created2019-10-18 21:35:36
last_update2019-10-18 21:35:36
depth1
children0
net_rshares0
last_payout2019-10-25 21:35:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length432
author_reputation34,058,241,623,249
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@guchtere ·
Wow your project is going fast!
The Blynk software looks pretty damn easy to create beautiful things together with Arduino. Never knew it was that easy!

Looking forward to part 4!😎
👍  ,
properties (23)
post_id81,101,996
authorguchtere
permlinkpzs0rt
categorycreativecoin
json_metadata{"app":"steemit\/0.1"}
created2019-10-22 12:45:30
last_update2019-10-22 12:45:30
depth1
children1
net_rshares2,730,194,046
last_payout2019-10-29 12:45:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length181
author_reputation25,183,211,396,485
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@markangeltrueman ·
Still researching the right rail and where to get it from. Accuracy can be a problem with the cheaper ones.
properties (22)
post_id81,108,986
authormarkangeltrueman
permlinkre-guchtere-pzsd3k
categorycreativecoin
json_metadata{"tags":["creativecoin"],"app":"steempeak\/1.18.0"}
created2019-10-22 17:11:48
last_update2019-10-22 17:11:48
depth2
children0
net_rshares0
last_payout2019-10-29 17:11:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length107
author_reputation38,705,954,145,809
root_title"Building a photography macro rail for focus stacking (Part 3 - Control with Blynk)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000