[DIY]自制Makeblock Orion相机

2015-11-4 19:54:57相机
42651
Makeblock Orion主控板的mcu是Atmel的328p,性能和资源比较有限。虽然勉强可以做普通8位摄像头数据采集,不过连线什么也比较乱。所以在大淘宝上找了一款串口控制和传输的摄像头,非常适合Arduino开发简单图像应用(家庭监控摄像头,植物生长的延时摄影)。
为了固定这个摄像头,用几个零件搭了个上下旋转的小支架。
Me Orion 主控板 x1
双孔梁 0824-032 x1
支架 3x3 x2
RJ25适配器 x1
串口摄像头 x1
铆钉、螺丝、RJ25线 若干
支架结构正面:
img01.jpg 支架结构背面:
img02.jpg

摄像头默认波特率是115200,由于示例程序使用的软串口,所以把摄像头波特率预先设置为19200。

Arduino的代码:
[C++] 纯文本查看 复制代码
#include "MeOrion.h"
#include <SoftwareSerial.h>

SoftwareSerial sw(8,2);
String buffer = "";
void setup() {
  Serial.begin(115200);
  sw.begin(19200);
}

double lastTime = 0;
bool isCapture = false;
int bytesSize = 0;
int bytesIndex = 0;
void loop() {
  if(Serial.available()){
    char c = Serial.read();
    if(c=='\n'){
      parseBuffer();
    }else{
      buffer+=c;
    }
  }
  if(sw.available()){
    Serial.write(sw.read());
  }
}
void parseBuffer(){
  buffer = buffer+"/";
  int count = 0;
  int startIndex = 0;
  int endIndex = 0;
  int len = buffer.length();
  if(len<1){
    return;
  }
  String tmp;
  String values[10];
  while(true) {
    startIndex = buffer.indexOf("/", endIndex);
    endIndex = buffer.indexOf("/", startIndex + 1);
    tmp = buffer.substring(startIndex+1, endIndex);
    values[count] = tmp;
    count++;
    if(endIndex==len-1) break;
  }
  if(values[0].equals("resolution")){
    cameraResolution(values[1].toInt());
  }else if(values[0].equals("clear")){
    cameraClear();
  }else if(values[0].equals("reset")){
    cameraReset();
  }else if(values[0].equals("capture")){
    cameraCapture();
  }else if(values[0].equals("quality")){
    cameraQuality(values[1].toInt());
  }else if(values[0].equals("request")){
    if(values[1].equals("length")){
      cameraGetLength();
    }else if(values[1].equals("buffer")){
      cameraGetBuffer(values[2].toInt(),values[3].toInt(),values[4].toInt(),values[5].toInt());
    }
  }else if(values[0].equals("baudrate")){
    cameraBaudrate(values[1].toInt());
  }
  buffer = "";
}
void cameraReset(){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x26);
  sw.write((unsigned char)0x0);
}
void cameraClear(){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x36);
  sw.write(0x01);
  sw.write(0x03);
}
void cameraResolution(unsigned char resolution){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x31);
  sw.write(0x05);
  sw.write(0x04);
  sw.write(0x01);
  sw.write((unsigned char)0x00);
  sw.write(0x19);
  if(resolution==0){
    sw.write(0x11);
  }else if(resolution==1){
    sw.write((unsigned char)0x00);
  }else if(resolution==2){
    sw.write(0x22);
  }
}
void cameraQuality(unsigned char quality){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x31);
  sw.write(0x05);
  sw.write(0x01);
  sw.write(0x01);
  sw.write(0x12);
  sw.write(0x04);
  sw.write(quality);
}
void cameraCapture(){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x36);
  sw.write(0x01);
  sw.write((unsigned char)0x0);
}
void cameraGetLength(){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x34);
  sw.write(0x01);
  sw.write((unsigned char)0x0);
}
void cameraGetBuffer(unsigned char s1, unsigned char s2, unsigned char e1, unsigned char e2){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x32);
  sw.write(0x0C);
  sw.write((unsigned char)0x00);
  sw.write(0x0A);
  sw.write((unsigned char)0x00);
  sw.write((unsigned char)0x00);
  sw.write(s1);
  sw.write(s2);
  sw.write((unsigned char)0x00);
  sw.write((unsigned char)0x00);
  sw.write(e1);
  sw.write(e2);
  sw.write((unsigned char)0x00);
  sw.write(0xFF);
}
void cameraBaudrate(unsigned char baudrate){
  sw.write(0x56);
  sw.write((unsigned char)0x0);
  sw.write(0x31);
  sw.write(0x06);
  sw.write(0x04);
  sw.write(0x02);
  sw.write((unsigned char)0x00);
  sw.write(0x08);
  if(baudrate==0){
    sw.write(0xAE);
    sw.write(0xC8);//9600
  }else if(baudrate==1){
    sw.write(0x56);
    sw.write(0xE4);//19200
  }else if(baudrate==2){
    sw.write(0x2A);
    sw.write(0xF2);//38400
  }else if(baudrate==3){
    sw.write(0x1C);
    sw.write(0x4C);//57600
  }else if(baudrate==4){
    sw.write(0x0D);
    sw.write(0xA6);//115200
  }
}
void urlencode(String input)
{
  input.replace("/","%2F");
}
void urldecode(String input)
{
  input.replace("%2F","/");
}


顺便提供一个开源的PC客户端软件采集图像(

installer_win.zip

267.52 KB, 下载次数: 892

1人收藏
1 条回帖
木果创客中级会员2015-11-4 22:28:04
好强大的虎子哥,学习了!
需要登陆后才可进行回复 登录

返回顶部
现在加入我们,注册一个账号 账号登陆 QQ账号登陆 微博账号登陆