Introduction: The Pi Quadcopter

Ever since hobbyist multi/quadcopters have become easily available, I have wanted to fly one. However, I did not want to simply buy an off-the-shelf model with a plug-n-play experience. I wanted to built a quadcopter myself. I wanted to own it. I imagine that is why you are here too. Buying a quadcopter is simply too easy.

Over my winter break I finally had the time to start planning and building a quadcopter of my own. I will walk you through my experience of making it, a quadcopter controlled over Wi-Fi by a Raspberry Pi B+ (instead of a traditional radio controller/ transmitter ), with a MultiWii flight controller.

Requirements:

  • Around $200 total. Depends on what you already have
  • An Android phone (No Apple support yet)
  • Time! Planning/ ordering/ build/ testing all takes a lot more time then you think

I would like to thank reglisse44 for his tutorial that inspired this one.

Step 1: The Raspberry Pi's Role

A high-level explanation of how the Pi is being used:

I had a Raspberry Pi on hand, so I decided to use it in place of a traditional radio controller. This setup accomplishes the same thing as a traditional radio transmitter/ receiver would. If I give an input to increase the throttle, then the Raspberry Pi reads that, and tells the flight controller the same thing that the traditional radio receiver would.

Just to clarify, the Pi is not the flight controller. The Pi acts as the radio transmitter/ receiver would - transmitting flight instructions to the flight controller.

Here's what happens when everything is powered: The Raspberry Pi turns on, creates an open Wi-Fi network, and connects to the MultiWii Flight Controller. A companion app on your Android phone (no iPhone support currently exists), connects to the network created by the Pi, and is able to control the quadcopter through the same controller layout on a regular radio controller.

Step 2: Some Basic Information and Definitions

When I started to build, I had no idea how anything was supposed to work or what the terms being tossed around meant. So I'll describe some basics along with definitions and links.

  • Flight Controller: This is a small board whose function is to direct the RPM of each motor. It is too complicated to control each motor of a multicopter individually. So, a flight controller responds accordingly to (roll, pitch, yaw, throttle) input from the pilot, calculating how to direct the motors. It contains at least an accelerometer and a gyroscope, and potentially a barometer and even GPS. The flight controller is capable of self-leveling, and has different modes of flight if desired.
    • MultiWii: The specific brand of flight controller being used. The original model was based on the accelerometer and gyroscope found in a Wii Motion Plus, hence the name. More info about MultiWii.
  • RC / Radio Control: The system used by the pilot to control the throttle, roll, pitch, and yaw of the quadcopter. A radio receiver is usually connected to the flight controller through pinouts on the flight controller board. In this instance, a mobile app is is connected over Wi-Fi to the Raspberry Pi to instruct the flight controller, which is connected over a FTDI (Mini USB -> pinout) serial connection.
  • Motors and Props: Depending on the type of quadcopter you are aiming for - Faster/Maneuverable (smaller) or Stable/Sturdy (larger) - the type of motors/props that you need will vary dramatically. Motors have a Kv rating, which determines their RPM with zero load at 1 volt. The general rule is for racing copters, a higher Kv rating and shorter props, while for a more stable copter a lower Kv with longer props is recommended.
    • CW and CCW: Due to the physics involved, two props spin clock-wise and two spin counter-clock-wise. Check out Step 6 for a good graphic.
    • "Brushless" DC motor: These are the most common type of motors used in RC applications. As compared to "Brushed" DC motors, they do not wear out as fast. However, they do need ESCs (as described below) in order to operate them since they are much more complicated to control
  • Power: The power system starts with a battery, which is connected to an appropriate power distribution board, splitting the voltage in parallel. From there, the power flows to the ESCs and then to the motors.
    • ESCs: A Electronic Speed Controller converts a digital signal into analog for a motor. It connects to the flight controller via pinouts, which is how the flight controller directs each motor. This is also how the flight controller is powered (as there is no other power source connecting it).
  • Tom's Hardware link. Great source covering this in more detail
  • For Li-Po battery information
  • ESC information
  • MultiWii software setup 1
  • MultiWii software setup 2 (Radio Transmitter details also)

