回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

基于ESP8266的无线快门线 简单

头像 DFH12ZJ2z37 2019.07.06 780 0

材料清单

  • FireBeetle ESP8266 WiFi 物联网开发板 X1 链接
  • 索尼multi USB端子 X1 链接
  • 导线 X3

步骤1 连线

相机为索尼A6000,快门线为索尼自由Multiport接口,其定义参考https://www.studio1productions.com/parts/sony-multiport-connector.htm

Pin4为快门,连接至IO12;Pin5为对焦,连接至IO0;PinA5为地线,连接GND。填点热熔胶,电工胶布绕一下保护接头,至此硬件部分施工完成。



project-image

步骤2 快门代码

采用Ticker库定时,快门与对焦拉低生效。采用内部LED作为指示灯。

代码
#include <Ticker.h>


Ticker tickerCycle;
Ticker tickerShoot;
Ticker tickerReset; //其实tickerReset与tickerShoot可合并

static const int PIN_FOCUS = 0;  
static const int PIN_SHOOT = 12; 

static int t_focus = 100;  //对焦时间(ms),半按快门对焦的时间,需要足够时间给镜头对焦
static int t_shoot = 100;  //曝光时间(ms),B门有效,否则为相机设置,PIN_SHOOT拉低开始计时
static int t_cycle = 2000; //定时周期(ms),隔多久按下快门

void cable_led(bool o) {
  //采用内置LED指示对焦动作
  digitalWrite(LED_BUILTIN, o ? LOW : HIGH);
}

void cable_focus() {
  cable_led(true);
  digitalWrite(PIN_FOCUS, LOW); 
  tickerShoot.once_ms(t_focus, cable_shoot);
}

void cable_shoot() {
  cable_led(false);
  digitalWrite(PIN_SHOOT, LOW);
  tickerReset.once_ms(t_shoot, cable_reset); // 定时器精度不高,但B门都是30s以上曝光的,精度够用
}

void cable_reset() {
  cable_led(false);
  digitalWrite(PIN_FOCUS, HIGH);
  digitalWrite(PIN_SHOOT, HIGH);
}


void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(PIN_FOCUS, OUTPUT);
  pinMode(PIN_SHOOT, OUTPUT);
  cable_reset();
  setupServer(); // 启用服务器,详见服务器相关代码
}


void loop() {
 server.handleClient(); // 服务器处理
}

步骤3 web服务器代码

参考示例代码写了个简单的网页服务器,ESP8266的处理器不够给力,略卡顿。换成ESP32应该能有较大改善。

代码
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "********";
const char *password = "********";

ESP8266WebServer server(80);
/*
 * Web Server Handlers
 */
static const char* tmp_main = "<html>\
  <head>\
    <meta charset='utf-8'>\
    <style>\
      h1{text-align:center;font-size:5vh;}\
      input{width:100%;font-size:3vh}\
      form{font-size:3vh;margin:5%;}\
    </style>\
  </head>\
  <body>\
    <h1>Remote Cable</h1>\
    <form action='/start' method='GET'>\
      拍摄间隔(ms): <br>\
      <input type='number' name='cycle' min='500' value=%d><br>\
      对焦时间(ms): <br>\
      <input type='number' name='focus' min='100' value=%d><br>\
      曝光时间(ms): <br>\
      <input type='number' name='shoot' min='100' value=%d><br>\
      <input type='submit' value='拍摄'><br>\
      <a href='/stop'><input type='button' value='停止'></a>\
    </form>\
  </body>\
</html>";

static const char* page_start = "<html>\
  <head><meta charset='utf-8' http-equiv='refresh' content='1;url=/'/></head>\
  <body><h1>STARTED</h1></body>\
</html>";

static const char* page_stop = "<html>\
  <head><meta charset='utf-8' http-equiv='refresh' content='1;url=/'/></head>\
  <body><h1>STOPPED</h1></body>\
</html>";

static char page[1024];


void handleRoot() {
  server.send(200, "text/html", page);
}
void handleStart(){
  t_cycle = server.arg("cycle").toInt();
  t_focus = server.arg("focus").toInt();
  t_shoot = server.arg("shoot").toInt();
  tickerCycle.attach_ms(t_cycle, cable_focus);
  server.send(200, "text/html", page_start);
  snprintf(page, 1023, tmp_main, t_cycle, t_focus, t_shoot);
}
void handleStop(){
  tickerCycle.detach();
  server.send(200, "text/html", page_stop);
}
void handleNotFound() {
  String message = "File Not Found\n\n";
  message += server.uri();
  message += "\n";
  server.send ( 404, "text/plain", message );
}


void setupServer(){
  delay(1000);
  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(IPAddress(10,10,1,1), //将IP改成10.10.1.1,方便输入,23333
                    IPAddress(10,10,1,1),
                    IPAddress(255,255,255,0));
  snprintf(page, 1023, tmp_main, t_cycle, t_focus, t_shoot);
  server.on("/", handleRoot);
  server.on("/start", handleStart);
  server.on("/stop", handleStop);
  server.onNotFound(handleNotFound);
  server.begin();
}

步骤4 可能的问题

移动电源自动关机

由于ESP8266的电流较小,可能导致移动电源自动关机,目前采用移动电源同时接相机假电池的方式增大负载。

可以考虑外接锂电池,不过要带额外的电池比较麻烦

对焦时间

部分镜头对焦速度慢,需要预留对焦时间,一般延时摄影采用手动对焦,可以设置一个很小的值。

评论

user-avatar