Programming the DJI Ryze Tello drone with Python

Fleet Flyer

© Lead Image © Leonid Eremeychuk, 123RF.com

© Lead Image © Leonid Eremeychuk, 123RF.com

Article from Issue 277/2023
Author(s):

Drones are more fun if you can program the unmanned aerial vehicle yourself. The DJI Ryze Tello and Python make this possible.

In this article, I work with the DJI Ryze Tello drone, which is available on Amazon [1] and from other vendors for around $99 (£99/EUR100). Why this model? The drone was designed for educational use and has open interfaces for that purpose. In other words, you can develop programs for the drone in Scratch or Python.

To familiarize yourself with the drone's capabilities, you first need to download the app that gives you manual control of the drone. The drone's battery lasts about 13 minutes, and the control range is about 100 meters. Because it is intended for operation inside buildings, this range is fine. If you get lost, the built-in 720p camera with electronic image stabilizer lets you view your current location.

For more intensive use, a Tello with the indispensable boost combo add-on adds $49 (£39/EUR45) to the price. Among other things, you get two extra batteries and a propeller protection set. During your first programming attempts, the propeller guards will definitely help prevent serious damage (Figure 1). Further information about the DJI Ryze Tello can be found on the manufacturer's website [2]; the essential technical data is shown in Table 1.

Figure 1: The DJI Ryze Tello with the highly recommended propeller guards from the accessories range. Source: DJI

Table 1

DJI Ryze Tello Overview

Feature

Spec

Dimensions

98.0x92.5x41.0mm

Weight

80g, including propeller and battery

Battery

1.1Ah/3.8V (removable)

Connector

Micro-USB port for charging

Other

Rangefinder, barometer, LED, vision system, WiFi 802.11n, 720p live streaming

Performance

Max. flight range

100m

Max. flight altitude

30m

Max. speed

8m/s (18mph)

Max. flight time

13 min

Camera

Field of view (FOV)

82.6 degrees

Photography

5Mpx (JPG, 2592x1936px)

Video

HD720p30 (MP4)

Software Installation

To download the app for the drone, search for Tello in the Google or Apple app store. The app also lets you update the drone's firmware. Instructions on how to do this can be found in the "Updating the Firmware" box.

Updating the Firmware

You never know exactly how long the drone has been sitting around in a warehouse, so before doing anything else, it's a good idea to update the device's firmware from the app on your smartphone. To begin, connect to the drone and then switch to the app's settings with the gear icon. When you get there, tap More, then the three dots (Figure 2), and Update in the Firmware Version line. You will then see the release notes and can start the update process by tapping Update.

Figure 2: Update the drone's firmware with the Tello app.

To connect to the drone in the app, first turn on the drone and wait until the LED flashes, which indicates it is starting a separate WiFi network to which you need to connect. Now launch the Tello app and connect to the drone. The app tells you the steps required. If everything worked, you will see the camera image in the app. The drone can now be launched with the lift-off icon at top left.

You can control four degrees of freedom in the app: forward and backward, left and right, up and down, and rotation about the z axis in both directions. You will encounter these four degrees of freedom again when creating programs. To make sure everything is working properly, go on a small test flight before you try controlling the drone with Python.

Before you start programming, you might want to install a suitable integrated development environment (IDE). PyCharm Community by JetBrains is a good choice for this project. You will find versions for different operating systems on the project website [3]. The installation completes the preparations, and you can now proceed to write your first program for the drone.

Connection Test

To create a program with PyCharm, select File | New Project. Leave all the default settings as is except for Location: Enter a meaningful project name in this field as the last component of the path. After pressing Create, the IDE directly creates a main.py file, where you will save your own program after deleting the sample code in the file.

To use your scripts, you need to include a drone control library [4] in your projects by selecting File | Settings | Project:<name> | Python Interpreter and pressing the plus icon to install the djitellopy library (Figure 3).

Figure 3: The djitellopy library in PyCharm allows you to control the drone.

The program in Listing 1 connects to the drone and displays the temperature and battery level. These two readings are very important for drone operations. If the charge level is too low, you do not want to fly. If the electronics or the battery are overheating, it's time for a short break. To start the program, just click the green arrow at the top of the IDE. Listing 2 shows the program output.

Listing 1

Opening a Connection

 

Listing 2

Connection Output

 

Depending on your computer's feature set, if nothing is working you might only see an error message. The program must connect to the drone's WiFi to achieve control. Most desktop PCs do not have a WiFi interface. A simple and inexpensive solution to this problem is a USB WiFi adapter. I had one [5] in my tinkering box that worked perfectly with Ubuntu.

Ready to Start

You now know how to connect the computer to the drone and query simple status information, so it's time for a small test flight. With the program in Listing 3, launch the drone, let it fly forward a few centimeters, and then land. Controlling the drone always follows the same pattern. You create an object for the drone and call its methods to perform the specific actions.

Listing 3

Flying the Drone

 

To discover what actions the object supports, mouse over a method and press Ctrl+Left mouse button to access the library's source code, where you can snoop around a bit. Alternatively, type drone. and scroll through the menu (Figure 4). I did look for better documentation for the library, but my search turned up nothing.

Figure 4: All available method calls for the DJI Ryze Tello.

I need to talk about one more special method for the drone object: send_rc_control specifies motion speeds for the drone's individual degrees of freedom. The permissible values range from -100 to 100. The method supports four parameters:

  • Speed left or right
  • Speed forward or back
  • Speed up or down
  • Rotational speed clockwise or counterclockwise

This method is a simple way to control the drone remotely.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • FOSSPicks

    After building a 3D printer last month, Graham's home is now filled with cup holders, phone holders, cable holders, and tiny PLA boats. This month, Graham explores Zrythm, Mumble 1.3, NoteKit, Kirogi, monolith, pastel, Nu Shell, PacVim, Stunt Car Racer Remake, and more!

  • Matt Trifiro on the Edge

    We talk with Matt Trifiro, one of the publishers of the State of the Edge report, on the nature of Edge computing and how it is changing IT.

  • Linux News

    Updates on Technologies, Trends, and Tools

  • Drone Brain Goes Open Source

    DARPA and NICTA release the code for the ultra-secure microkernel system used in aerial drones.

  • FOSSPicks

    This month Graham looks at Gyroflow, gRainbow, Polyrhythmix, mfp, Mission Center, and more!

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News