ESP32 + BaseCam Bluetooth Gimbal Control

by Penguingineer in Circuits > Arduino

1148 Views, 7 Favorites, 0 Comments

ESP32 + BaseCam Bluetooth Gimbal Control

Thumbnail Choice 1 Aspect Ratio Change No Text.png
Thumbnail Choice 1 Aspect Ratio Change No Text.png
Thumbnail Choice 1.jpg
IMG_20240802_175355120_HDR.jpg

Demo video for this project is below!

The BaseCam Brushless Gimbal Controller (BGC) family of products is widely used in the cinematography industry for camera gimbal control and stabilization systems, with an introductory YouTube video here:

In addition to having 3 x DM5005 gimbal motors react to the on-board IMU on a BaseCam Extended Long controller board, I wanted to be able to read and process signals from 3 x independent single-axis joysticks to control the roll, pitch, and yaw of those same gimbal motors through the BaseCam controller board. To do this, I utilized an ESP32 microcontroller to read inputs from the joysticks and relay those values to the BaseCam controller, directly wired in one case, and wirelessly through 2 x ESP32 boards using Bluetooth Low Energy (BLE) in another case.

The BaseCam family of gimbal controllers has functionality for taking in different signal types, including PWM, and analog-to-digital (ADC) readings. However, I wanted to have control over the way the signals would be processed before being read-in by the BaseCam controller, by way of an ESP32-S3 dev board. This project's wiring and setup allow for that type of control, either directly wired, or wirelessly using BLE. I hope it is useful for your next BaseCam project!

Disclaimer: Some of the links in this article are affiliate links. This means that if you click through the link and make a purchase, I earn a commission at no extra cost to you.

Note/warning - when working with LiPo batteries, motors, hot soldering irons, and other prototyping equipment, please take care to protect yourself from injury by wearing appropriate safety attire, including safety glasses, and a grounding strap to prevent electric shock if needed. Work steadily and carefully, and double check your wiring (polarity the battery, mounting/securing the motors, etc.) before powering on your devices to minimize the risk of self-injury, and additionally to protect the components from getting fried.

Supplies

Iso View White Background.png
Cap Removed White Background.png
In Hand White Background.jpg

PlatformIO + BaseCam API Setup

platformio INI Configuration File.png
BaseCam Adjustable Variables List.png
Serial API Configuration Marked.png

BaseCam offers a Serial API (Application Programming Interface) so that external controllers can interact with their product line using PlatformIO through Visual Studio Code. The BaseCam SimpleBGC Extended Long web page references the Serial API:

The API can be used with any Arduino-based microcontroller. In this project, I'm using an ESP32-S3 dev board, which can be programmed the same way as a standard Arduino board, either using the Arduino IDE, or PlatformIO, which is an extension for Visual Studio. The BaseCam API examples are provided as PlatformIO projects, so we'll use PlatformIO for this project.

  • PlatformIO web page: https://platformio.org/
  • Visual Studio Code web page: https://code.visualstudio.com/
  • Here's a great introductory video with examples to get started with PlatformIO if it's your first time learning it: Getting Started with PlatformIO by DroneBot Workshops

Download Visual Studio Code, and install PlatformIO. Download all Serial API files from the following Github link, and install any necessary API libraries on your computer: https://github.com/basecamelectronics/sbgc32-serial-api

To configure PlatformIO to work with the ESP32-S3 DevKitC dev board, the platformio.ini configuration file will look like the following screenshot. After successfully installing Visual Studio Code and PlatformIO on your computer, you will be able to flash this project's code to your ESP32.

The BaseCam API gives access to many control variables, including:

  • Pitch, roll, yaw speed
  • Pitch, roll, yaw angle
  • Nearly everything that can be adjusted in the BaseCam GUI software is also accessible via its Serial API.
  • In the PlatformIO project in my Github, check the list of adjustable variables (file name adjvars.h) to see the list of additional parameters that can be changed.

To be able to change the Adjustable Variables and set other variables, open serialAPI_Config.h and set the following two parameters to be SET_ON as in the above screenshot. If you want to control other aspects of the GUI, you can set their corresponding parameters (with enable that control access) to be SET_ON or SET_OFF as required, e.g.:

  • #define SBGC_ADJVAR_MODULE SET_ON
  • #define SBGC_CONTROL_MODULESET_ON

