I have a Logitech Gamepad F310 USB controller, a computer, and a Amcrest Pan/Tilt/Zoom (PTZ) camera that supports the ONVIF standard. I wanted to control the camera’s motion with the joystick. So I did.
Reading the joystick in Python is super easy using pygame. I ran the demo code toward the bottom of the joystick page as my first step. It showed all axes and buttons working great out of the box with my controller.
Amcrest cameras support the ONVIF protocol. The python-onvif-zeep package supports sending ONVIF commands from modern Python (I used Python 3.10 for this project).
Specific example code demonstrating how to use the package from Python to send PTZ commands to the camera can be found e.g. here.
Given the ability to read the joystick and the ability to control the camera, we just need to glue it together! So I wrote a 250-line package called joy-ptz-cam that does just this.
The package is pretty limited at the moment but does handle PTZ controls. It pans and tilts with the left joystick and zooms when you pull the right trigger and zooms out when you pull the left trigger. (Note that for this particular camera, zoom is purely software, but on an actual zoom cam it would work the optical zoom).
And there you go I saved myself $500 vs. getting one of those fancy joystick camera controller things.
I have a fancier PTZ ONVIF-compliant camera on order which is the real reason I wanted to try this out on the smaller cam.
One thought on “Controlling a Amcrest PTZ camera with a joystick”
Hey man, thanks for the code, this is -exactly- what I was looking for.
I may also do a gui with tkinter. If so, I’ll put it on the hub and link ya.