This lets you easily mount and control a pan-tilt module right on top of your Raspberry Pi palm-sized computer so you can always keep the action in frame. All with no soldering!

Transcript

This Pimoroni PiK Pan Tilt Hat lets you mount and control a pan tilt module right on top of your Raspberry Pi palm sized computer. I'm going to demonstrate how to set this up, how to get the pan and tilt to run along a set course and then how to control this pan and tilt HAT with your arrow keys on your keyboard whilst taking photos through a Pai camera module with a single button press.

Here on the table is everything you need to get started with this Pimoroni pan and tilt hat. Naturally you're going to need the HAT and I'm going to show you how to put this together in just a sec. I'm going to use the Raspberry Pi official camera module V2 but with this setup any camera module with a similar form factor will work like even this Noir camera here. For this setup I'm going to be using a Raspberry Pi 4 model B but you can definitely use an earlier model. You will also want a microSD card that's been flashed with Raspberry Pi OS, a power supply, a monitor, a HDMI cord and extra peripheries like a keyboard and mouse.

Inside your Pimoroni pan and tilt HAT box it will have a pan tilt PCB, the two servos pre-mounted in a pan tilt bracket, two black sheet acrylic parts which you're going to mount the camera module to, a white sheet acrylic part to attach LEDs to if desired and a selection of nylon screws and bolts. So let's put all these parts together. The first step is to connect the PCB to the bottom of the servo stack. Line up the servo stack on top of the white square on the PCB and use the black nylon fasteners to connect the setup together. You will want the servo to lean off the PCB when you're viewing it from above so that way when you connect the camera module to the Raspberry Pi the ribbon cable will not get in the way of the system. With that firmly attached the next step is to put those camera mounts onto a camera module.

First, peel off the protective layer on the acrylic camera mount parts. Then, with these two black acrylic parts, sandwich the camera module together and connect using the white nylon fasteners. When doing this, take note of the orientation of the acrylic piece and be sure to attach the piece with the larger hole against the camera lens side of your camera module. With these screwed securely together (about hand tight, not much more than that because you don't want to put undue stress bending the camera module or strip those nylon bolts), you can then clip it onto the pan tilt bracket.

The final step is attaching all the electrical connections together, both the camera ribbon cable and the wires for each of the servos. The servo connections go onto their marked spot on the bottom of the PCB. On the bottom of the PCB there's also a connection point for LEDs, but I'm not going to be using them here. Make sure to attach all these correctly. Black or dark brown wires are commonly used on servos to represent the ground wire, red is usually the voltage line, and orange or white are usual colors for the data channel wire. This wire is used to tell the servo the direction and angle to turn to. If attached incorrectly, it can cause damage to the servo, so take note that you're connecting it correctly.

Then, connect the ribbon cable to the CSI connector on the Raspberry Pi board. Make sure the ribbon cable is facing the right way and that it is clipped in correctly. To connect the ribbon cable, lift up the edges of the CSI connector gently, slip the ribbon cable in till it bottoms out, and then push down the edges of the CSI connector. Finally, connect the Raspberry Pi directly to the GPIO pins of the Raspberry Pi. Make sure to line all the GPIO pins up and press the boards together. Once this is done, you have succeeded in putting that hardware together.

Setting up a Pan & Tilt HAT with a Raspberry Pi 4 Model B board is easy. To begin, plug in the microSD card with Raspberry Pi OS, a mouse, a keyboard, the monitor and provide the system with power through the USB-C port. Next, install the Pimoroni custom built Pan & Tilt package to make controlling the servos easier. Connect the system to the internet using the Wi-Fi symbol on the top right and enable the camera which is a setting found under the Raspberry Pi configuration menu under the interfaces tab. Reboot the Raspberry Pi to lock in these changes.

Open up a Raspberry Pi terminal using the black icon in the top left corner of the screen. Installing the packages should take less than four minutes. The first line to type is this and it starts with sudo which means this line is going to be run with admin privileges and is used to update and install all the current packages on the current setup. If prompted, type y and press enter to continue the installing process. The next line to type is a client url command line and that's why it starts with curl and what it's going to do is pull data from an online server to install the specific Pan & Tilt HAT package for this hat. Bash which is what you type at the end of that line is going to automate the installation of all the facets of that installed package to your version of Raspberry Pi OS. Throw one more quick reboot to lock in all these changes.

Pimaruni has a very simple code that you can access and use as soon as you download it the Pan & Tilt package. Installed straight away is perfect for testing whether your Pan & Tilt camera is fully operational and has full

Range of motion can be controlled using the PanTiltHat.Pan or the PanTiltHat.Tilt functions, which accept values between 90 and negative 90. To up the ante, I have created code that uses the arrow keys on our keyboard to control the PanTilt of the camera intuitively and also take pictures with a press of a button. This code can be found on the article page link down below. No extra package is needed to run this code successfully. Copy and paste the code into Thonny IDE and save it on your desktop, naming it keyboardPanTilt.py. Each time you press an arrow key it's going to rotate in that direction five degrees and when you press P on your keyboard it's going to take a photo. When you do run this code make sure you do so from the terminal as it's using a pre-installed package called Cursors that relies on the terminal.

To get the terminal to function correctly, click on the black symbol on the top left of the screen and run it by typing and entering the following two lines:

CD (which stands for change directory) and Python (which summons the Python programming language to run the keyboardPanTilt.py file). Make sure to type the file name correctly and keep in mind that this is going to be case sensitive.

Once entered, you will see a live stream of the camera feed and be able to control the PanTilt HAT and take photos at a whim via your keyboard. The pictures are always saved to the desktop. Each keyboard input is constantly written into the terminal.

The code is fully open source and written as logically as possible, so it is ripe for customization. For instance, you can lower some of the values to slow down the Pan and Tilt speed and make it smoother, or insert a random number generator and watch your Pan and Tilt go wild.

These PanTilt setups are ideal for mini CCTV systems, automatic laser pointers to drive cats wild, or something completely fun like mounting a set of googly eyes on it and turning it into a friendly robot companion. The next step for me will be to combine this PanTilt HAT with face tracking. I just need to figure out how. Hopefully this tutorial has been helpful.

This has got you thinking creatively and willing to jump into this world. Until next time, stay cozy!

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.