Finally, a worthy projet for the vacation for my asument!
This is an ongoing project so stay tuned.
The project goal is to drive one or more Pelco cctv cameras with an arduino and to do a controlling board with custom pcbs, etc
I've borrowed a camera from school for testing purpose.
Details
There is 2 types of cameras in school, I've borrowed one of them the Pelco Esprit 4036.
The video encoder is also from the school, it's a Bosch VideoJet XF E.
I would first thank you all for following me in this project and huge thanks to Arsenijs Picugins who made an article about RS485 which is very well documented
Ok so what's new?
Well there is 3 chapters:
6 hours of debugging can save you 5 minutes of reading documentation
The camera, the keypad and the computer
Arduino administration is simpler than France one
6 hours of debugging can save you 5 minutes of reading documentation
Ok so to resume, the lib need to know which command we are sending to correctly parse the input data (e.g: if the command is SET_PAN , the lib must compute the given angle to hex values to transmit)
The solution: have a list with every special case!
constbyte CMND1[5] PROGMEM = {FOCUS_N, IRIS_O, IRIS_C, OFF, ON}; //List of all commands that go on the byte3; a list with command 2 is not required, a bit of logic pleaseconstbyte DATA1[2] PROGMEM = {PAN_L, PAN_R}; //List of all commands that use ONLY the DATA1 for data passconstbyte SETPOS[3] PROGMEM = {SET_PAN, SET_TILT, SET_ZOOM}; //List of all command that require an MSB and LSBconstbyte DATA_BOTH[5] PROGMEM= {PAN_L_TILT_D, PAN_L_TILT_U, PAN_R_TILT_D, PAN_R_TILT_U, WRITE_CHAR};//List of all commands that use the DATA1 and DATA2 for data pass (excluding the SETPOS' commands)constbyte RESP_CMND[3] PROGMEM = {RESP_PAN, RESP_TILT, RESP_ZOOM};
constbyte QUERY_CMND[3] PROGMEM = {QUERY_PAN, QUERY_TILT, QUERY_ZOOM};
constbyte PRESET_CMND[3] PROGMEM= {SET_PRESET, CLR_PRESET, GOTO_PRESET}; //will I use it?
The problem: Getting a value of progmem's flash isn't what it is.
If I want to compare the Command PAN_L to DATA1, I can't use a loop with DATA1[i] (with i incrementing)
why? Because progmem is maintained by a library: pgmspace.h (more on the arduino refenrece)
The solution: After reading a bit of documentation, you actually need to do this:
pgm_read_byte(&DATA1[i]) //(Demo purpose not in the lib)
The camera, the keypad and the computer
I swear the title is not a Clint Eastwood reference O_O
What do we do with a functionning library, we test it!
I had keypad laying around my place so I plugged him in the esp and onto the testing and good news!
The 2 modules that generates RS485 works with the 2 mains architectures (avr and esp32)
Ok little demo video right there /\
Arduino administration is simpler than France one
With the library completed ( I strongly suggest you to see the github repo, there are new examples, etc)
I updated the library.properties and the created keywords to create style coloring:
ouhhh fashion
So with this and that next step, uploading it to the arduino library manager (again thx because the documentation is really great)
A few hour later: Well now you can download it from the library manager ! (it's so coool)
Well with this project log finished, until next time!!!
My vacation is now over, I had a little tchat with my teacher and we figured out that the most "easy" way to have multiple cameras without denuding the already present wires is to have:
-A pair of wires with RS485 bidirectional
First of all we need to configure the camera via the dip switch, we have 3 possible modes:
(TX is here from Arduino to camera and RX camera to Arduino)
-RS422 with 5 wires (GND, TX-, TX+ and RX- ,RX+)
-RS485 with 4 wires (TX-, TX+ and RX- ,RX+)
-RS485 with 2 wires (TX-, TX+ OR TX-, TX+ and RX- ,RX+)
Of course we want RS485 with 2 wires, however we encountered a problem: the TX module was supplying 5v (in idle state) to the camera even when it responded (For more explanation).
The solution to this problem: control the TX module's idle voltage with pinout!
I use an esp32, so the pins delivers 3v3 but that's not a problem because the chip function fine with 3v3 and the camera still works (The voltage differential is enough big)
So I grabbed my jumper wires and a schematic like this:
You can see that the TX module's Read Enable, Driver EN and vcc is controlled by tht IO33.
This module pins work like this
VCC
RE pin
DE pin
Module state
3V3
LOW
LOW
Receiver
3V3
HIGH
HIGH
Transceiver
0V
HIGH
HIGH
Residual voltage
0V
LOW
LOW
Nothing
but what is the is the result, here are the result in UART communication from RX module to Arduino:
Still "One problem": we detect also the TX module transmission but that's not a problem because we can filter it out in the software:
Well that was all for today, see you next for Software Improvements!
Hello again, here a couple of images where I try to explain to you how it works:
If you can see well, between the TX- and TX+, there is a 2V coming from the rs485 module, it is a "problem" because when the camera responds at the query on the same pair of wire, the signal from the camera is cut out by this 2v (lowered to a volt difference about 200mv).
A short log for exposing a main problem: the rx pair of cable have too much noise (the ones that comes from the camera)
To be precise when I input a command for the camera, it drives the motor and just after I call a query for the pan position but the motor has just been driven so the cable have too much noise leading to incomplete result on my esp.
If I don't run the motor it works fine but there is still too much noise:
I know that rs485 work with voltage potential so I know that the cables at school are all the same so there is no ground connection on the cable and I won't make one for now.
So what I need to do here is to find a solution with the modules.
I mean the two components for the transmissions over the camera.
Since the protocol used is rs485, I was given two very different modules, one with the max485-CSA chip and the other with the max134-87E chip:
You can have a look a the documentation here: MAX13487E and MAX485.
To summarize: the left module comes with a groove adapter, you need only to wire tx and rx, however the right module need to be wired to be in transmitter mode or receiver mode and that is the major difference the left one an switch between these two modes automatically where the right one can't.
If you wonder why the groove module has twice as much components compared to the max485 it's because it has a current Buck-Boost converter, which enable the module to be driven in 3v3.
But one thing strange is that the voltage differential from the output of the max485 is higher than the max13487E.
We know we need two modules, one for transmitting the information and one for receiving.
Or do we need two? We'll see that in the next log where we will be choosing between the two modules