基于ESP8266的无线快门线
2019-07-06962
AI 快速预览详细
基于ESP8266的无线快门线项目使用FireBeetle ESP8266 WiFi物联网开发板,通过简单的连线和代码配置,实现索尼A6000相机的远程控制。该项目包括硬件连接、快门代码和web服务器代码。硬件部分需要将FireBeetle ESP8266开发板与索尼multi USB端子连接,并设置相应的引脚。快门代码采用Ticker库定时,通过拉低引脚实现快门和对焦功能。web服务器代码则提供了简单的网页界面,用户可以设置拍摄间隔、对焦时间和曝光时间。此外,还提到了移动电源自动关机的问题及其解决方案。
步骤1 连线
相机为索尼A6000,快门线为索尼自由Multiport接口,其定义参考https://www.studio1productions.com/parts/sony-multiport-connector.htm。
Pin4为快门,连接至IO12;Pin5为对焦,连接至IO0;PinA5为地线,连接GND。填点热熔胶,电工胶布绕一下保护接头,至此硬件部分施工完成。
步骤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 可能的问题




