Skip to content

Commit 38191d4

Browse files
committed
minor changes
1 parent c78855c commit 38191d4

9 files changed

Lines changed: 130 additions & 23 deletions

File tree

Protocol and errors.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Here is some explanation for the errors that you can get:
2+
3+
When you send some data, the frame is like this:
4+
5+
uint8_t messToCamera[7] = {
6+
0xFF, // sync byte
7+
0x01, // Address
8+
0x00, // Always 0 (in most of the cases)
9+
0x02, // Command
10+
0x00, // Data1 (Used for pan speed and response from camera)
11+
0x3F, // Data2 (Used everywhere)
12+
0x42 // Checksum: add all byte except sync and then modulo 0x100
13+
};
14+
15+
When you receive ACK from the camera, it's like this:
16+
17+
uint8_t ACKmessFromCamera[4] = {
18+
0xFF, //sync byte
19+
0x01, //Adress
20+
0x00, // 0?
21+
0x42 //Checksum taken for the previous message
22+
};
23+
24+
When you receive data from the camera (see get_position), it's like this:
25+
26+
uint8_t messFromcamera[7] = {
27+
0xFF, // sync byte
28+
0x01, // Address
29+
0x00, // Always 0 (in most of the cases)
30+
0x59, // Respond to the query command
31+
0x20, // Data MSB
32+
0x15, // DATA LSB
33+
0x8F // Checksum: add all byte except sync and then modulo 0x100
34+
};
35+
36+
37+
## So here are the errors you might encounter:
38+
39+
### Acknoledge errors
40+
41+
"Cam 1: ERROR Could not verify camera ACK: timeout reached (is camera well plugged in?)\n"
42+
43+
The acknoledge took too long to be received, maybe the camera isn't plugged in.
44+
Default timeout is 10 ms.
45+
46+
"Cam 1: ERROR Could not verify camera ACK: bad sync byte (is camera well plugged in?)\n",
47+
48+
The acknoledge data that you received isn't right, the sync byte isn't detect by the program
49+
50+
"Cam 1: ERROR Could not verify camera ACK: bad address (is camera well plugged in?)\n",
51+
52+
The acknoledge data that you received isn't right, the address byte isn't the one from the camera
53+
54+
"Cam 1: ERROR Could not verify camera ACK: bad null ???? (is camera well plugged in?)\n",
55+
56+
The acknoledge data that you received isn't right, the null byte (the third one) isn't detected by the program
57+
58+
"Cam %i: ERROR Could not verify camera ACK: bad checksum (is camera well plugged in?)\n",
59+
60+
The acknoledge data that you received isn't right, the checksum byte isn't good
61+
62+
### Request errors
63+
64+
"Cam 1: No valid request provided\n"
65+
66+
The command you provided isn't listed as a request (valid request are: QUERY_PAN, QUERY_TILT, QUERY_ZOOM)
67+
68+
"Cam 1: ERROR timout reached\n"
69+
70+
Same error as the acknoledge timeout
71+
72+
"Cam 1: Warn: no reponse from camera (bad index)\n"
73+
74+
The data received from the camera isn't properly "aligned", the program seek for the respond command and throw
75+
this error if it isn't at the fourth byte.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The important thing is to set the camera is RS485 biderectional and with the bau
3434

3535
About the modules for RS485, I'm working with a standart MAX485 chip but I'll test a more advanced module on the future (a seed-groove max485 module).
3636

37+
Tested on Arduino UNO and ESP32
38+
3739
## Exemple
3840

3941
go to the examples folder

examples/get_position/get_position.ino

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55

