Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Problem when using LANC Protocol and IR Library in the same sketch on: January 06, 2013, 04:16:57 pm
Here is the project I am currently working on:
The idea is to control a pan tilt head and a SONY mini DV camcorder with an Arduino, L293D chip for the two stepper motors in the head,
and an old IR TV remote control, using the IR library from Ken Shirriff and the LANC tutorial/code from Martin Koch.
I have designed a PCB with Arduino, an IR receiver and L293D as well as the circuit needed for the LANC commands.

Controlling the camcorder via serial port and LANC works fine, you can see the code below:
Code:
/*
Comprehensive LANC info: www.boehmel.de/lanc.htm

"LANC" is a registered trademark of SONY.
CANON calls their LANC compatible port "REMOTE".

2011, Martin Koch
http://controlyourcamera.blogspot.com/2011/02/arduino-controlled-video-recording-over.html
*/
#include <SoftwareSerial.h>
#include <IRremote.h>
#define IRreceive_pin 8
IRrecv irrecv(IRreceive_pin);
#define cmdPin 11
#define lancPin 12

//Start-stop video recording
boolean REC[] = {LOW,LOW,LOW,HIGH,HIGH,LOW,LOW,LOW,   LOW,LOW,HIGH,HIGH,LOW,LOW,HIGH,HIGH}; //18 33
boolean STOP[] = {LOW,LOW,LOW,HIGH,HIGH,LOW,LOW,LOW,   LOW,LOW,HIGH,HIGH,LOW,LOW,LOW,LOW}; //18 30
boolean ZOOM_IN[] = {LOW,LOW,HIGH,LOW,HIGH,LOW,LOW,LOW,   LOW,LOW,LOW,LOW,LOW,HIGH,LOW,LOW}; //28 04     
boolean ZOOM_OUT[] = {LOW,LOW,HIGH,LOW,HIGH,LOW,LOW,LOW,   LOW,LOW,LOW,HIGH,LOW,HIGH,LOW,LOW}; //28 14
int cmdRepeatCount;
int bitDuration = 96; //Duration of one LANC bit in microseconds.
char bytein = 'q';   
char char_old = 'q';
void setup() {
Serial.begin(19200);
//irrecv.enableIRIn();           // Start the receiver  The LANC part of this sketch works as long as this line of code for the IR receiver is not activated
pinMode(lancPin, INPUT); //listens to the LANC line
pinMode(cmdPin, OUTPUT); //writes to the LANC line

digitalWrite(cmdPin, LOW); //set LANC line to +5V
delay(5000); //Wait for camera to power up completly
}

void loop() {
if (Serial.available() > 0)
   { bytein = Serial.read();
   }
switch (bytein)           
  {
  case 'r':
    lancCommand(REC);
  break; 
  case 'z':
   lancCommand(ZOOM_IN);
   break;
 case 'x':
    lancCommand(ZOOM_OUT);
  break;
   case 's':
    lancCommand(STOP);
  break;
 delay(1000);
}
}

void lancCommand(boolean lancBit[]) {
  cmdRepeatCount = 0;
  while (cmdRepeatCount < 5) {  //repeat 5 times to make sure the camera accepts the command
  while (pulseIn(lancPin, HIGH) < 5000)
  {   //"pulseIn, HIGH" catches any 0V TO +5V TRANSITION and waits until the LANC line goes back to 0V
      //"pulseIn" also returns the pulse duration so we can check if the previous +5V duration was long enough (>5ms) to be the pause before a new 8 byte data packet
      //Loop till pulse duration is >5ms
 }
//LOW after long pause means the START bit of Byte 0 is here
  delayMicroseconds(bitDuration);  //wait START bit duration
//Write the 8 bits of byte 0
//Note that the command bits have to be put out in reverse order with the least significant, right-most bit (bit 0) first
  for (int i=7; i>-1; i--)
  { digitalWrite(cmdPin, lancBit[i]);  //Write bits.
    delayMicroseconds(bitDuration);
  }
//Byte 0 is written now put LANC line back to +5V
  digitalWrite(cmdPin, LOW);
  delayMicroseconds(10); //make sure to be in the stop bit before byte 1
  while (digitalRead(lancPin))
  { //Loop as long as the LANC line is +5V during the stop bit
  }
//0V after the previous stop bit means the START bit of Byte 1 is here
  delayMicroseconds(bitDuration);  //wait START bit duration
//Write the 8 bits of Byte 1
//Note that the command bits have to be put out in reverse order with the least significant, right-most bit (bit 0) first
   for (int i=15; i>7; i--)
   { digitalWrite(cmdPin,lancBit[i]);  //Write bits
     delayMicroseconds(bitDuration);
    }
//Byte 1 is written now put LANC line back to +5V
  digitalWrite(cmdPin, LOW);
cmdRepeatCount++;  //increase repeat count by 1
/*Control bytes 0 and 1 are written, now don’t care what happens in Bytes 2 to 7
and just wait for the next start bit after a long pause to send the first two command bytes again.*/
}//While cmdRepeatCount < 5
}

This program works as long as this line of code is not activated:
irrecv.enableIRIn();           // Start the receiver 

On the other hand the IR control of the pan tilt head is also no problem.
The code is too long to be inserted here but you can find it at this post:
http://christophhartel.com/wireless-control-of-a-pan-tilt-head-with-arduino-l293d-motor-controller-and-tv-ir-remote-control/

As mentioned above the problem occurs when I try to combine these two sketches.
Neither the pan tilt head nor the camcorder can be controlled once these functions are integrated into one sketch.
Any ideas how to resolve this problem are welcome.

Thanks a lot.

Christoph





2  Using Arduino / Networking, Protocols, and Devices / Re: I2C Set and read individual pins on: January 05, 2013, 11:26:40 am
Hi Alterach,

There is a Adafruit library for the MCP23017 that allows to read, write pins individually.
You can find an example, including code for an Arduino Uno at the bottom of this post:
http://christophhartel.com/arduino-io-expander-with-mcp23017-and-74hc4051/

Christoph

3  Using Arduino / Networking, Protocols, and Devices / Re: My i2c MCP23017 i/o expander is not working on: January 05, 2013, 11:21:25 am
Hi Centizen,

I recently had a similar project. Check out this post: http://christophhartel.com/arduino-io-expander-with-mcp23017-and-74hc4051/
At the bottom of the page I have included the code I wrote to drive two MCP23017 and two analog multiplexers with an Arduino Uno.
The Adafruit library for the MCP23017 makes programming really easy.

I hope this help.

Christoph

4  Community / Exhibition / Gallery / I/O Expander with MCP23017 and 74HC4051 on: December 28, 2012, 05:48:27 pm
The I/O expander described in this post provides a total of 24 digital I/O ports as well as 16 analog ports.
Each MCP23017 provides 16-bit, general purpose parallel I/O expansion for I2C bus or SPI applications.
The 74HC4051 is a 8-channel analog multiplexer/ demultiplexer.
The PCB includes 2x MCP23017 and 2x 74HC4051.

The Arduino sketch is based on the wire library and the MCP23017 library from Adafruit.
In this application the Analog In pins A0 and A1 of the Arduino board are used as inputs for the data from
the analog mux/demux. The addresses for the 4051 and the ports are selected by utilizing the GPA port of
one of the digital IO expanders MCP23017 and the I2C bus.

For more information, including PCB layout, assembly, schematic and the sketch, follow the link below.

http://christophhartel.com/arduino-io-expander-with-mcp23017-and-74hc4051/

Christoph
Pages: [1]