Hi,
i' m trying to send PelcoD commands to my PTZ camera, but i m a beginner with serial 485 so i looked some posts from other guys and some websites explaining:
http://forum.arduino.cc/index.php?topic=67590.0
http://forum.arduino.cc/index.php?topic=230959.0
and this for wiring:
https://arduinoinfo.mywikis.net/wiki/SoftwareSerialRS485Example
So in finally wrote my code: i want to call Preset1.
Due to this protocol (http://bruxy.regnet.cz/programming/rs485/pelco-d.pdf) i have to send this command:
0xFF, 0x01, 0x00, 0x07, 0x00, 0x01, 0x09
so i followed wiring
DI (data in) to pin 11
RO (receive out) to pin 10
DE (data enable) and RE (receive enable) jumpered together and to pin 3
Vcc and Gnd connected
A and B : the RS485 pair
Gnd between distant Arduinos can be in cable or local electrical ground.
and this is the sketch:
#include <SoftwareSerial.h>
/-----( Declare Constants and Pin Numbers )-----/
#define SSerialRX 10 //Serial Receive pin -> RO
#define SSerialTX 11 //Serial Transmit pin -> DI
#define SSerialTxControl 3 //RS485 Direction control -> DE in corto con RE
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13 //led di stato
/-----( Declare objects )-----/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
/-----( Declare Variables )-----/
int byteReceived;
int byteSend;
int i;
byte comandodainviare[7] ={0xFF, 0x01, 0x00, 0x07, 0x00, 0x01, 0x09};
void setup() /****** SETUP: RUNS ONCE ******/
{
// Start the built-in serial port, probably to Serial Monitor
Serial.begin(2400);
Serial.println("YourDuino.com SoftwareSerial remote loop example");
Serial.println("Use Serial Monitor, type in upper window, ENTER");
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver inizia con la configurazione di ricezione
// Start the software serial port, to another device
RS485Serial.begin(2400); // set the data rate verso il dispositivo esterno (tipo la telecamera)
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
Serial.println("inizio loop");
delay(3000);
digitalWrite(Pin13LED, HIGH); // Show activity
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
//RS485Serial.write(comandodainviare[1]); // Send byte to Remote Arduino
delay(200);
for(i=0;i<7;i++)
{
Serial.println(comandodainviare[\i]);
}
for(i=0;i<7;i++)
{
RS485Serial.write(comandodainviare[\i]);
}
delay(200);
digitalWrite(Pin13LED, LOW); // Show activity
delay(3000);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
Serial.println("Fine Loop");
}//--(end main loop )---
but the camera doesnt go to Preset1, even if with her keyboard it does.
is there a problem in the code? can someone help me using MAX485 ?
Thank you so much!