Teach your PC to fly a Mini-Drone!

A few months ago, I watched this TED talk where they setup an indoor arena and did some amazing things with drones.  It got me thinking, and it inspired me to build something like that for myself – but on a much smaller and cheaper scale.

In the video they use an expensive real-time infrared motion tracking system (I am guessing something like these Optitrack systems) to measure the position of the drones, and then uses a computer to calculate and send control signals to coordinate the drones. At a high level, my setup works in a similar way, as shown in this diagram:

Here’s a photo of what my setup looks like:

drone setup
Photo of the first working setup.

This is a list of the items needed to build this:

Component Description
USB Camera ELP 2megapixel Hd Free Driver USB Camera Support Mjpeg Linux Android Windows Developing Board,usb Camera Module
Arduino Microcontroller Board Arduino UNO R3 Board Module With DIP ATmega328P(Blue)
Nordic Semiconductor 2.4GHz Wireless Card Addicore nRF24L01+ Wireless AddiKit with Socket Adapter Boards and Jumper Wires
Cheerson CX-10 Mini-Drone Cheerson CX-10 Mini 29mm Diameter 4CH 2.4GHz 6 Axis Gyro RC Quadcopter UFO RTF Green
2 blade guards for the Cheerson CX-10 Upgrade Cheerson Cx-10 Propeller Prop Blade Guard Cover Bumper Protection Protector Green White

Total cost for these items was around $85. In addition to the above, you might also need a folding table and stack of books to hold up the webcam as I did, but you can probably think up something more refined!
Here is a video of it working:

Here are some links to further information on how this all works:

  1. Setting up the programming environment on your PC
  2. Detecting the circles from the webcam
  3. Finding a low-latency web camera

Source code:

  1. nrf24_cx10_pc  – The source code for the Arduino to send 2.4GHz wireless signals to the drone
  2. pc-drone – The Python / OpenCV code used to track the drone and decide on how to adjust the drone controls

We will also be sharing this project at the Bay Area Maker Faire from May 20-22, so please stop by the MakeHardware.com booth and check it out!

