Controlling a drone from a PC with an Arduino

Controlling a drone from a PC with an Arduino

Comments 23

Beware This post is more than 3 years old, it may be outdated or incorrect! Please check elsewhere for accurate information!

Introduction

As some of you may know, I’m a huge drone fan [pun intended], and as such I’m always experimenting with these wonderful flying machines and finding new uses for them, as well as new ways to have fun with them.

I have always wanted to control a drone with a PC, and later have a camera feed from the drone to the computer, to be able to do some kind of pattern matching and follow objects, without a huge budget and large and dangerous drones.

In this post I will show you how to control the world’s cheapest (but not the smallest) drone, the Eachine H8 Mini, using an Arduino Nano (any Arduino will do), the nRF24L01+ 2.4G Wireless communications chip, and a PC running Windows with Python installed.

Here’s what you will need, and the approximate costs:

Prices subject to change without notice, links include refferal codes, supplier Banggood

  • Eachine H8 Mini - $12.99 - Banggood, 1 piece, RTF
  • nRF24l01+ Chip - $3.45 - Banggood - COUPON 10% off: 637ccc, 3 pieces
  • “Arduino” Nano - $2.39 - Banggood - 1 piece, Geekcreit brand
  • mini USB cable - approximately $1, buy it in a local shop - 1 piece
  • DuPont female-female cable - $1.49 - Banggood - COUPON 10% off: 15ACC, 40 pieces

You will need to solder the pins to the Arduino Nano clone, and maybe the nRF24L01+ clone, so you will need a soldering iron and some solder.

I linked clones from Banggood, as those were the ones I bought, but as far as I know they are fully compatible, and there are no datasheets for them implying they are compatible with the original components.

Reference guide for Nordic Semiconductors nRF24L01+ (and Semitek SI24R1) pinout

Meaning Pin Pin Meaning
GND 1 2 VCC
CE 3 4 CSN
SCK 5 6 MOSI
MISO 7 8 IRQ

Reference guide for connecting 2.4G wireless module to Arduino Nano

Meaning Arduino PIN nRF24l01+ PIN Notes
0V GND GND Ground
3.3V 3V3 VCC _Please_, Do not connect VCC to 5V, it will burn out the nRF24l01+ chip!
SPI CE D5 CE Special pin for nRF24l01+, control standby and RX/TX
SPI CSN A1 CSN SPI standard pin
SPI CSK D4 SCK SPI standard pin
SPI MO D3 MOSI SPI standard pin
SPI MI A0 MISO SPI standard pin

IRQ is intentionally left unconnected (floating). The Pinout is silk-screened (written) onto the board itself.

Step 1: Download Arduino IDE

To program the Arduino Nano, even though it’s a clone, you will need the official Arduino IDE. I used the version 1.8.4 on Windows 10.

Use the Windows installer (.exe) file, don’t use the online app or the Windows Store application, they will not work.

Download

Step 2: Install the Arduino IDE

Please refer to the video here for instructions, as I cannot go into details about the installation process, that is not the topic of this post.

Step 3: Connect the Arduino and nRF24l01+

Use the reference table above to know which is which.

Step 4: Plug in Arduino

Plug in the Arduino into the USB 2.0 port on your computer, preferably a back-panel one.

Step 5: Upload program code to the Arduino

Download my ZIP file and extract it to the Desktop. Enter the directory nRF24_multipro and double click nRF24_multipro.ino (you may not see .ino depending on your OS setup).

In the Arduino window, select Tools -> Board -> Arduino Nano, select the COM port (best to unplug your printer if you have one plugged in).

2017-09-24_174047.jpg

Then, go to Sketch and Upload.

Step 6: Test out your setup

Plug in the drone’s battery into the micro LOSI connector, make sure to get the polarity right, and set it on a flat level surface quickly.

Unplug and plug back in (or press the RESET button) the Arduino, and see if the LEDs on the drone start flashing quickly then stop flashing and stay lit.

If that happens, it means everything works. If not, unplug everything and retry.

Step 7: Control the drone

Install Python 2.7.x from here (I used 2.7.14).

Press Windows key on your keyboard and button R at the same time, and type in “cmd” without quotes. Then run “cd C:\path\to\downloaded\files” (put in the correct path, make sure there are no spaces in the path, if there are move the folder!) and finally run “python serial_test.py”.

You should see a screen similar to this one:

2017-09-24_164808.jpg

