I'm a newbie to Arduino, I do know of most of it's capabilities, and I know that a Hitachi VK-S234 camera can be controlled by an Arduino via Arduino TX to Camera RX. I need to control "Zoom In" "Zoom Out" and "Focus."
I have written code for the arduino, but simple code.
The Hitachi camera is needed for my wildlife research, as it comes loaded with a powerful punch, even though it is an older camera.
Problem is, I know nothing about Arduino TX/RX functions, let alone sending strings of codes.
I only know how to hook the the camera to the arduino for tx to rx and rx to tx.
Ground to ground.
This camera is needed because the cost was very cheap, it packs a heavy duty optical zoom, and does beautifully in very low light conditions.
It's also a very TOUGH camera.
I have programmed and built a pan and tilt for the camera, but I have hit a brick wall in controlling the camera.
If you can write up this code, and have it work, I will add your name to research work that I produce, if wanted.
I will also be glad to send you a little cash for your work.
I've never done this before, But it looks like I need some help in this area. The help would be extremely appreciated!
I'm doing something wrong in my code, and I know it's probably something very small.
Like I stated, I've never done anything tx/rx, so I don't understand the correct setup in the code.
If I have it like:
int snapPin = 12;// pin to the trigger
int dataPin = 7;// pin to sensor data
int value = 0;
void setup() {
Serial.begin(4800);
pinMode(snapPin, OUTPUT);
pinMode(dataPin, INPUT);
}
void loop() {
value = digitalRead(dataPin);
if (HIGH == value) {
digitalWrite(snapPin, HIGH);
delay(50);
Serial.print (":WFCBB99");
}else{
digitalWrite(snapPin, LOW);
}
}
Apparently there has to be more to it than this.
The "snapPin" is to a camera trigger. A separate camera trigger.
The data pin is to a motion sensor.
don't forget that loop() is called continuously
so unless something resets dataPin,
you will be attemting to fire the shutter continuously while dataPin is HIGH
I would start with the basics, we need to know if even a simple command works before trying other stuff. I would try a few commands. Something like this to zoom in and then out.
Then if that works try some other stuff. If not (I may have been wrong in my interpretation of the specs) there's no point continuing until you figure out why.
NOTE: You are using Serial, this is connected to the USB chip which often causes problems. I'd swap to SoftwareSerial and use two other pins.
Hi my name is Dennis. I am totaly new to Arduino. I don't even have a board to play with yet. I can say that software serial is how you want to go. I have a working program for an Atmega8535 on a Futurlec board. It controls zoom, focus, & iris. The program is writen in Bascom Basic. The program can be downloaded from my site nemocam.com on the download page. You will have to view it in a program editor like Pbasic or Bascom. I don’t know much about programing but I will help the best I can. I would like to get a program for the Arduino as well. I am going to switch from Bascom to Arduino because it looks liked there is way more support available.
Here is the code for the Zoom, Focus & Iris writen in Bascom Basic. As far as I know this will control all the Hitachi VK series "chassis" camera. It uses software serial communication. This program was written for use with the Atmega 8535 micro on the Futurlec board similar to the Arduino. On the Futurlec board the serial wire goes directly from the TX pin on the micro to the RX pin on the camera. You can download the control code from the Download page on nemocam.com. The Code is the same for all the cameras in respect to the same function. The Code for the VK-S914 is the easiest to understand. Hope this helps.
Regards,
Dennis
' ***********************************************************************************************
' * *
' * Title : VK-S274 & VK-S274R SERIES Hitachi Block Camera Controller *
' * Version : 1.1 Beta *
' * Last Updated : 02.12.2008 *
' * Target Device : ATMEGA8535 *
' * Author : Farmtech & Neptune769 *
' * Support : Try Skype Name : farmtech_dk or in MCS Bascom Forum *
' * Program code : BASCOM AVR *
' * Hardware req. : VK-S274 or VK-S274R SERIES Hitachi Block Camera *
' * Description : Control : Zoom - Focus & Iris Via Serialport on Camera *
' * Baud for camera : 4800.8.E.1 : Even Parity default for camera *
' * : 9600.8.N.1 but need setup in Camera (:WE05EF0) *
' * *
' * More Commands : See Datasheet lots of other stuff you can do. *
' * *
' * Datasheet : http://www.data-sheet.net/Vk-s454+ebook+pdf.html *
' * : http://ip.gliebetronics.com:800/hitachi/S274R_Comm_E11.pdf *
' * *
' * Copyright : None use it as you like *
' * *
' **************************************************************************************************
$regfile = "m8535.dat"
$crystal = 8000000
$hwstack = 40
$swstack = 30
$framesize = 60
Open "comd.2:4800,8,e,1" For Output As #1 ' 4800 bps , even Parity ; default for camera
'Config Ports for the 6 buttons n PortC we use buttons to GND
Config Portc.0 = Input : Set Portc.0 'Zoom NEAR Button
Config Portc.1 = Input : Set Portc.1 'Zoom FAR Button
Config Portc.2 = Input : Set Portc.2 'Focus NEAR Button IN
Config Portc.3 = Input : Set Portc.3 'Focus FAR Button OUT
Config Portc.4 = Input : Set Portc.4 'Iris offset (average) + Button
Config Portc.5 = Input : Set Portc.5 'Iris offset (average) - Button
Config Portc.6 = Input : Set Portc.6 'Freeze ON / OFF Toggle Button
'Config Portc.7 = Input : Set Portc.7 'not used yet Button
Dim I As Byte , Irish As Byte , Irisl As Byte , Irisavg As Byte , Freezebit As Byte
'Print Version()
'setup Camera
Print #1 , ":WFCCB01" ' Switch the continuous digital zoom ON
Waitms 10
Print #1 , ":WFDFC10" ' Zoom speed normal
Waitms 10
Print #1 , ":WFCCB40" ' Switch the instant digital zoom ON
Waitms 10
Print #1 , ":WFCBBA8" ' Auto focus ON allways (not on manual Focus)
'setup Iris offset (average) level
Irisavg = &H40 ' Iris is normal hex 40 i hope
Irish = 0 ' Bit set for Iris to HIGH
Irisl = 0 ' Bit set for Iris to LOW
Freezebit = 0 ' togglebit for freez images
Wait 1
'The main program
Do
If Pinc.0 = 0 Then
Print #1 , ":WFCBB99" ' zoom near
Bitwait Pinc.0 , Set ' wait for button relace
Print #1 , ":WFCBBFE" ' stop
Print #1 , ":WFCBBA8" ' Auto focus on
Waitms 300 ' wait for auto zoom to get focus
End If
If Pinc.1 = 0 Then
Print #1 , ":WFCBB9B" ' zoom far
Bitwait Pinc.1 , Set ' wait for button relace
Print #1 , ":WFCBBFE" ' stop
Print #1 , ":WFCBBA8" ' Auto focus on
Waitms 300 ' wait for auto zoom to get focus
End If
If Pinc.2 = 0 Then
Print #1 , ":WFCBBFE" ' Auto focus off
Print #1 , ":WFCBBAA" ' focus near
Bitwait Pinc.2 , Set ' wait for button relace
Print #1 , ":WFCBBFE" ' stop
End If
If Pinc.3 = 0 Then
Print #1 , ":WFCBBFE" ' Auto focus off
Print #1 , ":WFCBBA9" ' focus far
Bitwait Pinc.3 , Set ' wait for button relace
Print #1 , ":WFCBBFE" ' stop
End If
'Iris offset (average) level + Open
If Pinc.4 = 0 And Irish = 0 Then ' if pinc.4 and irisbit high is 0 else skip
Irisl = 0 ' reset to low bit
I = Irisavg + 1 ' to start from known pos
For I = Irisavg To 255 ' Irisavg to High 00 - FF
Print #1 , ":WFD9E" ; Hex(i) ' Iris offset (average) send
Irisavg = I ' put I count into Irisavg
If I = 255 Then ' If MAX Iris then exit for
Irish = 1 ' Set Iris bit TO high so it dont do the OPEN until you have closed it a bit
Exit For
End If
If Pinc.4 = 1 Then Exit For ' check for button relace
Next ' next i
End If
'Iris offset (average) level - Close
If Pinc.5 = 0 And Irisl = 0 Then ' if pinc.5 and irisbit low is 0 else skip
Irish = 0 ' reset to high bit
I = Irisavg ' to start from known pos
For I = Irisavg To 0 Step -1 ' from Irisavg to MIN FF - 00
Print #1 , ":WFD9E" ; Hex(i) ' Iris offset (average) send
Irisavg = I ' put I count into Irisavg
If I = 0 Then ' If MIN Iris then exit for
Irisl = 1 ' Set Iris bit TO low so it dont do the CLOSE until you have open it a bit
Exit For
End If
If Pinc.5 = 1 Then Exit For ' check for button relace
Next ' next i
End If
If Pinc.6 = 0 And Freezebit = 0 Then
Print #1 , ":WFF3301" ' Freeze Field ON
Freezebit = 1 ' set freezebit to freeze OFF
Bitwait Pinc.6 , Set ' check for button relace
End If
If Pinc.6 = 0 And Freezebit = 1 Then
Print #1 , ":WFF3300" ' Freeze OFF
Freezebit = 0 ' set freezebit to freeze ON
Bitwait Pinc.6 , Set ' check for button relace
End If
'If Pinc.7 = 0 Then
' Print #1 , ":" ' not used yet
' Bitwait Pinc.7 , Set
'End If
Loop
Close #1
End
Nothing has worked thus far.
Data Length: 8 bit (This is correct)
Stop Bit: 1 Bit ( I don't know how to get this a part of the program)
Parity: Even ( I don't know how to get this figured into the program)
This is what the camera's instructions say, is needed.
I'm currently reading about Arduino TX serial to RX Serial Device.
I just wish that there was some type of program to send TX to device to get some type of reaction, like a setting, just to check if the communication is actually taking place.
Not sure about this. I guess that because you would most likely need the camera, in order to experiment. I think that it's going to be up to me, to figure this out, by learning.
Ground of the Arduino is connected to the Ground of the Camera. Arduino TX goes to RX of Camera.
Commands are sending out, but I don't have any way of knowing if they are getting to the camera.
So, I'm at a loss until I learn more about the process, I guess.
Data and stop bits are OK, but the parity may be causing you a problem. Arduino comms uses no parity as the default so on average half of the bytes you send will be rejected by the camera if they take the parity seriously.
Have a look at the UART section of the data sheet , section 19.10.4. (I'm assuming an ATmega328 chip)
The UCSRnC register and the UPMn1:0 bits. Set bit 1. Something like this in the setup() func after Serial.begin()
UCSR0C |= (1 << UPM01);
Hopefully the serial funcs won't reset the bits in this register.
I just wish that there was some type of program to send TX to device to get some type of reaction,
Get a terminal program for your PC.
BTW you aren't alone with the frustration, this is par for the course when using a new device.
If you can't get the parity Even it will not work. It must be Even. I know a person that wrote a PIC program that controlled the same kind of camera. But the PIC was Odd Parity and it didn't work until he did something to get it to be Even. I don't remember what he did and I can't access the hard drive where the information is on. Its on my desktop and the motherboard is fried. I'm on my laptop right now.
Also a correction on my last post. I had said that the Command Codes where easier to understand on the VK-S914. However it is the VK-S234 is the one I meant.
I was able to get the e-mail about the PIC program that was not able to do Even Parity. Below is the portion of the e-mail that applies. I hope this helps.
A while back I controlled a VK-S274 camera block from a PIC 16F628. I wrote my program in PBASIC and compiled it in PicBasic Pro. I recall the one hurtle I had to overcome was the fact that my PIC could not talk to the camera block because the default is that the block is set for Even Parity and the PIC cannot send serial data with Even Parity, only no parity. Therefore I had to connect the camera to a PC com port using a circuit to invert the data and convert to TTL levels. Then I was able to set the camera's serial settings to 4800,N,8,1 and save it to EEPROM. Then the PIC could talk to the camera directly without any extra circuitry at 4800,N,8,1,non-inverted.
Found another e-mail regarding the Parity. The PDF mentioned in the Quote is the Command Code document for the VK-S274R camera.
Try talking to it in other baud rates. Maybe the PTZ camera programmed the camera block for a non-default baud rate.
i.e.
4800,8,N,1
9600,8,N,1
4800,8,E,1
9600,8,E,1
Connect your Atmel serial pin to the RX on a PC com port. Open up Hyperterm and set it for the same settings as your program. Do you see the commands coming through? Just to prove your program works and is sending the proper strings.
The only way to reset the camera to any defaults or change any settings is to figure out the current communication settings.
To change the communication baudrate, issue...
:WE05E80 ---> (4800,8,E,1) (This is supposed to be the manufacturer default.)
:WE05EB0 ---> (9600,8,E,1)
:WE05EC0 ---> (4800,8,N,1)
:WE05EF0 ---> (9600,8,N,1)
If you look at the PDF, some commands have RAM and EEPROM area addresses. If you Write to a RAM area the command will change back to default after you power the camera off and on again. If you write any command to the EEPROM area, that setting will stick forever even after the camera is powered off. The above baud rate commands are EEPROM area commands only, therefore once you successfully transmit a baudrate change command to the camera block, it will change permanently and you'll have to then talk to it at the new baud rate in order to change it back.
Interesting, I was fighting an unwinnable war. LOL
Okay, well!
It looks like I'm buying the problem solver.
A full PTZ, and using the arduino's for remote wireless sensors.