http://86rc89.com/viewtopic.php?f=19&t=987
==================================================================
Во нашол, народ делает пульты к видеокамерам Sony, на Arduino.
http://www.slashcam.de/info/Sony-Cam-au ... 38723.html
http://blog.furiousgreencloud.com/2008/ ... amera.html
http://findlayproductions.ca/gooseblog/?p=5
http://www.boehmel.de/lanc.htm
Распайку взял тут, резистор на 100 кОм впаял.
Программу взял от сюда
http://findlayproductions.ca/gooseblog/?p=5
- Код: Выделить всё • Развернуть
/*
* 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 lancPin 2
#define aPin 0
#define bitMicroSeconds 104
byte ledPinState = 1;
void setup() {
// 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
}
void lowWait(int pin) {
byte commandCode = digitalRead(pin);
while (commandCode) {
commandCode = digitalRead(pin);
}
}
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);
/* DEBUG
Serial.print(usec);
Serial.println(" microseconds");
*/
}
/* DEBUG
Serial.print("frame start after ");
Serial.print(usec);
Serial.println(" microseconds");
*/
}
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
PinOut http://www.dvinfo.net/forum/attachments/sony-hvr-a1-hdr-hc-series/8310d1217085403-hdr-hc9-v-remote-terminal-lanc-lanc-10pin.jpg
LANC Code
18 33 start/stop
18 2B photo write
28 0 variable speed zoom Tele: slowest speed
28 2 variable speed zoom Tele: faster than 00
28 4 variable speed zoom Tele: faster than 02
28 6 variable speed zoom Tele: faster than 04
28 8 variable speed zoom Tele: faster than 06
28 0A variable speed zoom Tele: faster than 08
28 0C variable speed zoom Tele: faster than 0A
28 0E variable speed zoom Tele: fastest speed
28 10 variable speed zoom Wide: slowest speed
28 12 variable speed zoom Wide: faster than 10
28 14 variable speed zoom Wide: faster than 12
28 16 variable speed zoom Wide: faster than 14
28 18 variable speed zoom Wide: faster than 16
28 1A variable speed zoom Wide: faster than 18
28 1C variable speed zoom Wide: faster than 1A
28 1E variable speed zoom Wide: fastest speed
*/
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*/
#define lancPin 2 // Digital output LANC
#define bitMicroSeconds 104
byte ledPinState = 1;
void setup() {
nunchuck_init();
pinMode(lancPin, INPUT);
pinMode(13,OUTPUT);
digitalWrite(13,1);
}
int commandCode = 0;
void loop() {
wii();
jy2=map(jy,0,255,18,0);
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 lowWait(int pin) {
byte commandCode = digitalRead(pin);
while (commandCode) {
commandCode = digitalRead(pin);
}
}
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
}
//==========Wi
void wii()
{
nunchuck_get_data();
zb = nunchuck_zbutton();
x = nunchuck_accelx();
y = nunchuck_accely();
jx = nunchuck_joyx();
jy = nunchuck_joyy();
cb = nunchuck_cbutton();
}
nunchuck_funcs_m2.h
- Код: Выделить всё • Развернуть
//=======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()
{
byte cnt21;
uint8_t ctrlr_type[6];
Wire.begin();
// init controller
//delay(1);
Wire.beginTransmission(0x52); // device address
Wire.send(0xF0); // 1st initialisation register
Wire.send(0x55); // 1st initialisation value
Wire.endTransmission();
//delay(1);
Wire.beginTransmission(0x52);
Wire.send(0xFB); // 2nd initialisation register
Wire.send(0x00); // 2nd initialisation value
Wire.endTransmission();
//delay(1);
// 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 the crypto key (zeros), in 3 blocks of 6, 6 & 4.
Wire.beginTransmission(0x52);
Wire.send(0xF0); // crypto key command register
Wire.send(0xAA); // sends crypto enable notice
Wire.endTransmission();
//delay(1);
Wire.beginTransmission(0x52);
Wire.send(0x40); // crypto key data address
for (cnt21 = 0; cnt21 < 6; cnt21++) {
Wire.send(0x00); // sends 1st key block (zeros)
}
Wire.endTransmission();
Wire.beginTransmission(0x52);
Wire.send(0x40); // sends memory address
for (cnt21 = 6; cnt21 < 12; cnt21++) {
Wire.send(0x00); // sends 2nd key block (zeros)
}
Wire.endTransmission();
Wire.beginTransmission(0x52);
Wire.send(0x40); // sends memory address
for (cnt21 = 12; cnt21 < 16; cnt21++) {
Wire.send(0x00); // sends 3rd key block (zeros)
}
Wire.endTransmission();
//delay(1);
// end device init
}
// 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 zbutton state: 1=pressed, 0=notpressed
static int nunchuck_zbutton()
{
return ((nunchuck_buf[5] >> 0) & 1) ? 0 : 1; // voodoo
}
// returns zbutton state: 1=pressed, 0=notpressed
static int nunchuck_cbutton()
{
return ((nunchuck_buf[5] >> 1) & 1) ? 0 : 1; // voodoo
}
// 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
}
//========================================