Controls are as follows:

  • W to increase throttle, S to decrease
  • A to yaw left, D to yaw right
  • Arrow keys to move foward/backward and left/right

Pretty cool! If you have any issues, let me know in the comments below and I will try and help you.

Disclaimer: This code is based on work by goebish and perrytsao. I am not responsible for any damage, injury, or death resulting from your use of this code.

Edit: Seems like I’ve forgotten to include the download link for the firmware, so here it is:

Download

0
❤️
0
👍
0
😲
0
😢
0
😠
0

Comments (23)

Please be civil when commenting. Think before writing, don't spam, self promote, bully, harass or harm anyone. Please read the Comment Policy before posting. Comments are moderated.
See all 23 comments

Alex

Alex

I got a question. Is Eachine H8 Mini the same as Eachine H8 Mini 3D?

I am having problems starting Eachine H8 Mini (no 3D).

Reply · 1 month ago · #834

Milan Kragujević

...replying to Alex

Milan Kragujević Admin

Hi Alex,

It is not the same, and uses different protocol.

Also, since this post was written in 2017, the H8 mini you buy now will surely be completely different from the ones I had, as the pricing had to be optimized so the manufacturer changed the board layout multiple times to keep up with chip supplier changes.

In that case, it is unlikely that it will be supported, but you can ask on RCGroups forum for details, or check about firmware support of Deviation for Walkera Devo TX, and port the changes yourself.

Sorry I cannot be of more help.

Thanks for reading and best regards,

Milan

Reply · 1 month ago · #835

Alex

...replying to Milan Kragujević

Alex

Actually, I have figured it out. My mistake. It works with Bayang protocol. At least I could connect and take off.

Thank you.

Reply · 1 month ago · #842

Kyle

Kyle

Due to the issues with the Uno I mentioned in the other thread, I tried porting the code to a Teensy 4.1. The clock speeds are different so the soft spi calls will all mess up. RF24 calls all still work though.

I modified my RF24 source file to change some of the protected methods to public so I could substitute them for the included calls that are implemented with softspi. They pretty much map 1:1 so I attempted to substitute.

I can tell that read_register and write_register both work when substituted. Yes!

However, I don't have any diagnostics to tell if the modified WritePayLoad and ReadPayload calls are working without seeing the drone bind.

Can you give me any intermediary diagnostics?

Reply · 9 months ago · #522

Kyle

Kyle

I'm running on an Uno and have been having no luck getting this code to run. I added some delays around the initial radio config, and it it seems to show that radio.printdetails() is hanging. If I remove the call, the code runs further…but doesn't bind. If I ever call radio.printdetails, the code crashes.

I don't think the radio is actually being spoken to, and if printdetails doesn't run I have no way to check. Ever heard of this problem?

Is there an alternate way to read the radio config?

I'm not planning on using the python scripts. Are these required in any way to ‘arm’ the drone? I had planned to simply provide the value strings directly from the arduino. Will this work?

Reply · 10 months ago · #520

Federico Corradi

Federico Corradi

Hi, thank you for the hack. I have been able to program the arduino, connect to the drone and run the python scripts, after few trials of connect disconnect I have been able to communicate to the drone.. see the log below.

However, the drone doesn't move. It looks like it is still disarmed. Have you ever experience something similar?

0faa3899-c04d-4f91-9169-f9264a200a40.png

Reply · 1 year ago · #234

Milan Kragujevic

...replying to Federico Corradi

Milan Kragujevic Admin

Hello,

what model of the drone do you have? Can you take a picture of the circuit board markings and send it to me?

It's quite possible you have an incomatible version of the drone, which is why it is not responding.

Also, if the lights aren't lit fully, but are blinking instead, the pairing wasn't done properly and the drone isn't armed. If it was paired but not armed, try moving the throttle in the CMD window to maximum then back down to zero, then try again.

Regards,
Milan

Reply · 1 year ago · #239

Federico Corradi

...replying to Milan Kragujevic

Federico Corradi

Hi Milan, thank you for your reply. Yes, the lights aren't lit fully and the pairing isn't done correctly. I have H8 mini 4ch 6-axis gyro. I have checked the wiring couple of times, and it seems fine to me..

drone: https://www.banggood.com/Ea...

nrf24L: https://www.banggood.com/11...

Could it be a power issue? I see that the NRF24L01PALNAhas a 115mW transmit power, while the arduino code sets the RF_POWER TX_POWER_80mW ...

thank you again for your help!

Reply · 1 year ago · #241

Milan Kragujevic

...replying to Federico Corradi

Milan Kragujevic Admin

Hi Federico,

I don't think it's a power problem, 115 mW is WAY too much for this kind of data rate and modulation, and the distances it will be used. 80 mW is enough and stays within most legal limits in most countries.

You most certainly have a different revision of the same model. My board is green and has this written: "WJ-KZX3R-4D ZM-2015.01.03". If your is different, it uses a different protocol, which I may have archived somewhere since I had quite a few quadcopters, and have the protocol specification for another revision, which is blue, has a table and "KZX3R-4D-1 XX3" in one row and "KZX3R-4D-2 XX8" in the second row, no mentions of WJ, there is also "ZM-2015.12.15".

Green board uses H8 mini firmware and protocol as is in this project, and has a GD32F130G4 Cortex-M3 microcontroller.
Blue board uses CG023 firmware and protocol, which is not currently supported in this code, and has a cheaper STM32F031K4 Cortex-M0 microcontroller.

Let me know what kind of board you have, and take detailed and high resolution pictures please.

Thanks,
Milan

Reply · 1 year ago · #242

Federico Corradi

...replying to Milan Kragujevic

Federico Corradi

2017.11.29 with the code "KZXX3RX(QYJ)" , it has a panchip PAN163CX 2 4GHz wireless transceiver microcontroller

Reply · 1 year ago · #244

Milan Kragujevic

...replying to Federico Corradi

Milan Kragujevic Admin

I will let you know more info tomorrow. Thanks for the revision number. Regards, Milan.

Reply · 1 year ago · #245

Federico Corradi

...replying to Milan Kragujevic

Federico Corradi

Thank you Milan!

1 year ago · #246

Federico Corradi

...replying to Milan Kragujevic

Federico Corradi

Hi Milan,

I have opened the quad-copter mini h8. it contains a blue board 2017.11.29 with the code "KZXX3RX(QYJ)"

Reply · 1 year ago · #243

Merced Gonzales

Merced Gonzales

i have arduino 1.8.9, but when i run the python script it says this: name 'arduino' is not defined. what do i do about that.

Reply · 1 year ago · #184

Milan Kragujevic

...replying to Merced Gonzales

Milan Kragujevic Admin

Add arduino's bin directory to your PATH.

Reply · 1 year ago · #187

Merced Gonzales

...replying to Milan Kragujevic

Merced Gonzales

Do you mean putting the Arduino's bin folder into where ever I download your files (meaning this project)

Reply · 1 year ago · #190

Milan Kragujevic

...replying to Merced Gonzales

Milan Kragujevic Admin

No! Absolutely not. You could have researched this yourself, but since you didn't -- here are instructions for 3 most popular OS platforms (Windows, macOS, Linux) - https://gist.github.com/nex...

Reply · 1 year ago · #191

Merced Gonzales

Merced Gonzales

will this work with a cx-10 mini drone.

Reply · 1 year ago · #183

Milan Kragujevic

...replying to Merced Gonzales

Milan Kragujevic Admin

No, not without changes.

Reply · 1 year ago · #186

Merced Gonzales

...replying to Milan Kragujevic

Merced Gonzales

What changes would I need to make?

Reply · 1 year ago · #189

Milan Kragujevic

...replying to Merced Gonzales

Milan Kragujevic Admin

I don't know, a lot of them, I don't have a CX-10, especially not the revision you have (each model has a lot of revisions that are incompatible with eachother, and it's often impossible to know which one you have). I would need a RF spectrum analyzer and a tool to log all protocol data, which would actually take weeks. I have a job now, and genuinely don't have time for such things, so even if you did ship me the exact drone you have, I couldn't help you. Sorry.

It's much cheaper and simpler to order a H8 mini from Banggood... https://goo.gl/DwwX9u it's $12 with free shipping worldwide (Ref. link)

Reply · 1 year ago · #192

Werner

Werner

Works like a charm, but you need Arduino Studio 1.8.4 otherwise it will fail with the error Chetan Kumar pointed out. Thank you so! :)

Reply · 2 years ago · #100

Chetan Kumar

Chetan Kumar

Hi, I'm getting an error while compiling the INO.

RF24L01:102:32: error: use of enum 'TXRX_State' without previous declaration
void NRF24L01_SetTxRxMode(enum TXRX_State mode)

I checked the file, but I didn't find the enum declaration. Is there a missing file?

Reply · 2 years ago · #75


Scroll to top