Thursday, August 12, 2021

Debugging the Arduino Motor Shield

 Our L293 based motor shield had some problems! How do we diagnose what the problems are and create a better design? This final tutorial, will explain how we went about troubleshooting the issues and creating a better circuit to be used in version 2 of our design. #arduino #uno #motor #shield #debugging

Saturday, August 7, 2021

How to write your own Arduino Library

 Following our article on how to design your own Arduino motor shield, we have written a companion piece that explains how to create your own Arduino library. Our explanation focuses on all the things that the beginner tutorials don't cover. #Arduino #UNO #STEM #nexgencodecamp

Wednesday, July 28, 2021

How to Create your own Arduino Motor Shield

The Nexgen Rover is an Arduino based robot designed wholly by Nexgen Codecamp. It is used in our technology related STEM courses aimed at high schools. The robot is based on Arduino technology and runs an Arduino UNO with a motor controller shield on top. This article explains how we designed and manufactured our own motor shield to suit the requirements of the rover. #arduino #stemeducation #uno #motor #shield #nexgen

Thursday, June 3, 2021

A Review of Open Source Flight Control Firmware

 The evolution of open-source flight control firmware is fascinating and involves everything from years of committed development with no reward, to convoluted betrayal from previous partners and friends. In this article, we will review the most popular open-source projects, explain their antecedents and highlight the survivors. #arduino #drone #development

Thursday, February 25, 2021

Sunday, June 21, 2020

The Falcon DS1 - BeagleBone Blue Drone (Part 3)


The hardest part of the build is coming up with a bracket to mount the BeagleBone on the Martian II air frame. In part 1 of these tutorials, I mentioned that there was an existing bracket design available. This doesn't fit for a number of reasons, including clashes with the XT60 socket, the propellers and the top deck of the air frame. But we will come to that...

Start off by putting the frame together. There is a very thorough video of how to do this on YouTube. They are using some different components (including the flight controller), but it does a great job of showing what goes where.

As shown in Figure 20, I labelled the front of the drone and motor number locations using electrical tape. This helps keep you oriented.

Figure 20. Martian II Frame Construction.

Once you have the arms attached to the bottom frame and the Power Distribution Board (PDB) mounted, you can add the quad 20A Electronic Speed Controller (ESC). The RaceStar ESC that I bought has mounting holes which line up nicely with the PDB. I assume that this isn't a coincidence but I admit that I fluked it. Figure 21, provides an overview of what the bottom layer of the drone will look like when we are finished.

Figure 21. Bottom layer Component layout

Figure 22, illustrates the Quad ESC in place above the PDB. Now comes the tricky part (for me, you will find it easy since I supply the bracket design), mounting the BeagleBone. Referring to Figure 21, you can see that there is only 10 mm clearance between the PDB and the propellers, so our bracket can't overhang much. In addition the XT60 socket and associated cables must remain accessible with the BeagleBone in place. If we are going to stick with a stock Martian II frame, the available distance between the top and bottom layers is 30 mm and with the ESC in place we have already used 20 mm of that. Finally, we want to keep the weight centred as much as possible.

Figure 22. Bottom layer components in place.

In the end, I wasn't able to satisfy all of these constraints. The BeagleBone is just too big, it requires 17mm even if you didn't have to make connections to the pin headers (which you do). In addition, to provide access to the XT-60 the BeagleBone needs to be offest from the centre line of the drone.

Typically with the Martian II build, the LiPo battery is attached to the top frame. Instead, I have placed it between the ESC and BeagleBone. As illustrated in Figure 23, it took 5 attempts but I eventually came up with a design that met most of the constraints.

Figure 23. BeagleBone mounting plate with LiPo.

The STL file for the mounting plate is available for download from Thingiverse.

Figure 24. BeagleBone Blue 3D Printed Mounting Plate.

Wire up the power and control cabling as per the schematics in Parts 1 and 2. As our build is a bit different to the standard Martian II, I will provide a few supplementary notes and guidelines based on my experience.

Mounting the Motors