39 thoughts on “Teach your PC to fly a Mini-Drone!”

  1. Hi! I’ve replicated your setup (Cheerson x-10, Arduino Uno, NRF24L01, etc.). I had to make a few tweaks to the python code, but essentially, everything is in place. However, when I turn on the quadcopter and fire up serial_test.py, I see the [PC] commands, but the quadcopter does not respond. I tried setting the current_protocol=PROTO_CX10_GREEN in nRF24_multipro.ino, and then I get a follow-up [AU] comment in my terminal following each [PC] command. However, the quadcopter doesn’t respond to that either.

    Is there something I’m supposed to do before running the python code? To use the controller that came with the quadcopter, I’m required to move the left stick up and then down to activate it. I’ve tried doing that before the python code, but there is still no response.

    1. Hi Jeff,

      Since you are seeing the [AU] acknowledgements from the Arduino Uno, that means the Arduino is sending the radio signals through the nrf24. However, there is no way for the Arduino to know that the radio signal is being received by the CX-10. Most likely your quadcopter needs to “bind” to the Arduino/nrf24 board. I believe that the CX-10 needs to be in binding mode, and then the Arduino/nrf24 radio should be started after that.

  2. Thanks for the post. Very interesting indeed.
    When I tried to repeat it, I found that the white wire on a photo isn’t connected to Arduino.
    Any comments?

  3. I am looking for a sensor driven drone to fly autonomously in a warehouse at night and take pictures/video of a pre-programmed area when the sensor calls for the drone. We are looking at using dragonfly and DGI drones but open to other ideas. Please contact me if your interested in this project: [email protected]

  4. hi every body..thanks for this brilliant post..
    i want to implement this project but i have already cx-10-wd-tx… does it work or i have to buy a cx-10?

  5. Hi

    I have a problem on connection between Arduino and CX-10 drone (I actually used orange).
    When I went through the NRF code for initialization and bind in scratch, I found the protocol was not written. So I ordered a blue and green drone to test this project.
    Would you tell me how I can connect my orange CX-10 to Arduino board? Every time I tried to connect, I only saw the blinking light on the board.

  6. Hi there. First of all, I have to say that this is an awesome project.
    I tried to test it out using JJRC H36 drone. But I have problems binding to it.
    I used the original code from https://github.com/goebish/nrf24_multipro to supplement missing protocol for JJRC H36. Any suggestions on where to look on how to fix this problem?

    Best regards Marko.

  7. Hi all,
    I know it’s an old project but i’ve made to make it all work (more or less).
    I’d like to have a quick chat on some pars that I’d tweak to improve stability and performance of the drone trajectory.
    Is there someone that I can ask to?

    Thanks,
    Christian

  8. It seems like they’ve changed the board on the CX-10, any advice on how you figured out the control protocol code to see if I’d be able to modify it?

  9. Hi, is this compatible with Cheerson CX-10WD or CX-10W ?
    What I want to do is use the PC to:

    1-capture the video streaming via wifi and use it with OpenCV, hoping that this code https://github.com/Otacon/wifi_china_drone_controller will give me a jumpstart on capturing the vídeo;
    and
    2- control the copter using the method you presented.

    Basically i would use OpenCV on the PC to fly the copter but using the onboard camera of the Cheerson CX-10WD.

    1. I don’t think it’s compatible with the CX-10W(d). The controller board is completely different from the CX-10. The chip on the board has no markings on it. There are no solderpoint to connect wires for CS en other controls.
      When I start the Arduino with the drone there is a very short hamper in the blinking of the LEDs so there is something going on but the sync doesn’t complete. So no connection.

      I will order a CX-10 and see if that does work.

  10. I have question about possibility use this idea for another kind drones. It is working only for Cheerson CX-10 Mini-Drone or another? For what should I pay attention if want use something bigger?

  11. Hi,
    I have the hardware and code up and running on the Ardunio with a CX-10c but the code is not getting past the init stage, i.e. the bind step isn’t working.
    I haven’t had a chance to go debug where in the bind function it is not working but I expect, as this is working for other, it is more likely a hardware or config issue.

    Any clues form those who have had similar issues, or other ways to help debug the issue would be appreciated.

    rgs Steve

    1. Hi Steve,

      It’s hard to tell what might be going wrong here. I assume you’re running the serial_test.py script to test out the Arduino and radio setup? Are you seeing the serial port responses back from the Arduino?

      1. mhadmin,
        At this stage I am only using the arduino code to get the copter to Bind.

        So I am running the multipro.ino and it is selecting the right protocol, then within CX10_GreenBlue.ino, it runs the ‘Init’ function ok, but loops in the ‘Bind’ process, presumably because it is not receiving the response signal.
        if(NRF24L01_ReadReg(NRF24L01_07_STATUS) & _BV(NRF24L01_07_RX_DR)) { // data received from aircraft
        but I haven’t debugged in and around that yet to see what could be wrong.
        Any suggestions?
        tks

  12. Have you heard if anyone has tried this with a raspberry pi zero w? I would like to try, but am a bit new to this whole thing. The RPI zero w has wireless already, and a sweet camera module, and all that is less than $40.

  13. Hi mhadmin again,

    Sorry for keeping on bugging. I am trying to figure out how you used the python test script to work (serial_test.py) with the already present Arduino code to command/test the drone. Can you please push me in the right direction?

    Thank you for your help!

    1. Ha! I got it to work. If anybody else is having trouble. Upload the Arduino code first (do not open the serial monitor), execute the python script (assuming you have python installed and the necessary modules), turn on the CX-10, wait for it to connect, then control it via your keyboard.

      Excellent work mhadmin and thank you for your project! My next step is incorporating the camera.

  14. Hi, thanks for the post here, helping me to ultimately get a project up and running with a Syma X5C-1 which isn’t working yet. I plan to test with a CX-10 and then convert later.
    To get just the base CX-10 running though, could you explain which of the .ino files you load up in the Arduino ide, to enable just the connection phase.
    Do I need to run the test.py file you mention in the python environment to get some response or will running the arduino files alone give me enough to show that at least I have a connection to the CX-10.
    Some help here would be appreciated to put me down the right path before I look into it in real detail.

    1. The file to load onto your Arduino is:
      https://github.com/perrytsao/nrf24_cx10_pc/blob/master/nRF24_multipro/nRF24_multipro.ino

      That .ino file will already bind to the CX-10 after it reboots and you first turn on the CX-10. You can tell it is bound because the LED on the Arduino will go from blinking to solid.

      The serial_test.py file is only necessary if you want to send commands to the CX-10 in order to see if you have a response. It is not needed for just binding.

      1. Tks, I’ll try that out.
        Once I have the Syma up and running I will be trying to do something slightly different to yourself, get it tracking a moving object, but the work you did on the rest of the project could well help.
        rgs

      2. Hi mhadmin,

        Awesome work on the project and I am very excited to get this up and running on my own.

        I am also trying to get the CX-10 code up and running using nRF24_multipro.ino and I need a little push in the right direction. When I compile the .ino file I am getting a bunch of errors about functions that don’t exist in the current code. Just to verify with you – do I need to comment all the code that does not belong to the CX-10 such as process_CG023, process_V2x2, etc? I also verified that I do have in fact have all the libraries needed. Here is a list of all compile errors:

        Arduino: 1.7.11 (Windows 8.1), Board: “Arduino Uno”
        Drone_Test.ino: In function ‘void loop()’:
        Drone_Test.ino:201:24: error: ‘NRF24L01_Reset’ was not declared in this scope
        Drone_Test.ino:203:29: error: ‘NRF24L01_Initialize’ was not declared in this scope
        Drone_Test.ino:213:37: error: ‘process_CG023’ was not declared in this scope
        Drone_Test.ino:216:36: error: ‘process_V2x2’ was not declared in this scope
        Drone_Test.ino:220:36: error: ‘process_CX10’ was not declared in this scope
        Drone_Test.ino:223:34: error: ‘process_H7’ was not declared in this scope
        Drone_Test.ino:226:38: error: ‘process_Bayang’ was not declared in this scope
        Drone_Test.ino:229:37: error: ‘process_SymaX’ was not declared in this scope
        Drone_Test.ino:232:37: error: ‘process_H8_3D’ was not declared in this scope
        Drone_Test.ino: In function ‘void init_protocol()’:
        Drone_Test.ino:391:24: error: ‘CG023_init’ was not declared in this scope
        Drone_Test.ino:392:24: error: ‘CG023_bind’ was not declared in this scope
        Drone_Test.ino:395:23: error: ‘V2x2_init’ was not declared in this scope
        Drone_Test.ino:396:23: error: ‘V2x2_bind’ was not declared in this scope
        Drone_Test.ino:400:23: error: ‘CX10_init’ was not declared in this scope
        Drone_Test.ino:401:23: error: ‘CX10_bind’ was not declared in this scope
        Drone_Test.ino:405:21: error: ‘H7_init’ was not declared in this scope
        Drone_Test.ino:406:21: error: ‘H7_bind’ was not declared in this scope
        Drone_Test.ino:409:25: error: ‘Bayang_init’ was not declared in this scope
        Drone_Test.ino:410:25: error: ‘Bayang_bind’ was not declared in this scope
        Drone_Test.ino:413:24: error: ‘Symax_init’ was not declared in this scope
        Drone_Test.ino:414:24: error: ‘SymaX_bind’ was not declared in this scope
        Drone_Test.ino:417:24: error: ‘H8_3D_init’ was not declared in this scope
        Drone_Test.ino:418:24: error: ‘H8_3D_bind’ was not declared in this scope

        Error compiling.
        This report would have more information with
        “Show verbose output during compilation”

  15. Yes, you can control the drone just by sending serial commands to the Arduino. The commands can be generated by Python as they are here or any other language. You will still need to use the Arduino firmware in this repository https://github.com/perrytsao/nrf24_cx10_pc or something equivalent so that the Arduino can properly interpret the serial commands and send the radio signals to the CX-10.

  16. Hi, is it possible to command the drone via serial monitor instead of using blob detection?
    Basically, can we do basic controls with it using just an arduino without python?

  17. Will the nRF24L01+ wireless transmitter work with the onboard Cheerson CX-10 rx? If not is there a tx card compatible with the current rx if soldering is not a strong point :)?

    As well, is there any way to relay images from the drone to the arduino for cv processing from the drones camera, can the images/ videos be streamed or processed on the PC?

    1. Yes, the nRF24L01+ does work with the onboard Cheerson CX-10 RX. This entire project was done without soldering! The only wiring needed is the jumpers from the Arduino Uno to the nRF24L01+ card which is described on the Github page https://github.com/perrytsao/nrf24_cx10_pc

      The Cheerson CX-10 doesn’t have a camera on it so there is no way to stream images. There are many other drones that do such as the CX-10W or the Hubsan H107D or Estes Proto-X. They use different transmitter/receivers though, so it would require some different hardware.

  18. Thanks for this project. I managed to implement the entire project. The only difficulty is the blobs detection. I don’t have a perfect brightness. Do you have a tip for an optimal detection ?
    I will soon post an article on my blog to show a demo. Thanks again 😉

    1. That’s awesome that you got it to work! Can’t wait to see your post about it!

      In order to help calibrate the lighting, I would take a couple of snap shots under your specific lighting conditions. You can do this by running the fly_drone.py script, and pressing the space bar, and it will save some of the images to the drive. THen I would try using the pc-drone/detectDrone/detectDrone.py script to loop through the images and see in which snapshots the blobs were detected. You can tweak the parameters in the detectDrone.py script, and then make the corresponding changes in the fly_drone.py code.

Leave a Reply to Steve Sheffield Cancel reply

Your email address will not be published. Required fields are marked *