How To Create a Bluetooth Raspberry Pi Camera Trigger - Tom's Hardware

1 year ago 46

The caller Raspberry Pi Camera Module 3 offers exceptional representation prime and a prime betwixt a modular (75 degrees) and wide (120 degrees) lenses. Best of all, we present person autofocus. Taking pictures with the Picamera2 is easy, but sometimes we conscionable privation to property a fastener and instrumentality a picture, and look successful the shot!

In this task we volition usage Blue Dot, a Python module and Android app to make a Bluetooth controlled camera trigger. Thanks to Blue Dot’s casual to usage room and Picamera2’s verbose operation we volition beryllium capturing 1080p photos via a tiny magnitude of code.

For This Project You Will Need

  • A Raspberry Pi 3 oregon 4
  • A Raspberry Pi Camera
  • An Android device

Installing the Raspberry Pi Camera Module

 1. Open the camera larboard by mildly lifting the integrative fastener upwards.

Raspberry Pi Camera Module

(Image credit: Tom's Hardware)

2. Insert the ribbon connector with the bluish tab facing the USB / Ethernet ports. Raspberry Pi Zero users volition request to usage an adapter and link the camera to the larboard connected the close broadside of the board.

Raspberry Pi Camera Module

(Image credit: Tom's Hardware)

3. Close the fastener connected the connector and springiness it a precise gentle propulsion to marque definite it is successful place.

4. Power up the Raspberry Pi to the desktop. Open a terminal and instal the latest Picamera updates.

sudo apt update && sudo apt upgrade -y

5. From the terminal, cheque that your camera is moving properly. The libcamera bid is useful for rapidly checking that our camera is connected and moving arsenic expected.

libcamera-hello

Installing Blue Dot

Blue Dot is the instauration of Martin O’Hanlon and it provides a genuinely elemental means to remotely power a Raspberry Pi. The sanction “Blue Dot” represents the large, bluish dot that dominates the Android device’s screen. We’re going to usage Blue Dot arsenic a large, bluish fastener to trigger the camera to instrumentality a picture.

1. On your Android instrumentality unfastened the Google Play Store and hunt for Blue Dot. Alternatively follow this link.

2. Install Blue Dot connected your Android device.

3. On your Raspberry Pi, unfastened a terminal and instal Blue Dot’s Python library.

sudo pip3 instal bluedot

4. Go to the Bluetooth menu, close click and prime “Make Discoverable”.

Bluetooth Raspberry Pi Camera Trigger

(Image credit: Tom's Hardware)

5. On your Android instrumentality spell to the Settings >> Connected devices and prime Pair New Device.

6. Select “raspberrypi” and travel the pairing instructions. If your Raspberry Pi has a antithetic hostname, past “raspberrypi” volition not appear, look for your hostname.

Bluetooth Raspberry Pi Camera Trigger

(Image credit: Tom's Hardware)

With our Android instrumentality and Raspberry Pi present connected we volition constitute a speedy Python publication to cheque that Blue Dot tin pass betwixt the 2 devices.

1. Open Thonny, recovered successful the main paper nether Programming.

2. Create a caller record and import the Blue Dot Python library.

from bluedot import BlueDot

3. Create an object, bd, that we volition usage to enactment with the library.

sudo pip3 instal bluedot

4. Wait for the idiosyncratic to property the bluish button. This enactment of Python is simply a blocker. It volition hold until the idiosyncratic interacts. When that happens the codification moves to the adjacent line.

bd.wait_for_press()

5. Print a connection to the Python shell.

print("You pressed the bluish dot!")

6. Save the codification arsenic bd-test.py and click Run. The codification volition hold for a transportation from our Android device.

7. On your Android device, unfastened Blue Dot.

8. Select the hostname of your Raspberry Pi. Typically this is “raspberrypi”. 

Bluetooth Raspberry Pi Camera Trigger

(Image credit: Tom's Hardware)

9. Click connected the Blue Dot to trigger the Python codification into action. You should spot a connection successful the Python shell.

Bluetooth Raspberry Pi Camera Trigger

(Image credit: Tom's Hardware)

Complete Test Code Listing

from bluedot import BlueDot bd = BlueDot() bd.wait_for_press() print("You pressed the bluish dot!")

Creating a Camera Trigger with Blue Dot

Bluetooth Raspberry Pi Camera Trigger

(Image credit: Tom's Hardware)

The extremity of this task is to make a camera trigger with Blue Dot. When the fastener is pressed a relation is launched connected the Raspberry Pi which handles taking a photograph.

1. Create a caller record and import the Blue Dot Python library.

from bluedot import BlueDot

2. Import Picamera2 and libcamera. The preview people is utilized to make preview windows, utile for framing a shot. The controls people from libcamera enables america to usage autofocus with the caller Camera Module 3.

from picamera2 import Picamera2, Preview from libcamera import controls

3. Import the intermission relation from awesome and past the clip library. Pause volition beryllium utilized to halt the codification from exiting. Time volition hold the codification aft a preview model is created, giving america clip to framework a shot.

from awesome import pause import time

4. Create an object, bd, that we volition usage to enactment with the library.

bd = BlueDot()

5. Create an object, picam2, that volition alteration america to easy usage the Picamera2 library.

picam2 = Picamera2()

6. Define a function, take_picture() that volition beryllium utilized to instrumentality a picture. Functions enactment by calling their name, this triggers the relation to tally done each of the steps wrong it.

7. Create a configuration for the camera to instrumentality inactive images. This sets the representation size to 1080p, portion preview windows volition beryllium 720p.

camera_config = picam2.create_still_configuration(main={"size": (1920, 1080)}, lores={"size": (1280, 720)}, display="lores")

8. Set Picamera2 to usage the caller configuration.

picam2.configure(camera_config)

9. Start a preview model with a 720p resolution. We acceptable the presumption utilizing X and Y coordinates, different it defaults to 0,0. Tweak this to conscionable your needs.

picam2.start_preview(Preview.QTGL, x=100, y=200, width=1280, height=720)

10. Show the preview window.

picam2.start(show_preview=True)

11. Set the camera to usage continuous autofocus. Note, this lone works with the Camera Module 3.

picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous})

12. Pause for 2 seconds earlier capturing the representation to a record called picam1.jpg.

time.sleep(2) picam2.capture_file("picam1.jpg")

13. Close the preview model and past halt Picamera2.

picam2.stop_preview() picam2.stop()

14. Out of the function, use Blue Dot’s “when_pressed” relation to respond to idiosyncratic input by moving the take_picture function.

bd.when_pressed = take_picture

15. Use intermission to forestall the codification from exiting.

pause()

16. Save the codification arsenic bluedot_camera.py and click Run to commencement the code. You volition spot that the codification waits for the Android instrumentality to connect.

17. On your Android device, unfastened Blue Dot.

18. Select the hostname of your Raspberry Pi. Typically this is “raspberrypi”.

19. Click connected the Blue Dot to trigger the camera. You volition spot the preview model look and then, 2 seconds later, an representation volition beryllium saved to the micro SD card. Repeated presses volition make a caller image, but arsenic the filename is the aforesaid it volition overwrite each time.

Complete Code Listing

from bluedot import BlueDot from picamera2 import Picamera2, Preview from libcamera import controls from awesome import pause import time bd = BlueDot() picam2 = Picamera2() def take_picture(): camera_config = picam2.create_still_configuration(main={"size": (1920, 1080)}, lores={"size": (1280, 720)}, display="lores") picam2.configure(camera_config) picam2.start_preview(Preview.QTGL, x=100, y=200, width=1280, height=720) picam2.start(show_preview=True) picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous}) time.sleep(2) picam2.capture_file("picam1.jpg") picam2.stop_preview() picam2.stop() bd.when_pressed = take_picture pause()

Get instant entree to breaking news, in-depth reviews and adjuvant tips.

Read Entire Article