We need to mount the four brushless motors to work out the correct wire length to the ESC. My RacerStar motors came with two sets of M3 screws, 8mm and 6mm. The thickness of the frame arms is 4mm, so use the 6mm screws to ensure they don't short out the motor coils. For now you can just do them up finger tight but eventually you will want to apply loctite to ensure that the motors don't fall off mid flight (bad).

The RacerStar ESC can be programmed using the BLHeliSuite software on PC. With that we can reverse the motor direction but you need compatible Flight Controller software. For our purposes, it is probably simpler to just swap two wires if the motor is going in the wrong direction.

My motors indicate their default rotational direction (clockwise or anticlockwise) by arrows on the top of the motor and different coloured propeller  nuts. The black nuts rotate clockwise and the red nuts anticlockwise. To minimise the amount of work, you should mount the motors in the configuration shown in Figure 25.

Figure 25. Required Motor Directions (X Configuration)

Once you have mounted the motors you can then wire them to the Quad ESC. While you are doing this, also solder the ESC battery connection to the appropriate pads (+ and -) on the Power Distribution Board and a connector to allow you to plug power into the flight controller.

The Falcon DS1 - BeagleBone Blue Drone (Part 2)

Control Wiring

The BeagleBone uses mostly JST connectors. We need the following:
  • Four (4) of the 2-pin 1.5 JST ZH female connectors, with attached 150mm 28AWG wires, for the motors,
  • Eight (8) of the 4-pin 1.0 JST SH female connectors, with attached 150mm 28AWG wires, for the encoders as well as the UART, I2C, CAN, and PWR busses, and
  • Four (4) of the 6-pin 1.0 JST SH female connectors, with attached 150mm 28AWG wires, for the SPI, GPS, GPIO, and ADC busses.
These connectors are small but they are also fiddly to crimp and a bit delicate. Nevertheless this is what we are stuck with. Despite a LOT of searching, I was unable to find a complete diagram which indicated all of the correct connections for using the BeagleBone Blue as a flight controller for ArduCopter. The best I was able to find was the Imfatant version, which he provides as part of his description regarding how to get ArduCopter onto the BeagleBone. I have reproduced his image below in Figure 12.

