Programming the DJI Tello Drone with Python
The DJI Tello is a compact, affordable, and programmable drone ideal for beginners and educators looking to explore the world of drone technology and coding. Equipped with a camera, it offers a variety of features, including video transmission, precise hovering, and basic tricks. Its compatibility with Python enables developers and enthusiasts to create custom behaviors and flight paths, making it an excellent tool for both learning and experimentation.
In this article, we’ll dive into how you can get started with programming the DJI Tello in Python, explore available simulators to test code safely, and discuss an advanced topic on matrix drone shows using Tello drones.
Equipment and Setup
To program a DJI Tello drone in Python, you’ll need:
- A DJI Tello drone (standard or Tello EDU version)
- Python installed on your computer (version 3.6+ recommended)
- Tello SDK to access Tello’s programmable features
- A compatible device (PC, Mac, or mobile device)
- Wi-Fi connection to connect to the Tello drone
Setting up your programming environment involves installing Python, configuring the SDK, and ensuring your device can communicate with the drone over Wi-Fi.
Programming the Tello in Python
With Python, programming the DJI Tello is straightforward thanks to the Tello SDK, which provides a range of commands for movement, rotations, flips, and even camera control. The SDK is compatible with various Python libraries that allow you to establish a connection, send commands, and receive feedback from the drone.
For a simple example, here’s how you can control your Tello with Python:
import socket
import time
# Tello's IP and Port
TELLO_IP = "192.168.10.1"
TELLO_PORT = 8889
# Connect to Tello
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 9000))
def send_command(command):
sock.sendto(command.encode('utf-8'), (TELLO_IP, TELLO_PORT))
print(f"Sent: {command}")
send_command("command") # Initiate SDK mode
time.sleep(1)
send_command("takeoff") # Take off
time.sleep(5)
send_command("land") # Land
This code initiates SDK mode, takes off, hovers for a few seconds, and then lands.
Drone Simulators for Safe Development
Developing with a real drone has inherent risks, especially in indoor environments. Luckily, simulators allow us to test and iterate on our code safely before using it with an actual Tello.
DroneBlocks Coding Simulator
The DroneBlocks Coding Simulator is an excellent online tool to practice programming a Tello without any hardware. Available at DroneBlocks Coding Simulator, it provides a visual interface where you can test code by simulating movements, rotations, and simple flight paths in a virtual environment. The simulator supports block-based coding, making it especially beginner-friendly for those just getting started with drone programming.
DroneBlocks Tello Simulator
For a Python-based simulation, the DroneBlocks Tello Simulator provides a Tello flight simulator that can be run locally. Installable via PyPI, it allows developers to programmatically control a virtual Tello in Python. This is especially useful for those who wish to work directly with Python scripts and Tello SDK commands in a simulated environment that mimics the behavior of a real Tello.
pip install DroneBlocksTelloSimulator
After installation, you can run Python commands in this environment, providing a safe way to refine your code.
Advanced Topic: Matrix Drone Shows
An exciting application of DJI Tello drones is the creation of matrix drone shows, where multiple drones perform coordinated movements to create intricate patterns and displays. This requires advanced programming techniques, such as automatic path generation, collision avoidance, and synchronization of multiple drones.
A recent study titled “Implementation of Matrix Drone Show Using Automatic Path Generator with DJI Tello Drones” explores an automatic path generator that allows for creating these synchronized drone shows. By calculating optimal paths and timings, developers can ensure each drone follows a specific route, avoiding mid-air collisions while achieving complex formations.
To implement a matrix drone show, you would need to:
- Define the formation pattern and set the starting positions for each drone.
- Generate unique paths for each drone, taking into account speed, distance, and synchronization.
- Use the Tello SDK to send commands to each drone in real time, monitoring progress to maintain the formation.
Here’s an example of how a basic path coordination might look:
# Assume each Tello has a unique IP address and can be controlled individually
drones = [("192.168.10.1", 8889), ("192.168.10.2", 8889), ("192.168.10.3", 8889)]
commands = ["up 50", "forward 100", "cw 90"]
# Send commands to all drones
for drone in drones:
for command in commands:
send_command(drone, command)
This code could be expanded to allow more complex and simultaneous movements. The research presents a robust approach to coordinate multiple drones, paving the way for impressive aerial displays.
Final Considerations
Programming the DJI Tello with Python is a rewarding experience, offering insights into both coding and robotics. Whether you’re learning basic controls or experimenting with coordinated multi-drone shows, the Tello is a flexible platform with ample support for developers of all levels. By leveraging simulators, you can practice and refine your code safely. Advanced applications, like drone shows, showcase the potential of using autonomous drones for synchronized performances and illustrate the future of automated drone displays.
The DJI Tello opens doors to creativity and learning, making it a great tool for anyone interested in exploring robotics, automation, or the art of drone programming.
Next Development: Face recognition with Open CV (AI and machine learning)
This repository demonstrates using OpenCV with the TelloEDU mini drone or a computer’s web camera to perform facial detection and keep track of the number of faces detected at a given time.
This repository showcases how to utilize OpenCV for real-time facial detection using the TelloEDU mini drone’s camera or a computer’s webcam.
- It detects faces in the camera stream and draws rectangles around them, along with counting the number of faces detected.
- The code available on this repository on github Face recognition with Open CV . The repository includes a simple GUI for displaying the video feed and the number of faces detected.
Next Development: Enhancing the Matrix Drone System for Automatic Path Generation (Experimental Paper)
Download Paper: Implementation_of_Matrix_Drone_URI
Use the share button below if you liked it.
It makes me smile, when I see it.