For those who have done this before, the above is obvious. If this can help explain some of the vague details to someone, I'm happy.

Step 3: Parts

Propulsion:

  • (1) HobbyKing Slowfly Propeller (Pack of 4): HobbyKing Link
    • Large (10 inch) propellers that will work well with our 1100KV motors.
    • Includes 2 clockwise and 2 counter-clockwise
    • I suggest buying more than one pack. They're cheap and you can easily break them!

Electronics:

  • (1) Raspberry Pi B+:
    • I have a B+ model running Raspbian, and it works fine.
    • I put my Pi in a case, which I would highly recommend doing.
  • (1) ZMR MultiWii Lite: Amazon Link, Different Vendor and more information, Forum discussing setup
    • I believe any MultiWii board would work. This one is cheaper than others, it doesn't have as many fancy features, but works just as well.
    • When bought from Amazon, an FTDI adapter and extra jumpers are included.
    • The name/picture is different on Amazon than what I received. "ZMR MultiWii Lite" is the name on my board, although Amazon's listing reads differently. I purchased through the link I have provided.
  • (4) Hobby King 30A ESC: HobbyKing Link
    • The amp rating for an ESC must exceed the max draw of its motor, otherwise it will burn out.
    • These are rated for 30A, which exceeds the max draw of our motors, 18A.
  • (1) USB Wi-Fi adapter: Amazon Link to get you started
    • I used an ALFA AWUS036NH because I already owned it, and it works well with the Pi. Other adapters would probably work well, but this adapter (as compared to a small USB model) has an antenna which I judged as necessary.