Figure 12. BeagleBone Blue Connections (ref:

I ended up doing my own drawing, to ensure I knew what connected to what. I needed this in order to work out the best layout on the airframe and what cables and connectors are required.

Figure 13. BeagleBone Blue Control Wiring.

Note that the front of the drone is towards the top of the diagram in Figure 13. The motor numbers match up with the nearest motor outputs on the QUAD ESC. The control wires for each motor (S1, S2, S3 and S4) then go to the corresponding servo/ESC connections on the BeagleBone Blue.

Now that we have the connections worked out we can load up some software and start testing our rig.

Loading ArduCopter on the BeagleBone Blue

The most comprehensive guide to loading the ArduCopter software onto the BeagleBone Blue is found at the Imfatant Github repository. There is also a summarised version of these instructions on the Mirkix Github repository (Mirko Denecke's port of ArduPilot).

Figure 14. Checking the BBB Connection to the Mac.

I don't intend to reproduce what has already been written in these guides but I will point out areas where things have changed or if I had difficulties.

PART 1 - Preparation

  1. The first issue I found in the Imfatant Guide is that the recommended console image is no longer available at I used the latest version that I could find: Download this and flash it to a microSD card using Etcher (or equivalent). I used a Toshiba 16GB class 10 card so that I would have plenty of room and speed.
  2. I inserted the SD card (it only goes in one way) and booted up the BeagleBone Blue (BBB from here on), by connecting it to my Mac via the micro USB connection. As suggested in the instructions I tried "ssh debian@" but the operation timed out. It appears that there are two drivers that you have to download and install for this to work on the Mac. 
  3. Download the two drivers: Network: and Serial: and then install them. The Serial driver may ask you to reboot your computer (it did for me).  The Beaglebone Blue creates a network connection and emulates an Ethernet adapter. Your computer will receive IP addresses and The Beaglebone Blue has IP addresses and You can check whether this has worked by looking at Networks in system preferences (ref: Figure 14).
  4. You should now be able to ssh in ("ssh debian@") without difficulty. Password is "temppwd" (see Figure 15 to view a successful first log in).  If you receive a “REMOTE HOST IDENTIFICATION HAS CHANGED” error, you have probably previously connected to a different computer on (like another BBB). Remove the old ECDSA key with: "ssh-keygen -R".
  5. Next thing you need to do is get WiFi up on the BBB. Follow the Imfatant instructions for this but I found that I had to power the device down and reboot before the changes would take effect. Make sure you "sudo shutdown -h now" before powering down. While you have the power off, CAREFULLY turn the antennas around so that they face off the board. They swivel so don't just try and bend them up and over. You can unplug and replug the antennas if you prefer. Once you power back up, you should have the central green LED lit to indicate a WiFi network connection (ref: Figure 16). 
  6. To get the WiFi IP address of your BBB, I usually use "hostname -I" or "ip addr show wlan0". Alternatively, you can just have a look on your router. Terminate your usb connection and ssh back in using the WiFi IP address. The password is the same. Verify that you have an internet connection using "ping -c 3".
  7. The remainder of the Imfatant Part 1 Preparation instructions went smoothly for me.
Figure 15. Logged into the BBB via USB.

Figure 16. Green WiFi LED on indicating a connection.

Part 2 - Installing ArduPilot

Follow the Imfatant instructions for setting up the ArduPilot environment configuration file, /etc/default/ardupilot.

The switch -A in the ardupilot config file maps ArduPilot's "Console" serial port (SERIAL0, default 115200) to a target IP address and port number of one's choosing. For example, this allows MAVLink data to be transmitted over WiFi for test purposes. This data stream is auto-sensed by ground control station software like Mission Planner (Windows) and QGroundControl (Windows, OS X, Linux, iOS and Android).

To get the IP address of your Mac, from the Apple menu pull down “System Preferences” and click on the “Network” preference pane. The IP address for your WiFi connection will be shown on the right (see Figure 17).

Figure 17. Getting your Mac IP address for WiFi.

For Windows, press the Windows Start key to open the Start screen. Type cmd and press Enter to launch the command prompt. Type ipconfig at the command prompt to check the network card settings. See Figure 18, you want the IPv4 address.

Figure 18. Getting IP address for Windows

The next tricky bit is getting the latest ArduCopter executable, built specifically for the BBBlue's Arm architecture, onto the BBB. The Mirko Denecke link no longer works but the Imfatant one will allow you to download arducopter v3.6.

Once you have the file downloaded, there are a few different ways you can copy it to the BeagleBone. You can use SCP, just copy it onto a USB drive and then plug that into the BBB, or you can use something like FileZilla. I took the last approach. Depending on permissions, this may be as easy as dragging the file across (Figure 19).

To check the current permissions on the file type, "ls -ld /usr/bin/ardupilot". My initial result was:

drwxr-xr-x 2 root root 4096 Aug  6 08:29 /usr/bin/ardupilot

Which is a problem because the directory's owner and group is root and we have FTP'ed in as debian. In the string displayed above, the first character indicates if we are looking at a directory (d), file (-) or link (l). After that, the folder and file access rights are divided into three categories:

xxx are access rights for the owner
yyy are access rights for the owner's group
zzz are the access rights for everyone else
The access rights symbols will indicate whether you can read (r), write (w), execute (x) or are missing a right(-). Based on our results, the only person who can write a file into this directory is the owner (i.e. root). We can use chmod to fix this. In terminal type: "sudo chmod o+rwx /usr/bin/ardupilot" The "o" switch applies this change to all users and we are adding (+rwx) read, write and execute rights for this directory. Check with "ls -ld /usr/bin/ardupilot". You should get something like:

drwxr-xrwx 2 root root 4096 Aug  6 08:29 /usr/bin/ardupilot

You should now be able to drag across the arducopter executable into the /usr/bin/ardupilot directory as shown in figure 19. Username and password is the same as for ssh. Use port 22.

Figure 19. Copying the arducopter executable to the BBB using FileZilla.

After this we "sudo systemctl enable arducopter.service" and rebooted the BBB. Job done! You can check that arducopter is enabled with "systemctl is-enabled arducopter".

In Part 3 we will start putting everything together.