R+ and R- likely refer to the RS422 receive pair the camera is looking for. You
would need an RS232-RS422 converter to talk to the camera. T+ and T- if they
exist at the camera would be the RS422 camera transmit pair.
Hexadecimal and Pelco D protocol
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- kastengeist
- Posts: 6
- Joined: Mon Feb 25, 2013 4:07 am
Re: Hexadecimal and Pelco D protocol
If I send commands as bytes in an array it doesn't seem to work. I cant figure this out. I dotn fully understand pelco-d and arduino/RS-485.. I see hex but for example do is send (byte)0x00; or (byte)0x3F; if I have a (byte)0x3F; the checksum wont calculate.. right now I am simply typing right, left, up, down in the serial monitor so the arduio can parse and send the commands.. Also i cant for the life of me figure out how to send CLR or HOME/ENTER so I can set up the internal PTZ camera... Please help me to understand. Thank you in advance.
Here is where I believe the problem is..
and here is my full code:
Here is where I believe the problem is..
Code: Select all
byte Cmd1 = (byte)0x00; /* Command 1 Seen below*/
byte Cmd2 = (byte)0x02; /* Command 2 Seen Below */
byte Dat1 = (byte)0x20; /* (Data 1) - pan speed, range from 00 (stop) to 3F (high speed) and FF for "turbo" speed (the maximum pan speed that the device can go) */
byte Dat2 = (byte)0x00; /* (Data 2) - tilt speed, range from 00 (stop) to 3F (maximum speed) */
getCheckSum();
byte dataVal[7] ={Sync, CamAdr, Cmd1, Cmd2, Dat1, Dat2, check_sum};
// byte dataVal[7] ={0xFF, 0x01, 0x00, 0x02, 0x20, 0x00, 0x23}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
Code: Select all
/* YourDuino SoftwareSerialExample1
- Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote"
- Connect this unit Pins 10, 11, Gnd
- Pin 3 used for RS485 direction control
- To other unit Pins 11,10, Gnd (Cross over)
- Open Serial Monitor, type in top window.
- Should see same characters echoed back from remote Arduino
Questions: [email protected]
*/
/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;
String PTZCommand;
/*
Byte 1 | Byte 2 | Byte 3 | Byte 4 | Byte 5 | Byte 6 | Byte 7
Sync | Camera | Address | Command 1 | Command 2 | Data 1 | Data 2 | Checksum
*/
byte Sync = (byte)0xFF; /* (Sync) - the synchronization byte, fixed to FF */
byte CamAdr = (byte)0x01; /* (Camera Address) - logical address of the camera being controlled (Address 1 is 01) */
byte Cmd1 = (byte)0x00; /* Command 1 Seen below*/
byte Cmd2 = (byte)0x00; /* Command 2 Seen Below */
byte Dat1 = (byte)0x00; /* (Data 1) - pan speed, range from 00 (stop) to 3F (high speed) and FF for "turbo" speed (the maximum pan speed that the device can go) */
byte Dat2 = (byte)0x00; /* (Data 2) - tilt speed, range from 00 (stop) to 3F (maximum speed) */
byte check_sum = CamAdr + Cmd1 + Cmd2 + Dat1 + Dat2; /* (Checksum) - sum of bytes (excluding the synchronization byte), then modulo 100 (Decimal code: 256) */
/*
Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0
Command 1 Sense | Reserved | Reserved | Auto / Manual Scan | Camera On/Off | Iris Close | Iris Open | Focus Near
Command 2 Focus Far | Zoom Wide | Zoom Tele | Tilt Down | Tilt Up |Pan Left | Pan Right | Fixed to 0
Example (Command 2):
Pan Left - 0 0 0 0 0 1 0 0, which equals to 04 (both hexadecimal and decimal)
*/
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(9600);
Serial.println("Current Pelco-D CheckSum: "); //Notification text for checksum
Serial.print(check_sum);
Serial.print("\n");
// Serial.println("YourDuino.com SoftwareSerial remote loop example");
//Serial.println("Use Serial Monitor, type in upper window, ENTER");
Serial.println("Please enter PTZ Command: \n"); //Prompt User for input
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
// Start the software serial port, to another device
RS485Serial.begin(9600); // set the data rate
}//--(end setup )---
void getCheckSum(){
byte check_sum = CamAdr + Cmd1 + Cmd2 + Dat1 + Dat2; /* (Checksum) - sum of bytes (excluding the synchronization byte), then modulo 100 (Decimal code: 256) */
Serial.write(CamAdr);
Serial.write(check_sum);
}
void t_Set() {
byte Cmd1 = (byte)0x00; /* Command 1 Seen below*/
byte Cmd2 = (byte)0x03; /* Command 2 Seen Below */
byte Dat1 = (byte)0x00; /* (Data 1) - pan speed, range from 00 (stop) to 3F (high speed) and FF for "turbo" speed (the maximum pan speed that the device can go) */
//byte Dat2 = (byte)0x5F; /* (Data 2) - tilt speed, range from 00 (stop) to 3F (maximum speed) */
byte Dat2 = (byte)0x95;
getCheckSum();
byte dataVal[7] ={Sync, CamAdr, Cmd1, Cmd2, Dat1, Dat2, check_sum}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
void t_Right() {
byte Cmd1 = (byte)0x00; /* Command 1 Seen below*/
byte Cmd2 = (byte)0x02; /* Command 2 Seen Below */
byte Dat1 = (byte)0x20; /* (Data 1) - pan speed, range from 00 (stop) to 3F (high speed) and FF for "turbo" speed (the maximum pan speed that the device can go) */
byte Dat2 = (byte)0x00; /* (Data 2) - tilt speed, range from 00 (stop) to 3F (maximum speed) */
getCheckSum();
byte dataVal[7] ={Sync, CamAdr, Cmd1, Cmd2, Dat1, Dat2, check_sum};
// byte dataVal[7] ={0xFF, 0x01, 0x00, 0x02, 0x20, 0x00, 0x23}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
void t_Left() {
byte dataVal[7] ={0xFF, 0x01, 0x00, 0x04, 0x10, 0x00, 0x15}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
void t_Up() {
byte dataVal[7] ={0xFF, 0x01, 0x00, 0x08, 0x00, 0x20, 0x29}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
void t_Down() {
byte dataVal[7] ={0xFF, 0x01, 0x00, 0x10, 0x00, 0x20, 0x31}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
void t_Stop() {
byte dataVal[7] ={0xFF, 0x01, 0x08, 0x00, 0x00, 0x00, 0x09}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
void t_CLR() {
byte dataVal[7] ={0xFF, 0x01, 0x00, 0x88, 0x00, 0x00, 0x89}; //This is the most basic instruction. Camera 1, four zeros and a check sum of one
for(int i=0; i<7; i++){
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
digitalWrite(Pin13LED, HIGH);
delay(6);
Serial.write(dataVal[i]);
RS485Serial.write(dataVal[i]);
delay(6);
digitalWrite(SSerialTxControl, RS485Receive);
digitalWrite(Pin13LED, LOW);
}
Serial.write("\n");
}
//Code ends here
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
digitalWrite(Pin13LED, HIGH); // Show activity
if (Serial.available())
{
// byteReceived = Serial.read();
while (Serial.available()==0) { //Wait for user input
}
PTZCommand=Serial.readString();
if (PTZCommand=="right"){
Serial.print(PTZCommand);
Serial.write("\n");
t_Right();
};
if (PTZCommand=="left"){
Serial.print(PTZCommand);
Serial.write("\n");
t_Left();
};
if (PTZCommand=="set"){
Serial.print(PTZCommand);
Serial.write("\n");
t_Set();
};
if (PTZCommand=="up"){
Serial.print(PTZCommand);
Serial.write("\n");
t_Up();
};
if (PTZCommand=="down"){
Serial.print(PTZCommand);
Serial.write("\n");
t_Down();
};
if (PTZCommand=="stop"){
Serial.print(PTZCommand);
Serial.write("\n");
t_Stop();
};
if (PTZCommand=="clr"){
Serial.print(PTZCommand);
Serial.write("\n");
t_CLR();
};
Serial.println("Please enter PTZ Command: \n"); //Prompt User for input
}
// digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
// RS485Serial.write(byteReceived); // Send byte to Remote Arduino
digitalWrite(Pin13LED, LOW); // Show activity
delay(10);
// digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
if (RS485Serial.available()) //Look for data from other Arduino
{
digitalWrite(Pin13LED, HIGH); // Show activity
byteReceived = RS485Serial.read(); // Read received byte
Serial.write(byteReceived); // Show on Serial Monitor
delay(10);
digitalWrite(Pin13LED, LOW); // Show activity
}
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
//NONE
- kastengeist
- Posts: 6
- Joined: Mon Feb 25, 2013 4:07 am
Re: Hexadecimal and Pelco D protocol
Sorry for bumping this post, didn't realize it was 3 years old..
Please be positive and constructive with your questions and comments.