Power:

  • (1) Turnigy 3S 3300mAh:HobbyKing Link
    • This battery falls within the specs of the motors and works with the ESCs.
  • (1) Power Distribution Board: HobbyKing Link
    • No processing here, just distributes electricity. Connect with 3.5 mm bullet plugs.
  • (1) 5V Battery Pack: EasyAcc 10000mAh Power Bank
    • Unfortunately, we must use an additional battery pack to power the Pi (you could technically power it through GPIO pins, but those don't have any voltage protection). I am using the EasyAcc 10000mAh Power Bank, and yes that sounds like overkill. Look below and test it out yourself!
    • Note: Not all battery packs are made the same! The Pi requires a good consistent voltage to start up. If the voltage is fluctuating too much (with a cheap power supply) it may not start.
  • (1) Battery Monitor: HobbyKing Link
    • Will ring and flash when your battery is low.
    • This also helps to keep the life of your battery. For a longer Li-Po battery life, keep each Li-Po cell above 3.0 V.
    • Since our battery has 3 cells (3S), that means we need to keep the battery above 9.0V. This monitor will warn us when we go below that threshold.
  • (1) Battery Charger: HobyKing Link
    • You need to charge your Li-Po battery!
    • Of course, you only need this if this is your first time working with Li-Po batteries
  • (1) 12V DC power supply for Battery Charger: Amazon Link
    • This power supply is used to power the battery charger. The charger takes a 12V DC connection, so you don't need to have a power supply if you have a car adapter/ 12V battery.

Connectors:

  • (2) USB to Mini USB Cables:
    • One cable to connect the Pi to the MultiWii
    • One cable to connect the Pi to the Wi-Fi adapter. The ALFA Wi-Fi adapter uses Mini USB and should come with one. Shorter is better.
  • (1) USB to Micro USB Cable:
    • One cable to connect the 5V battery pack to the Pi. The EasyAcc battery pack comes with a short cable.
  • (2) 3.5mm Spring Connectors (Pack of 10 male/10 female): HobbyKing Link
    • 12 3.5mm female connectors to solder onto the ESCs for the motor connections.
    • 8 3.5mm male connectors to solder onto the ESCs for the power distribution board.
  • (1) XT60 Female To 4mm Bullet Connector: Amazon Link

Support:

  • (1) Frame:
    • Frame is 0.5 cm plywood.
    • Diameter: 55cm - A good width for a "stable" quadcopter.
    • Arm Width: 6.5cm - Wide enough for the motors plus a little extra. Felt stable.
    • Center Square width: 12cm - Wide enough to fit the Pi and MultiWii securely on top.
    • Stacked center square is 4cm above the base, supported by ~3cm square balsa wood of 4cm height.
    • Screws to attach the arms to the center square. I used 4 screws per arm.
    • Wood Glue to attach the risers to the center square.
    • Get creative! I had a lot of fun building my own frame.
  • (4) Feet:
    • I used ~2.5cm wide and ~7cm tall plastic cutouts from an old 9mm ammo container.
    • Place where appropriate - I put mine in the middle of my arms.
    • Make them simple, sturdy, but most importantly - easy to replace. They will (and should) break on harder landings.
  • (Many) Zip Ties:
    • In order to tie off cables, and to secure battery packs.
    • Use liberally.
  • (1) Mounting Pads: HobbyKing link
    • Necessary to use for the flight controller - they reduce vibration that would otherwise interfere with gyroscope and accelerometer readings.
    • Also good to mount the Pi with.
  • (Several) Velcro Strips:
    • Attach battery packs
    • Attach Wi-Fi adapter
    • Mount Pi (I used mounting pads, but you could velcro the case)
    • Use with Zip Ties
  • (A lot of) Tape - Electrical and Masking:
    • Electrical tape to insulate the ESC/Motor connections
    • Masking tape to hold wires/ESCs down

You will have to solder the ESC's wires to the 3.5mm bullet connectors! If you have never soldered before, I suggest watching: https://www.youtube.com/watch?v=nS0bEuYPJoA

Step 4: Building the Frame

I decided to make my own frame instead of buying one. I suggest that you do the same!

My plan was for an overall diameter of 55 cm. I knew that for a "stable" quadcopter this was a good bet. An arbitrary choice, but it works.

  1. Cut 2 x 12 cm squares
  2. Cut 4 x 21.5 + 4 cm arms. 21.5 + 21.5 + 12 = 55 cm. The extra 4 cm is to allow the arms to be attached to the center square
  3. Attach arms to center square with screws
  4. Attach power distribution board (or anything going on the first layer)
  5. Cut appropriate height risers
  6. Glue risers to center square
  7. Level top square with small shims as necessary
  8. Glue top square onto risers
  9. Attach feet as necessary
  10. Drill 4 holes for each motor base at end of arms (I left about 1 cm from the end of the arm to each motor)

Done!

Step 5: Power

Time to place your battery packs.

  • Battery packs usually go underneath the quadcopter, attached with Velcro.
    • Velcro works well alone in static conditions, but I also used zip-ties in order to prevent the packs from flying off mid-flight.
    • Make sure that all wires will reach their destinations! Try it out before placing the Velcro.
  • ESCs should be stacked/placed in a way to minimize slack in their wires.
    • Respect the colors! When connecting to the power distribution board, the ESC should be connected to the appropriate red and black ports. To flip the direction of the motors, swap the output red and black wires.

Step 6: Propulsion

Time to attach your motors!

  • Attach your motors securely to your frame, but do not attach props yet.
    • Two of your motors will spin clock-wise (CW) and the other two counterclockwise (CCW)
    • You must test which direction your motors spin before attaching any props!
    • Do not put your props on until you are ready to fly
  • Follow the pictures above on how to attach your props when ready!

NOTE: Make sure all props are approximately the same height off the motors. Push outlying props lower if necessary.

Step 7: Setting Up the MultiWii

There are tutorials online to do just this, so I will list my steps without much explanation.

A few good links:

Configuring the MultiWii

  1. Download MultiWii 2.4 (or greater) firmware from the Google Code Archive
  2. Download the Arduino Software IDE
  3. Open the Arduino project file in the MultiWii folder
  4. Plug in your MultiWii
  5. Select "Tools"->"Port"-> Select your board
  6. The board/ processor steps apply only if you have the same board that I do
  7. Select "Tools"->"Board"->"Arduino Pro or Pro mini"
  8. Select "Tools"->"Processor"->"ATMega328 (5V, 16 MHz)"
  9. Navigate to config.h
  10. Uncomment (remove the "//"): #define QUADX
  11. Uncomment: #define CRIUS_LITE
  12. Uncomment: #define FAILSAFE (Shutdown after 10 seconds of no activity)
  13. Choose value for FAILSAFE options based on the MultiWii wiki.
    1. I only changed FAILSAFE_OFF_DELAY to 0.
  14. Save the file.
  15. Run "Verify/Compile". "Sketch"->"Verify/Compile"
  16. Run "Upload". "Sketch"->"Upload"
  17. Exit the Arduino IDE
  18. Open the appropriate MultiWii conf application (For me, the 64-bit Windows did not work. 32-bit did work)
  19. Select the appropriate COM port for your board
  20. Hit "Start" to begin reading data from your board
    1. If you rotate your board, you should see the picture in the bottom right update
  21. Hit "Read" to read in the preset values.
    1. If you make any changes, just be sure to "Write" the data back to board.
  22. Set the Horizon flight mode. Info about flight modes
    1. Select the boxes next to Horizon. Essentially, these will activate the Horizon flight mode when the appropriate AUX radio channel has a specific value (Low, Med, or High).
    2. The default AUX radio value (that way no need to change during flight) is 1500. I selected all the boxes to be safe.
  23. To save settings back to the board (after you select any boxes or change any values), hit "Write".
    1. For example, if you select AUX1 Mid, then when you "Write", you should see the Horizon box turn green. This is good.
  24. Be sure to set Horizion as a flight mode. Otherwise by default you are flying in Acro mode. As a beginner, you will crash if you are in Acro.
  25. Wire your ESCs to the appropriate pinouts on the MultiWii. The conf program will show what pinout numbers to connect each ESC too.
    1. The white ESC wire should be on the inside of the MultiWii. It is the "Signal" wire, which corresponds to the printed "S" on the MultiWii
  26. When mounting the MultiWii, be sure to use mounting pads. These will decrease the vibration, increasing your control over the quadcopter.
  27. When everything is ready, connect the quadcopter to the Raspberry Pi

Step 8: Setting Up the Pi

There is a lot of setup involved, and you can follow the guide here, or I suggest following it on GitHub. The following guide is the same on the GitHub page just linked

Download/Clone my PiQuadcopter repository: https://github.com/rgw3d/PiQuadcopter.git

Overview of all the tech

  • The first thing to do is to create a hosted Wi-Fi network. To accomplish this we use isc-dhcp-server and hostapd
    • isc-dhcp-server serves as the DHCP server for our Wi-Fi network
    • hostapd serves as access point management, essentially making a Wi-Fi card into a router
  • Now for communication with our MultiWii device. I have a C library with the MSP protocol, and I use a backbone library libserialport
    • libserialport is downloaded from their git repository, and installed
    • cMultiWii, my MSP implementation is downloaded from the git repository. This will be compiled later
  • Websocket communication is needed next. I use the websocketpp library.
    • websocketpp is not installed. It is a header-only library (.hpp), and is compiled each time (with the intention of improving performance)
  • Compiling websocket.cpp in this repo will build the executable that will receive commands from a remote control, and then relay them to the MultiWii. It compiles the websocketpp library which takes along time, and the cMultiWii library which is quick to compile.

Instructions to set up your Pi with all of the software it needs:

  • Download/clone this repo
  • Run `setup_pi_software.sh`, which will install `libserialport`, `isc-dhcp-server`, `hostapd`, and download `cMultiWii`, `websocketpp`. It will also compile the websocket server. This script is just a convenience to help install all of the necessary software.
  • You need to check to see if your MultiWii is `/dev/ttyUSB0`. Check the troubleshooting section for more information
  • Since your network configuration might be different, your `/etc/network/interfaces`, `/etc/default/isc-dhcp-server`, and `/etc/dhcp/dhcpd.conf` files are not automatically modified
  • Add the following configuration to your `/etc/network/interfaces` file in order for `hostapd` to work. Also, remove any reference to `wpa_supplicant` as it causes issues with hostapd
allow-hotplug wlan0
iface wlan0 inet static
	address 192.168.10.1
	netmask 255.255.255.0
	gateway 192.168.10.1
  • Add the following configuration to your `/etc/default/isc-dhcp-server` file in order for isc-dhcp-server to know what device to use
INTERFACES="wlan0"
  • Add the following configuration to your `/etc/dhcp/dhcpd.conf` file in order for `isc-dhcp-server` to know what subnet to use
subnet 192.168.10.0 netmask 255.255.255.0 {
	range 192.168.10.1 192.168.10.30;
}
  • You need to ensure `wlan0` and `hostapd.conf` are correct. check the troubleshooting section for more information

Running the program and automatic startup

  • I would suggest a reboot after all of the installation process
  • To start up the hosted network and the websocket, run sudo ./piquadcopter.sh
  • To schedule everything to start up automatically on boot, edit /etc/rc.local with something like.../home/path/to/piquadcopter.sh.
    • rc.local is called automatically on startup.
  • Check troubleshooting for more help


Troubleshooting

  • To find your wireless interface, run `ifconfig`
  • To find your USB device, run `dmesg | grep ttyUSB` and look for what number it is
  • Once you find your device, you will need to edit line 4 of `configure_port.c` within `cMultiWii` to reflect the proper device.
  • If your wireless interface is not `wlan0`, then you will have to change it in your `interfaces` file, and in `hostapd.conf`
  • Check `/etc/hostapd/hostapd.conf` for hostapd configurations, and make sure they match your `interfaces` configuration
  • If hostapd is throwing errors similar to: `n180211: Could not configure driver mode` ... then you probably need to kill the instance of hostapd already running.
    • Run `ps -A` to view all active processes
    • Find the process ID number for hostapd
    • `sudo kill ` will kill hostapd and hopefully resolve the issue
  • If there are any problems with isc-dhcp-server, try running `sudo journalctl -u isc-dhcp-server.service` to look for errors

  • If you need to recompile at any time, just run `make` at the top level of this repository

Step 9: Download Android App

You can either download the entire repository and build the app yourself, or you can download the APK directly from here. The APK is within the app/ folder.

Once you have installed the APK, your controller is ready.

Caveats:

  • It does not tell you if you are connected (Not yet, anyway)
  • The RC data sent (Range: 1000-2000) is rounded to every 10's place. This way, not every tiny change is recorded and sent, potentially flooding the Pi and slowing it down.
    • Maybe this not necessary, but I figured better safe then sorry.
  • When flying the app only sends RC information when the position of the sticks change. MSP works by essentially overriding the normal radio input. However, the override does not last long (about a second) before more RC data needs to be sent. Without input, the flight controller will default to 1500 (value of centered sticks) for all inputs. This is the cause for the sudden audible jumps in motor speed you can hear in my video. However, while I am slowly increasing the throttle, there are no sudden jumps.
    • I realize only updating on stick change is the naive way of doing things, but on the first implementation of the app it works. I did not want the Pi to continually send the same RC command to the flight controller, because if the App looses connection I want the failsafe to kick-in

Step 10: Power on Sequence

At this point, your quadcopter should be ready to fly! Here is how you should power on the system

  1. Start with everything turned off. That means the entire quadcopter is off, and the Android app is closed.
  2. Plug in the Pi and wait for it to start up (Setting up the auto-startup sequence is most convenient, otherwise you will have to manually start it each time)
  3. Connect to the Wi-Fi network hosted by the Pi with your phone
  4. Connect main power to the quadcopter, and listen for the ESC startup beeps. The motors will not spin until you arm your motors
  5. Turn on your controller app on your phone
  6. Arm your motors and you are off!

Important notes before flying:

  • Be sure to test it out without any propellers on. Be sure to see if the quadcopter tries to self-balance - you can hear the motors spinning at different speeds when you tilt it. You can do the same thing with testing the failsafe. Also test to see how responsive the motors are to your controller inputs.
  • Only once you are sure of the setup process involved should you try to fly. The failsafe is important if something becomes unplugged and control is lost.
  • Check out this video on how to arm and disarm your motors.

Step 11: Thank You!

I hoped you enjoyed this Instructable!