66
PelcoCam MyPelcoCam(01, //Address of the camera
77
PELCO_D9600,//Config
8-
6, //TX pin
9-
7, //RX pin
8+
6, //TX pin (Arduino to Cam)
9+
7, //RX pin (Cam to Arduino)
1010
false, //Enable logging?
1111
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
1212

1313
void setup() {
14-
// Begin the serial communication If you enabled logging, no need to begin the normal serial
15-
MyPelcoCam.begin();
1614

1715
Serial.begin(9600);
16+
17+
// Begin the serial communication
18+
MyPelcoCam.begin();
19+
20+
1821
// Send stop, send_command will return a bool that indicates if the cameras sended its ACK
1922
// It's a good way to see if the camera is plugged in
2023
while (!MyPelcoCam.send_command(STOP)) {

examples/send_raw/send_raw.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
PelcoCam MyPelcoCam(01, //Address of the camera
55
PELCO_D9600,//Config
6-
6, //TX pin
7-
7, //RX pin
6+
7, //RX pin (Cam to Arduino)
7+
6, //TX pin (Arduino to Cam)
88
true, //Enable logging?
99
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
1010

1111
void setup() {
12-
//Begin the serial communication If you enabled logging, no need to begin the normal serial
12+
Serial.begin(9600);
13+
14+
//Begin the serial communication
1315
MyPelcoCam.begin();
1416

1517
//Send stop, send_command will return a bool that indicates if the cameras sended its ACK

examples/set_position/set_position.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
PelcoCam MyPelcoCam(01, //Address of the camera
55
PELCO_D9600,//Config
6-
6, //TX pin
7-
7, //RX pin
6+
7, //RX pin (Cam to Arduino)
7+
6, //TX pin (Arduino to Cam)
88
true, //Enable logging?
99
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
1010

1111
void setup() {
12-
//Begin the serial communication If you enabled logging, no need to begin the normal serial
12+
Serial.begin(9600);
13+
14+
//Begin the serial communication
1315
MyPelcoCam.begin();
1416

1517
//Send stop, send_command will return a bool that indicates if the cameras sended its ACK

examples/simple/simple.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
PelcoCam MyPelcoCam(01, //Address of the camera
55
PELCO_D9600,//Config
6-
6, //TX pin
7-
7, //RX pin
6+
7, //RX pin (Cam to Arduino)
7+
6, //TX pin (Arduino to Cam)
88
true, //Enable logging?
99
8); // RE pin for manual switching modules set to -1 if it is a auto module (like a groove one)
1010

1111
void setup() {
12-
//Begin the serial communication If you enabled logging, no need to begin the normal serial
12+
Serial.begin(9600);
13+
14+
//Begin the serial communication
1315
MyPelcoCam.begin();
1416

1517
//Send stop, send_command will return a bool that indicates if the cameras sended its ACK

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Pelco_And_Arduino
2-
version=1.0.0
2+
version=1.1.0
33
author=Boris Hilkens <pixelbo21@gmail.com>
44
maintainer=Boris Hilkens <pixelbo21@gmail.com>
55
sentence=This library makes Pelco cameras moves!
66
paragraph=With simple arduino coding, you can move multiple Pelco camera and even do more!
77
category=Device Control
88
url=https://github.com/Pixelbo/Pelco_And_Arduino
9-
architectures=*
9+
architectures=avr, esp32

src/Pelco_And_Arduino.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
*
2323
* @param Address The address of the camera
2424
* @param baud baud of the cameras
25-
* @param txPin the TX pin of the module (Arduino to Cam)
2625
* @param rxPin the RX pin of the module (Cam to Arduino)
26+
* @param txPin the TX pin of the module (Arduino to Cam)
2727
* @param log_messages Print log messages of this camera
2828
* @param readEnPin Pin for RS485 modules that require toggle between rx and
2929
* tx (RE and \DE pin of the module)
3030
*
3131
*/
3232

33-
PelcoCam::PelcoCam(uint8_t address, uint32_t config, uint8_t txPin, uint8_t rxPin, bool log_messages,
33+
PelcoCam::PelcoCam(uint8_t address, uint32_t config, uint8_t rxPin, uint8_t txPin, bool log_messages,
3434
uint8_t readEnPin) {
3535
address_ = address;
3636
config_ = config;
@@ -168,7 +168,7 @@ bool PelcoCam::send_command(uint8_t command, uint16_t data1, uint8_t data2, bool
168168
if (log_messages_) {
169169
sprintf(
170170
log_buffer,
171-
"Cam %i: ERROR Could not verify camera reponse: timeout reached (is camera well plugged in?)\n",
171+
"Cam %i: ERROR Could not verify camera ACK: timeout reached (is camera well plugged in?)\n",
172172
address_);
173173
Serial.print(log_buffer);
174174
}
@@ -179,16 +179,37 @@ bool PelcoCam::send_command(uint8_t command, uint16_t data1, uint8_t data2, bool
179179
timeout--;
180180
delayMicroseconds(10);
181181
}
182+
if(log_messages_){
183+
sprintf(
184+
log_buffer,
185+
"Cam %i: Reading Acknoledge from camera\n",
186+
address_);
187+
Serial.print(log_buffer);
188+
}
182189

183190
(*SerialCam).readBytes(ACKmessFromCamera, 4); // General response is 4 byte
184191

185192
if (!autoModule_)
186193
digitalWrite(rePin_, HIGH); // set back at TX mode
187194

195+
if (log_messages_) {
196+
sprintf(log_buffer, "Cam %i: Received ACK data (may be wrong): ", address_);
197+
Serial.print(log_buffer);
198+
199+
for (int i = 0; i < 7; i++) {
200+
sprintf(log_buffer, "%02X ", messFromcamera[i]);
201+
Serial.print(log_buffer);
202+
}
203+
Serial.println();
204+
205+
}
206+
207+
208+
188209
if (ACKmessFromCamera[0] != 0xFF) { // Check sync byte and checksum of the previous comand
189210
if (log_messages_) {
190211
sprintf(log_buffer,
191-
"Cam %i: ERROR Could not verify camera reponse: bad sync byte (is camera well plugged in?)\n",
212+
"Cam %i: ERROR Could not verify camera ACK: bad sync byte (is camera well plugged in?)\n",
192213
address_);
193214
Serial.print(log_buffer);
194215
}
@@ -198,7 +219,7 @@ bool PelcoCam::send_command(uint8_t command, uint16_t data1, uint8_t data2, bool
198219
if (ACKmessFromCamera[1] != address_) { // Check adress byte
199220
if (log_messages_) {
200221
sprintf(log_buffer,
201-
"Cam %i: ERROR Could not verify camera reponse: bad address (is camera well plugged in?)\n",
222+
"Cam %i: ERROR Could not verify camera ACK: bad address (is camera well plugged in?)\n",
202223
address_);
203224
Serial.print(log_buffer);
204225
}
@@ -208,7 +229,7 @@ bool PelcoCam::send_command(uint8_t command, uint16_t data1, uint8_t data2, bool
208229
if (ACKmessFromCamera[2] != 0x00) { // check the always 0 byte (alarm byte)
209230
if (log_messages_) {
210231
sprintf(log_buffer,
211-
"Cam %i: ERROR Could not verify camera reponse: bad null ???? (is camera well plugged in?)\n",
232+
"Cam %i: ERROR Could not verify camera ACK: bad null ???? (is camera well plugged in?)\n",
212233
address_);
213234
Serial.print(log_buffer);
214235
}
@@ -218,7 +239,7 @@ bool PelcoCam::send_command(uint8_t command, uint16_t data1, uint8_t data2, bool
218239
if (ACKmessFromCamera[3] != messToCamera[6]) { // Check the checksum
219240
if (log_messages_) {
220241
sprintf(log_buffer,
221-
"Cam %i: ERROR Could not verify camera reponse: bad checksum (is camera well plugged in?)\n",
242+
"Cam %i: ERROR Could not verify camera ACK: bad checksum (is camera well plugged in?)\n",
222243
address_);
223244
Serial.print(log_buffer);
224245
}

src/Pelco_And_Arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class PelcoCam
6767
int searchIndexPROGMEM(const byte look_array[], byte value);
6868

6969
public:
70-
PelcoCam(uint8_t address, uint32_t config, uint8_t txPin, uint8_t rxPin, bool log_messages = false, uint8_t readEnPin = NOT_A_PIN);
70+
PelcoCam(uint8_t address, uint32_t config, uint8_t rxPin, uint8_t txPin, bool log_messages = false, uint8_t readEnPin = NOT_A_PIN);
7171
void begin();
7272

7373
bool send_command(uint8_t command, uint16_t data1 = 0x00, uint8_t data2 = 0x00, bool request = false);

0 commit comments

Comments
 (0)