Продублирую свои наработки по сбору информации по созданию на Arduino, пульта управления, на базе LANC протокола, для видеокамер Sony http://86rc89.com/viewtopic.php?f=19&t=987 ==================================================================
/* * Arduino LANC zoom controller - AKA Zoomduino * By Angus Findlay * Using code from Brady Marks of Furious Green Lab * Connections: * LANC 2.5mm plug sleeve to Arduino Ground * LANC 2.5mm plug ring to Arduino Vin (input to regulator, NOT 5V) * LANC 2.5mm plug tip to Arduino Digital Pin 2 * Potentiometer wiper to Arduino Analog Pin 0 * Potentiometer outer to Arduino 5V and Ground, switch polarity to reverse zoom direction. * This provides a voltage divider to determine which code to send the camera. * * This code has only been tested with a Canon XH-A1, and is provided entirely without warranty or guarantee. * I hope it's useful for people, but if it isn't, I won't be held responsible. * Released under the GPL. * * Angus Findlay * angus@(domain on the next line) * www.findlayproductions.ca * December 28, 2008 * */
/* * Copyright (C) 2006 Free Software Foundation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * See file LICENSE for further informations on licensing terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * @author: Brady Marks <brady@furiousgreencloud.com> * documentation of LANC from http://www.boehmel.de/lanc.htm * @date: 2008-05-22 * @locations: Furious Green Lab, Vancouver, British Columbia, Canada */ int speeds[18]= /*These are the commands sent to the camera. 99 tells the code to send nothing.*/ { 0x0e,0x0c,0x0a,0x08,0x06,0x04,0x02,0x00, /*Zoom tele, from fastest to slowest*/ 99,99,99, /*Dead zone*/ 0x10,0x12,0x14,0x16,0x18,0x1a,0x1e}; /*Zoom wide, from slowest to fastest*/
// define pin modes for tx, rx, led pins: pinMode(lancPin, INPUT); pinMode(aPin,INPUT); pinMode(13,OUTPUT); digitalWrite(13,1);
}
int commandCode = 0;
void loop() { commandCode=speeds[map(analogRead(aPin),0,1023,0,17)]; //The analog input returns from 0 to 1023, but our array is from 0 to 17. This converts the values.
if (commandCode == 99) return; // If the pot is in the middle, send nothing. SendCode(40,commandCode); SendCode(40,commandCode); }
void SendCode(int type,int code) { frameStartBitWait(); writeByte(lancPin,type,bitMicroSeconds); // Video Cam Control lowWait(lancPin); writeByte(lancPin,code,bitMicroSeconds); // Tele/Wide etc }
byte readByte(int pin,unsigned long uSec /* bit width*/ ) { byte result = 0; delayMicroseconds(uSec * 1.5); // skips the Start Bit and Land in the midlle of the first byte
for (int i = 0; i < 8; i++) { if (digitalRead(pin) == LOW) { // == *LOW* because bits inverted in LANC result++; } result <<= 1; delayMicroseconds(uSec); } delayMicroseconds(0.5*uSec); return result; // return happens at end of last (8ths) bit }
void writeByte(int pin, byte value, unsigned uSec /* bit width */) { delayMicroseconds(uSec); // wait for stop bit pinMode(pin,OUTPUT); for (int i = 0; i < 8; i++) { boolean bit = value & 0x1; digitalWrite(pin,!bit); // NOT (!) pin because all data is inverted in LANC value >>= 1; delayMicroseconds(uSec); } pinMode(pin,INPUT); // return happends at end of last (8th) bit }
Спаял, работает, теперь надо облагораживать, да на штатив
Сделал дистанку на базе Wii нунчака, джойстиком зумим, кнопками запись и фото.
Код:
#include <Wire.h> #include "nunchuck_funcs_m2.h" int x,y, zb, cb,jx,jy,jy2;
/* * Arduino LANC zoom controller - AKA Zoomduino * By Angus Findlay * Using code from Brady Marks of Furious Green Lab * Connections: * LANC 2.5mm plug sleeve to Arduino Ground * LANC 2.5mm plug ring to Arduino Vin (input to regulator, NOT 5V) * LANC 2.5mm plug tip to Arduino Digital Pin 2 * Potentiometer wiper to Arduino Analog Pin 0 * Potentiometer outer to Arduino 5V and Ground, switch polarity to reverse zoom direction. * This provides a voltage divider to determine which code to send the camera. * * This code has only been tested with a Canon XH-A1, and is provided entirely without warranty or guarantee. * I hope it's useful for people, but if it isn't, I won't be held responsible. * Released under the GPL. * * Angus Findlay * angus@(domain on the next line) * www.findlayproductions.ca * December 28, 2008 * */
/* * Copyright (C) 2006 Free Software Foundation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * See file LICENSE for further informations on licensing terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * @author: Brady Marks <brady@furiousgreencloud.com> * documentation of LANC from http://www.boehmel.de/lanc.htm * @date: 2008-05-22 * @locations: Furious Green Lab, Vancouver, British Columbia, Canada */
/*======================================================= Fix the controller and adapted for Wii: frwind v0.2 testing Sony HDR-CX130 Use joystick for zoom, button for REC and Photo Capture
int speeds[19]= /*These are the commands sent to the camera. 99 tells the code to send nothing.*/ { 0x0e,0x0c,0x0a,0x08,0x06,0x04,0x02,0x00, /*Zoom tele, from fastest to slowest*/ 99,99,99, /*Dead zone*/ 0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e}; /*Zoom wide, from slowest to fastest*/
if (zb == 1) SendCode(0x18,0x33); // REC start/stop, Z Button Wii if (cb == 1) SendCode(0x18,0x2b); //Photo, C Button Wii if (jx <= 10) SendCode(0x28,0x16); // Medium speed zoom wide if (jx >= 245) SendCode(0x28,0x06);// Medium speed zoom tele commandCode=speeds[jy2];
if (commandCode == 99) return; // If the pot is in the middle, send nothing. SendCode(40,commandCode); SendCode(40,commandCode); }
void SendCode(int type,int code) { frameStartBitWait(); writeByte(lancPin,type,bitMicroSeconds); // Video Cam Control lowWait(lancPin); writeByte(lancPin,code,bitMicroSeconds); // Tele/Wide etc }
void frameStartBitWait() { // finds thge start of a telegram/frame unsigned long usec = pulseIn(lancPin,HIGH); while (usec < 5864) { // 6230 experimentally with a RTV900 usec = pulseIn(lancPin,HIGH); } }
byte readByte(int pin,unsigned long uSec /* bit width*/ ) { byte result = 0; delayMicroseconds(uSec * 1.5); // skips the Start Bit and Land in the midlle of the first byte
for (int i = 0; i < 8; i++) { if (digitalRead(pin) == LOW) { // == *LOW* because bits inverted in LANC result++; } result <<= 1; delayMicroseconds(uSec); } delayMicroseconds(0.5*uSec); return result; // return happens at end of last (8ths) bit }
void writeByte(int pin, byte value, unsigned uSec /* bit width */) { delayMicroseconds(uSec); // wait for stop bit pinMode(pin,OUTPUT); for (int i = 0; i < 8; i++) { boolean bit = value & 0x1; digitalWrite(pin,!bit); // NOT (!) pin because all data is inverted in LANC value >>= 1; delayMicroseconds(uSec); } pinMode(pin,INPUT); // return happends at end of last (8th) bit }
//=======nunchuck_funcs_m2.h================== /* NO DELAY
* Nunchuck functions -- Talk to a Wii Nunchuck * * This library is from the Bionic Arduino course : * http://todbot.com/blog/bionicarduino/ * * 2007 Tod E. Kurt, http://todbot.com/blog/ * * The Wii Nunchuck reading code originally from Windmeadow Labs * http://www.windmeadow.com/node/42 ** ** fixed Mark, for china low cost Wii Nunchuk */
#include <WProgram.h>
static uint8_t nunchuck_buf[6]; // array to store nunchuck data,
// initialize the I2C system, join the I2C bus, // and tell the nunchuck we're talking to it static void nunchuck_init() {
// read the extension type from the register block Wire.beginTransmission(0x52); Wire.send(0xFA); // extension type register Wire.endTransmission(); Wire.beginTransmission(0x52); Wire.requestFrom(0x52, 6); // request data from controller for (cnt21 = 0; cnt21 < 6; cnt21++) { if (Wire.available()) { ctrlr_type[cnt21] = Wire.receive(); // Should be 0x0000 A420 0101 for Classic Controller, 0x0000 A420 0000 for nunchuck } } Wire.endTransmission(); //delay(1);
// Send a request for data to the nunchuck // was "send_zero()" static void nunchuck_send_request() { Wire.beginTransmission(0x52);// transmit to device 0x52 Wire.send(0x00);// sends one byte Wire.endTransmission();// stop transmitting }
// Encode data to format that most wiimote drivers except // only needed if you use one of the regular wiimote drivers static char nunchuk_decode_byte (char x) { x = (x ^ 0x17) + 0x17; return x; }
// Receive data back from the nunchuck, // returns 1 on successful read. returns 0 on failure static int nunchuck_get_data() { int cnt=0; Wire.requestFrom (0x52, 6);// request data from nunchuck while (Wire.available ()) { // receive byte as an integer nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.receive()); cnt++; } nunchuck_send_request(); // send request for next data payload // If we recieved the 6 bytes, then go print them if (cnt >= 5) { return 1; // success } return 0; //failure }
// returns value of x-axis joystick static int nunchuck_joyx() { return nunchuck_buf[0]; }
// returns value of y-axis joystick static int nunchuck_joyy() { return nunchuck_buf[1]; }
// returns value of x-axis accelerometer static int nunchuck_accelx() { return nunchuck_buf[2]; // FIXME: this leaves out 2-bits of the data }
// returns value of y-axis accelerometer static int nunchuck_accely() { return nunchuck_buf[3]; // FIXME: this leaves out 2-bits of the data }
// returns value of z-axis accelerometer static int nunchuck_accelz() { return nunchuck_buf[4]; // FIXME: this leaves out 2-bits of the data } //========================================
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 3
Вы не можете начинать темы Вы не можете отвечать на сообщения Вы не можете редактировать свои сообщения Вы не можете удалять свои сообщения Вы не можете добавлять вложения