Control Zoom camera with RC receiver

Hi everybody,
I’m new to Arduino, and still have alot to learn from you all.
I have a zoom camera for awhile and now decide to mount it on my big FPV. So I tried to control it through an Arduino. After a few errors with the camera’s address which starts with 01 and not 00, I finally got it to work.
Here’s my sketch, I really hope to here feedback from you if there are improvement to make.

/* Read stick position and translate to camera's action based on Pelco-D protocol*/
#include <LiquidCrystal.h>

LiquidCrystal lcd(4,5,6,7,8,9);
const int irRCpin = 2;
volatile long tempo;
volatile int RCpulseWidth;
int i;
char function='O';

const byte header_D = 255; // = FF

const byte add = 1;
const byte wide = 64;
const byte tele = 32;
const byte zoom_ctrl = 3;
const byte check_sum_D = 6;

const byte Pelco_D_stop_all[7] = {header_D,add,0,0,0,0,1};
byte Pelco_D[7] = {header_D,add,0,0,0,0,0};

void setup()
{
  lcd.begin(16,2);
  lcd.print("Hello");
  
  pinMode(irRCpin,INPUT);
  digitalWrite(irRCpin,HIGH);
  Serial1.begin(9600);
  attachInterrupt(0,pulseWidth,CHANGE);
  
  delay(1500);
  lcd.clear();

}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Pulse width:");
  if((RCpulseWidth > 800) && (RCpulseWidth < 2200))
  {
    lcd.print(RCpulseWidth);
    lcd.print(" ");
  }
  lcd.setCursor(0,1);
  
  ////////////////////
  
  if((RCpulseWidth > 800) && (RCpulseWidth < 1450) && (function != 'A') ) //zoom wide
  {
    Pelco_D[zoom_ctrl] = wide;
    Pelco_D[check_sum_D] = (Pelco_D[1] + Pelco_D[2] + Pelco_D[3] + Pelco_D[4] + Pelco_D[5])%100;
    
    for (i = 0; i<7; i++)
    {
      Serial1.print(Pelco_D[i]);          
    }
    
    function = 'A';
    lcd.print("Zoom wide");

  }
  
  //////////////////////
  
  if((RCpulseWidth >= 1450) && (RCpulseWidth <= 1600) && (function != 'B')) //stop all
  {
    for (i = 0; i<7; i++)
    {
      Serial1.print(Pelco_D_stop_all[i]);
    }
    
    function = 'B';
    lcd.print("Stop all ");
  }
  
  //////////////////////
  
  if((RCpulseWidth > 1600) && (RCpulseWidth < 2200) && (function != 'C')) //zoom tele
  {
    Pelco_D[zoom_ctrl] = tele;
    Pelco_D[check_sum_D] = (Pelco_D[1] + Pelco_D[2] + Pelco_D[3] + Pelco_D[4] + Pelco_D[5])%100;
    
    for (i = 0; i<7; i++)
    {
      Serial1.print(Pelco_D[i]);     
    }
    
    function = 'C';
    lcd.print("Zoom tele");
  }
  
}

///////////////////////////////
///////////////////////////////

void pulseWidth()
{
 RCpulseWidth = micros() - tempo;
 tempo = micros();
}

For more info on Pelco-D : http://www.commfront.com/RS232_Examples/CCTV/Pelco_D_Pelco_P_Examples_Tutorial.HTM#5

Hello,

I’m not an expert but your code seems quite good. Do you know if the signal measured is stable or not (I mean if no change on the command, do you receive each time the exact same value) ? I’ve seen that your program is taking a wide range between 1450 and 1600 for the neutral position so it’s not important in your case but I try to solve my jittering problem (my topic is just under yours).

regards

Fred

voleur2poule, I take a wide range in the neutral position because I don't want the board to make the camera zooming at the lightest touch at the sticks (some kind of death band). As for the jittering, as I saw on the LCD, there is only the latest digit jittering sometimes but very few, may be +/- 4 us.