BaseCam SimpleBGC GUI Setup (Before Gimbal Motors)

Firmware Upgrade - Red.png
RC ROLL pin mode - Red.png
Main IMU Sensor - Red.png
Serial Connection - Red.png
Calibrate IMU Sensors Markup.png
Sensor Calibration Helper Markup.png

Download the SimpleBGC GUI software from BaseCam's website, and run the application file (versions available for Windows, Mac and Linux). This program is used to communicate with the BaseCam board.

Connect your BaseCam controller board to your computer, select the COM port corresponding to the controller in the drop-down menu in the top left of the window, and click the Connect button nearby to connect to the controller board. Upon connection confirmation, navigate to the Firmware Upgrade tab, and update the firmware on your BaseCam controller board, as well as the GUI version, if needed.

Navigate to the RC Settings tab > Input Configuration > set the RC_ROLL pin mode to: Serial port (Serial API, etc.) This will enable the BaseCam board to receive the serial commands from the ESP32-S3 dev board that's connected to it.

Navigate to the Hardware tab > Main IMU Sensor section. Enable the checkbox: Use the on-board IMU if main IMU is not detected - I like to do this to verify that the BaseCam board is communicating with the PC, but if your BaseCam board doesn't have an on-board IMU (e.g. the BaseCam SimpleBGC 32-bit CAN_MCU controller board), you can leave this box unchecked.

In that same tab (Hardware), scroll down to the Serial Connection section and set both Main serial port speed and RC_SERIAL port speed to 115200. This is the baud rate that is used to communicate with the ESP32 which is connected via its Serial (RX, TX) pins.

To enable the BaseCam Extended Long controller's on-board IMU to function properly, it needs to be calibrated on at least 2 x axes. To do this, power the BaseCam controller, and lay it flat on/parallel to a tabletop. Press the calibration button and wait until a blue checkmark appears next to the closest axis (e.g. +/-X, +/-Y, +/-Z). Turn the BaseCam board on its other edges, and calibrate the board in each position. The more positions that are calibrated (indicated by a blue check mark), the better.

Prepare Gimbal Motors With CANbus Driver Board

DM5005 Install CAN Driver Board.jpg
IMG_20240802_174417574.jpg
IMG_20240802_174533478.jpg
IMG_20240802_174212191.jpg
IMG_20240802_175225602.jpg

The gimbal motors I'm using for this project are the DM5005 motors from his vendor:

http://shop.smc-powers.com/DM5005.html

To use these motors with the BaseCam Extended Long control board, you'll need to install the appropriate CANbus motor driver board from the same vendor:

http://shop.smc-powers.com/GBC-CAN04050

Solder the 3 x gimbal motor phase orange wires to the (A,B,C?) pads on the driver board as shown [Add photos]. The 2 x thin red wires are non-polarized, and are for a thermistor that is built into the gimbal motor. The thermistor is not compatible with this particular CANbus motor driver board, and additionally, adding thermistor temperature sensing is not necessary for this project, so I left those disconnected.

