marklysze / Magic-Pocket-Control-ESP32

Blackmagic Design Camera Control for ESP32 devices (feat. LILYGO T-Display-S3, M5Stack M5CoreS3, M5Stack Basic, M5Stack M5StickC Plus, Freenove ESP32-S3-WROOM
GNU General Public License v3.0
18 stars 4 forks source link
blackmagicdesign ble bluetooth bmd camera

:movie_camera: Magic Pocket Control for ESP32 devices

Blackmagic Design camera control on a LILYGO T-Display-S3, M5Stack M5CoreS3, M5Stack M5StickC Plus, Freenove ESP32-S3-WROOM, or (hopefully) any other ESP32 device.

Designed for the Pocket 4K, Pocket 6K/G2/Pro, USRA G2 4.6K, URSA 12K.

Coding is in C++ and setup for development in Visual Studio Code with the PlatformIO extension.

NOTE: If you're using Mac or Linux and recently cloned the repository and were not able to get it running then please try again as all backslashes in the #includes have been changed to forward slashes.

Magic Pocket Control

Video with demos (opens YouTube):

License: GPL v3

:star: How about a Star?

What can it do?

The key features are:

What's new?

December 2023

M5Stack Rotary Encoder

M5Stack Rotary Encoder

Added lens focusing on the M5Stack CoreS3 using the M5Stack rotary encoder. Initial testing on Pocket 6K and URSA Mini Pro G2.

Two modes:

  1. Free Focus - turn the rotary encoder and it will change focus position freely
  2. Range - turn the rotary encoder and it behaves more like a follow-focus with hard stops

Why two modes? The BMD EF-based cameras have variations in the lenses supported and how to control them. The free-focus uses an offset for each step on the rotary encoder - this works on the URSA Mini Pro G2. The Range sends specific positions to the camera - this didn't work on the URSA Mini Pro G2 but did on the Pocket 6K (where both options worked). Additionally, for the free-focus offset different values moved the lens focus position different amounts depending on the lens.

Therefore, you'll likely need to play around to see if this works for you!

--

Added support for the URSA Mini Pro G2 for general features - see the M5Stack CoreS3 main file.

Thanks to Paul Jones for lending me his camera!

What can you do?

I hope you find the functionality useful and it would be great if you could contribute your improvements, suggestions, or general feedback to the project!

Do you use TouchDesigner?

If you're a TouchDesigner user, check out nelsoniso's repository here which utilises the serial output of this project to update TouchDesigner in real-time and allow you to control the settings of the camera from TouchDesigner, it's very cool.

The main-m5stack-grey-touchdesigner.cpp file has the serial in and out functionality.

Has it been tested?

It needs to be thoroughly tested and even though they do contain fairly basic functionality, there's still unknowns around connection longevity, camera firmware changes, known issues in camera firmware, and the position of the sun in the sky.

Here's the state of cameras and firmware.

Camera Firmware Status
Pocket 4K 7.9.1 $\color{green}{\textsf{OK}}$ $\color{orange}{\textsf{ (BRAW <-> ProRes change firmware bug)}}$
Pocket 4K 8.1 $\color{green}{\textsf{OK}}$ $\color{orange}{\textsf{ (See Known Bugs below)}}$
Pocket 6K 7.9.1 $\color{green}{\textsf{OK}}$ $\color{orange}{\textsf{ (BRAW <-> ProRes change firmware bug)}}$
Pocket 6K 8.1 $\color{green}{\textsf{OK}}$ $\color{orange}{\textsf{ (See Known Bugs below)}}$
Pocket 6K G2 ... PeterP27 confirmed $\color{green}{\textsf{OK}}$
Pocket 6K Pro ... Not Tested
URSA Mini Pro 4.6K G2 ... $\color{green}{\textsf{OK}}$ (Thanks Paul Jones!)
URSA Mini Pro 12K ... Not Tested
URSA Mini Pro 12K OLPF ... Not Tested

If you're in Sydney, Australia, and would be able to lend me a camera I haven't tested for a day to test so we know it works, that would be amazing.

Known bugs

Why?

My primary objective was to convert a Windows-based application I had for controlling my cameras to a small portable device.

These devices are so small, portable, and don't require much power.

I'm opening up to the community who may find this useful or would like to contribute to it. Any contribution you make will be appreciated!

Why did I choose the LILYGO T-Display-S3 Touch version to program for?

I found this device had all the necessary components needed to connect and interact with the cameras:

What ESP32 devices are support?

Hopefully all of them are supported and I have a few that I'm developing for to check they work - LILYGO T-Display-S3, M5Stack M5CoreS3, M5Stack M5StickC Plus, Freenove ESP32-S3-WROOM.

It would be great if you could let the community know what ESP32 device you have and whether it works and I'll update this note.

Can't I use a mobile/tablet app?

Yes, indeed you can! Alternatively, this is designed as a lightweight small device that allows you to see and control basic functions of your camera. It can act as a dedicated device for each camera you have, or simply to avoid touching the camera to control it (when it's on a gimbal, mounted somewhere, or in a moving car :) ).

How do I run this?

You will need the following:

Configuring PlatformIO

It is important that you use PlatformIO if you want to use the repository as it is. Feel free to use the libraries in your own project if you don't want to develop for the repository. The following notes are based on using this repository

platformio.ini - This file tells PlatformIO what boards you have and which "main-[board name].cpp" file to use. In the src/main/ folder you'll see a set of main cpp files, each one is the program that relates to the board. When you compile and upload the program to your board PlatformIO uses the main file that matches the name of the board you have chosen (in the bottom taskbar of Visual Studio Code you can choose the environment you are using which represents the board. For example, programming for the M5Stack M5StickC Plus will be done in the src/main/main-m5stick-c.cpp file because that has the name related to the environment chosen when we select "env:m5stick-c".

If you want to add your own board and program for it, do so like this:

  1. Open platformio.ini and check if the board already exists, if so you're good to go.
  2. If not, go to the PlatformIO boards page and find your board. If you don't find it you'll need to find something as close as possible.
  3. Click on the board name and it will open up its own page
  4. Look for the ID of the board. For example, for the Adafruit ItsyBitsy ESP32 the ID is adafruit_itsybitsy_esp32.
  5. Add the following to the end of the platformio.ini file (putting in the ID of the board):
    [env:adafruit_itsybitsy_esp32]
    platform = espressif32
    board = adafruit_itsybitsy_esp32
  6. Save the file
  7. Create a main source file under src/main/ that has the ID of the board prefixed by "main-", e.g. "src/main/main-adafruit_itsybitsy_esp32.cpp"
  8. Choose the new environment using the bottom environment bottom of Visual Studio Code
  9. Click Build to compile (make sure your main file has at least "void setup()" and "void loop()" defined)

You will need to do the following to ensure that the TFT_eSPI library is configured for the LilyGO T-Display-S3 or any other device that you're using it for:

What can we do with these cameras?

See the Blackmagic Camera Control Developer Information document, here. It's not up-to-date and I've used the sample code, noted below, to update functionality. There remains other functionality not documented or in the code samples that has been worked out by the community.

I converted a lot of the Swift (Mac) code from Blackmagic Design's Cameras Code Samples, Download here

How does the program work?

Control System

Camera Connection

Camera

Changing State

Establishing a Connection

Debugging

Thank you to...

FAQ

  1. I'm not seeing anything on the screen?
    • Ensure you have uncommented the T-Display-S3 line (Around line 133) in the User_Setup_Select.h file for TFT_eSPI and also commented out the default line (Around line 30). In PlatformIO this is under libdeps\lilygo-t-display-s3\TFT_eSPI\TFT_eSPI.h
  2. It's not working on my camera?
    • Ensure that you have Bluetooth turned on in the Setup menu on the camera
    • I have tested with the Pocket 4K and 6K (Original) - contact me if you are having trouble connecting to your camera.
    • The version of your firmware may need to be updated to the latest version so the protocol used is compatible with your camera.
  3. How do I enter the PIN code to connect?
    • If you're using the LILYGO T-Display-S3 touch-version there's an on-screen numpad that appears when you're required to enter the code.
    • If you're using another ESP32, such as one without a screen, you can use the Serial console to enter the PIN code (see the M5Stick example code) for the first time you connect. Once you've done that you can unplug the device from your computer.
    • Once you've entered the code and connected succesfully both devices should remember each other for future connections, unless you clear the connections (as can be done on the Camera under the Bluetooth screen).

I'm developing with the code but having trouble

See the programming and device tips document, DevelopmentTips.md.

Disclaimer

License

Contact me

You can contact me here

:thumbsup: Thank you

Thanks for being part of the community! :sparkles: