Jul 7, 2020 3 min read

Flying DJI Tello drone using Golang

Flying DJI Tello drone using Golang
Table of Contents

Gobot is a framework for controlling robots, drones, and the Internet of Thing devices using the Golang programming language. In this article, you will build a simple application to controll your DJI Tello drone using your Keyboard in Golang.

Gobot is a framework for controlling robots, drones, and the Internet of Thing devices using the Golang programming language.

In this article, you will build a simple application to control your DJI Tello drone using your Keyboard in Golang.


Before you begin this guide, you'll need the following:

  • You will need a DJI Tello drone to follow along with this article
  • Experience with basic Go syntax - You can read my beginner Golang article to get up to speed. Here is also a link to a book that can help you get started (Disclaimer: Affiliate link)

Information about the drone

The DJI Tello is a great starter drone that is fully programmable and costs about 80-100€.  Here are some pieces of information about the drone:

  • Weight: Approximately 80g
  • Built-In Functions: Range Finder, 5MP Camera with 720P Live View  Vision System, WIFI 802.11n 2.4G,
  • Max Flight Distance: 100m
  • Speed: 8m/s
  • Flight Time: Up to 15min per battery
  • Detachable Battery: 1.1Ah/3.8V
  • Port: Micro USB Charging Port

Setting up the project

The first step is setting up the project file structure, which is pretty easy because it only requires a single file.

touch main.go

After that, you also need to install the necessary dependencies for using the gobot library.


Connecting to the Tello Drone

After completing the project setup, you can continue by connecting to your drone using the following code.

package main

import (


func main() {
	drone := tello.NewDriver("8888")

	work := func() {

		gobot.After(5*time.Second, func() {

	robot := gobot.NewRobot("tello",


As you can see, the tello.NewDriver() function is used to create a new drone driver, which can then be passed to the gobot robot as a device. We also define a function called work where we define the action the drone should perform.

In this example, the drone takes off at the start of the script using the drone.TakeOff() function. The example also makes use of the gobot.After() helper function that allows us to include a time delay for a command.

Adding controls for flying

Now that you are connected to the drone, the next step is to execute the commands when pressing the keyboard instead of using a time delay.

For that, we use the keyboard module of the gobot library. You first need to register a new keyboard driver and add the driver to your gobot devices. After that, you can use the keys.On() function in your work() function.

package main

import (


var (
	intensity int = 20

func main() {
	keys := keyboard.NewDriver()
	drone := tello.NewDriver("8888")

	work := func() {
		keys.On(keyboard.Key, handleKeyboardInput(drone))

	robot := gobot.NewRobot("tello",
		[]gobot.Device{keys, drone},



The keys.On() function takes two arguments:

  1. The key that it should react to
  2. The function that should handle the keyboard event

Let's continue by implementing the function to handle the keyboard input.

func handleKeyboardInput(drone *tello.Driver) func(interface{}) {
	return func(data interface{}) {
		key := data.(keyboard.KeyEvent).Key

		switch key {
		case keyboard.A:
			fmt.Println("Going left.")
		case keyboard.D:
			fmt.Println("Going right.")
		case keyboard.W:
			fmt.Println("Going up.")
		case keyboard.S:
			fmt.Println("Going down.")
		case keyboard.U:
			fmt.Println("Going forward.")
		case keyboard.J:
			fmt.Println("Going backward.")
		case keyboard.K:
			fmt.Println("Rotating counter-clockwise.")
		case keyboard.H:
			fmt.Println("Rotating clockwise.")
		case keyboard.L:
			fmt.Println("Landing drone")
		case keyboard.T:
			fmt.Println("Take off drone")

As you can see, we extract the key from the event and react to it by executing the right drone action.

If the key is none of our defined options we reset the drone position instead.

func resetDronePostion(drone *tello.Driver) {

Testing the application

Excellent, now that we have finished the application, you can run it using the following command.

go run main.go

You should now be connected to the drone and be able to take off and fly using the keys you defined earlier.


You made it all the way until the end! I hope that this article helped you understand Gobot and how you can use it to control your DJI Tello drone.

If you have found this useful, please consider recommending and sharing it with other fellow developers and subscribing to my newsletter. If you have any questions or feedback, let me know using my contact form or contact me on twitter.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Gabriel Tanner.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.