With the motor phase wires soldered, install the driver board onto the gimbal motor using 2 x M2 screws. For each of the three gimbal motors, the CANbus slave address can be set using the DIP switch on the bottom of the driver board. Each motor needs to have its own CAN ID/address so the BaseCam controller can distinguish between them. There are 4 x switches on the DIP switch, and each can be set to ON or OFF. By setting different combinations of ON/OFF for the first 3 x switches (#1, 2, and 3) on the driver board, you can set up to 8 x individual CAN ID's/addresses. Setting switch #4 to ON includes a 120 ohm resistor in the CAN circuit, and is recommended by the vendor. For this project, I set the CAN IDs for the motors to 1, 2, and 4, corresponding to the following DIP switch positions You can choose any combination of CAN IDs you wish, so long as each motor has its own CAN ID.

  • CAN ID #1 - switch 1 ON, switch 2 OFF, switch 3 OFF
  • CAN ID #2 - switch 1 OFF, switch 2 ON, switch 3 OFF
  • CAN ID #4 - switch 1 OFF, switch 2 OFF, switch 3 ON

After mounting the CANbus driver boards to the gimbal motors and setting their DIP switches as instructed above, you'll need to create cables that connect the CAN motor driver boards to (1) the BaseCam controller board (CAN high and CAN low wires), and to (2) a battery or other power supply (between 12-28VDC) which will power the gimbal motors. The connector on the CAN driver board is 6-pin ZH 1.5mm. The connector on the BaseCam board is 4-pin, 1.25mm pitch. If you'd like to quickly assemble some of the wires with less soldering, you can additionally use these clamp-on wire connectors which I've found useful for prototyping.

Create a cable with a male XT-60 connector on one end, which can be plugged into the battery. Remember to add heat shrink if needed, to prevent electrical shorts.

Regarding CAN protocol wiring - CAN signaling is differential, meaning that the difference in the voltage levels between the High and Low CAN wires is what is used for interpreting digital signals sent over the wire. For that reason, it is recommended that the High and Low CAN wires (blue and yellow) be twisted in a helix shape around one another, as this will help to reduce electromagnetic (EM) interference which could otherwise disrupt the signals over the wires. By twisting the wires in this way, any noise received by one wire would also be received by the other, so the net change in the CAN signal will be minimized.

Wiring:

  • Connect the positive (red) wire of the LiPo battery (14.8VDC nominal voltage) in parallel to the VCC pins on the 3 x CAN motor driver boards.
  • Connect the negative (black) terminal of the LiPo battery in parallel to the GND pins on the 3 x CAN motor driver boards.
  • Connect the CAN_H pin on the BaseCam controller in parallel to the CANH pins on the 3 x CAN motor driver boards (yellow wire.)
  • Connect the CAN_L pin on the BaseCam controller in parallel to the CANH pins on the 3 x CAN motor driver boards (blue wire.)

Below (and on the Github repository for this project), I've shared a CAN wiring and communication protocol document from the gimbal motors vendor, called SMC - MS MF RMD motor CAN protocol V2.35.pdf

ESP32 Wiring - Direct Connection

BaseCam ESP32 + Joysticks Wiring Diagram - Direct.png

For the case of using only 1 x ESP32-S3 dev board to read the 3 x single-axis joysticks connect VCC and GND for each of the 3 x joysticks to 3V3 and GND on the ESP32 board, respectively. The joystick modules act as spring-loaded potentiometers, so we'll make use of ESP32 pins that have analog to digital conversion (ADC) capability (GPIO4, GPIO5, GPIO6.) We'll use the hardware Serial1 pins on the ESP32 (GPIO17, GPIO18) to connect to the UART1_RX, UART1_TX pins on the BaseCam controller board. Note that the RX pin on the ESP32 is connected to the TX pin on the BaseCam board, and vice versa. If you'd like to power the ESP32 from the BaseCam board, tie the 5V pins on both boards together, and tie the GND pins on both boards together. Connect the BaseCam board to your computer to provide 5V power, and also communicate between the BaseCam Simple GUI software and the controller board.

Pin Connections Summary:

  • ESP32 GPIO6 - Joystick #1 SIG pin (white)
  • ESP32 GPIO7 - Joystick #2 SIG pin (green)
  • ESP32 GPIO15 - Joystick #3 SIG pin (purple)
  • ESP32 RX (GPIO18) - BaseCam UART1_TX pin (blue)
  • ESP32 TX (GPIO17) - BaseCam UART1_RX pin (green)
  • ESP32 5V pin - BaseCam 5V pin (red)
  • ESP32 3V3 pin - Tied to all 3 x joystick VCC pins (yellow)
  • ESP32 GND pin - Tied to all 3 x joystick GND pins, as well as the BaseCam GND pin (black)
  • Battery positive (red) terminal - connected in parallel to the VCC pin for all 3 x gimbal motor drivers, as well as the +BAT pin on the BaseCam board.
  • Battery negative (black) terminal - connected in parallel to the GND pin for all 3 x gimbal motor drivers, as well as the battery GND pin (just beneath the positive BAT+ pin) on the BaseCam board.
  • BaseCam CAN_H pin - connected in parallel to the CANH pin all on all 3 x gimbal motor drivers (yellow wire)
  • BaseCam CAN_L pin - connected in parallel to the CANL pin all on all 3 x gimbal motor drivers (blue wire)

ESP32 Wiring - Bluetooth Low Energy (BLE)

BaseCam ESP32 + Joysticks Wiring Diagram - BLE.png

For the case of using 2 x ESP32's to relay the joystick information to the BaseCam controller, the first Client/Master ESP32 reads the 3 x joysticks, and continuously sends those readings to the second Peripheral/Slave ESP32, which in turn relays them to the BaseCam controller using the BaseCam API. With respect to wiring, this just means removing the 3 x joystick connections from the Peripheral ESP32, and instead connecting them to the Client ESP32. All other wiring remains the same as the Direct Wiring case. In addition, the primary/client ESP32-S3 dev board can be powered from any 5V source, e.g. a battery bank, laptop USB port, or a wall-powered 5VDC power supply via a micro-USB to USB-A cable.

Update Gimbal Driver Firmware and BaseCam GUI Settings

CAN Modules Scan Devices Markup.png
Gimbal Flash Firmware Markup.png
Gimbal Hardware Num Poles Markup.png
Calibrate R and L Markup.png

To enable the CAN motor driver boards to work properly, you'll need to load the right firmware onto them. After connecting the motors to the CAN_H and CAN_L pins on the BaseCam controller board, connect the BaseCam board to your computer and run the BaseCam SimpleBGC GUI software. To update the drivers on the CAN boards:

  1. Download the CAN_DRV_New.zip file from my Github, extract it, and inside that zip folder, there is a file called CAN_DRV_New.bin - this is the firmware upgrade file that must be applied to each CAN motor driver board.
  2. Connect to the BaseCam board by selecting the appropriate COM (USB) port.
  3. Navigate to the Firmware Upgrade tab --> Connected Modules sub-tab.
  4. Select the gimbal motor whose firmware you want to update.
  5. Select the firmware file using the Browse button, and then click the FLASH button to load the firmware onto that gimbal driver board.
  6. Repeat the above steps to update the firmware for all 3 x gimbal motors.

Next, after having updated the gimbal drivers' firmware, in the BaseCam SimpleBGC GUI software, navigate to the Hardware tab. Set the motor poles for each motor to 28 (this is specified in the DM5005 product page on the SMC Powers website.)

Calibrate the resistance (R) and inductance (L) for each motor as well, and click the Write button to save that setting to the motor driver boards after doing so for each motor.

Assembly

IMG_20240802_175355120_HDR.jpg
IMG_20240802_175256572.jpg
IMG_20240802_175032372.jpg
IMG_20240802_175014574.jpg
IMG_20240802_175120919.jpg
CAD Assembly Skew.png
CAD Assembly Front.png
CAD Joysticks.png
CAD BaseCam.png

I mounted the single-axis joysticks, secondary/peripheral ESP32-S3 dev board, and BaseCam controller board on a 3D-printed base (files available for download here), and inserted the ESP32-S3 dev board into a breadboard with adhesive backing to stick to the printed base. The joysticks are mounted using M2 x 10mm standoffs. The BaseCam Extended Long board is mounted using M3 x 10mm standoffs. Finally, the 3 x pointer/arrow indicators used to show the gimbal motor directions were attached to the gimbals using M3 x 6mm screws. All 3D-printed parts were printed from 1.75mm thick black PLA+ filament using a Voxelabs Aries 3D printer.

Code - Direct Connection (1 X ESP32 Only)

MainCPP_False_Marked.png

The code for this project can be found on my Github page:

The code is structured as a PlatformIO project. To import and use the project files, download and extract the zip file, and in Visual Studio Code > PlatformIO, select File > Open Folder. I modified the code using an example code from BaseCam as inspiration:

The code is written so the user can choose between the directly-wired arrangement, or a wireless (Bluetooth) arrangement. For this case, set the variable BLE_Mode_boolean in main.cpp to false. Upload the code to the ESP32-S3 dev board with PlatformIO using a micro USB cable, and verify that the installation was successful before proceeding. If you'd like to see any debugging messages from the ESP32, you can leave it connected to one USB port on your computer during operation.

Code flow:

  • main.cpp: The primary code that contains the typical setup() and loop() functions for Arduino-compatible scripts.
  • The ESP32 initializes its connection to the BaseCam controller first. If the ESP32 has an issue connecting to the BaseCam via its serial pins, it will throw an RX TIMEOUT ERROR message. Double check that your wiring matches the wiring diagram.
  • The code initiates the BLE receiving connection (if in Bluetooth mode.)
  • In the loop, if not in Bluetooth mode, the ESP32 continuously reads from the 3 x connected joysticks directly, puts their read values into a structure object called Control to update its Pitch, Roll, and Yaw speed values. If in Bluetooth mode, instead of reading the joystick values directly, whenever the ESP32 receives a comma-delimited string of 3 x integer values, those values are parsed and then used to update the Control structure object.
  • The Control structure object, now updated, is pushed to the connected BaseCam controller using the following command: SBGC32_Control(&SBGC32_Device, &Control);

Code - Bluetooth Low Energy (BLE) Using 2 X ESP32s

MainCPP_True_Marked.png
Arduino IDE Readings Marked.png
PlatformIO Readings Marked.png

For the Bluetooth Low Energy case, the ESP32 connected to the serial pins on the BaseCam controller board runs the same PlatformIO project code as for the previous case, except In that same code, set the variable BLE_Mode_boolean to true, and then flash the code to the Peripheral/Slave ESP32. The PlatformIO project is saved in zip format on my Github page (https://github.com/TheESTest/BaseCam-ESP32-Controller):

  • Basecam_ESP32_Control.zip

The Client/Master ESP32 board, which reads the 3 x joysticks and sends their data out over BLE, runs the following Arduino code, which can be opened and flashed using the Arduino IDE. This code is saved as a zip file at the same Github link above:

  • BaseCam_ESP32_BLE_Client.ino

Speed Versus Angle Control Modes

BLE Mode Boolean and Operating Mode String.png
Angle Mode Markup.png
Deadband Markup.png

You can select between Angle vs. Speed control modes for the gimbals. For this project, I selected Angle control mode by specifying it in the BaseCam GUI software (on the RC Settings tab.) This also needs to be set in the PlatformIO project's main.cpp file by setting the String object operating_mode to "angle" (or "speed" if you'd like to use the speed control mode instead.) You can additionally play with the "Control in motor coordinates ("servo mode") setting to affect the motor behavior in response to the joystick inputs, and also set a dead-band limit which will instruct the gimbal motors to not move unless a minimum threshold commanded value is received from the joysticks.

Demonstration

IMG_20240802_175524019.jpg

A video demonstration is shown in the YouTube link below! Come check it out!

Conclusion

In Hand White Background.jpg

This project successfully demonstrated how to send commands from an ESP32-S3 dev board to a BaseCam gimbal controller board in order to control gimbal motors over a CANbus connection. You can alternatively send the signals from one ESP32 to another over Bluetooth Low Energy, to add wireless capability to your BaseCam controller!

Here are some ideas to take this project further:

  • Build a custom full gimbal assembly with three or more axes, and incorporate the electronics mentioned here into that assembly. This could be used for remotely-controlled camera monitoring, cinematography, robotic telemetry, and more.
  • Add a ESP32-based capacitive touch screen module with on-screen buttons and text fields to create, change, save and modify settings and commands sent to the BaseCam control board.
  • Design and 3D-print an enclosure to house the client ESP32 module and user interface devices (joysticks, etc.) to create a portable battery-powered gimbal controller.
  • Design and utilize a custom ESP32-based PCB using KiCAD.
  • Experiment with a variety of input devices such as potentiometer knobs, tactile switches, and other input sensors and switches to expand how the user can interact with the BaseCam board.
  • Create an extendable EMT conduit surveillance pole using a pair of couplings with EMT conduit, and mount a camera gimbal near the top of the pole, and mount the control electronics along the pole.

If you'd like to purchase the single-axis joystick controller used for this project, it can be found at the link below:

Check out our other Instructables articles:

My website's blog posts offer more inspiration for your next project! It offers a free newsletter with project ideas if you'd like to sign up!

My business also offers mechanical and electrical engineering design consulting. I'd be happy to discuss your project's needs to see how we may assist you - simply reach out to schedule a chat.

Thanks for reading!

Austin Allen

Founder and Owner

Elation Sports Technologies LLC