driving an LED using a Raspberry Pi

Today we will look at what it takes to turn on and off a light that is not part of the Raspberry Pi. The LEDs have changed between the Pi4 and Pi5 so we will not look at using the on-board LEDs but an LED attached through the GPIO (General Purpose I/O) ports.

Before we get into the GPIO pin assignments, let’s review what an LED is and how it works. If you read the blog posting on driving an LED using an Arduino UNO R3 you can skip to the picture of the Raspberry Pi GPIO ports.

The LED design is very simple. When you put a voltage across an LED it emits light. Unfortunately, if you put 5 volts with almost any amperage across the LED it will melt and become unusable. To prevent the LED from melting a resistor is typically placed between the Raspberry Pi and the LED to limit the voltage going into the LED.

To begin our discussion let’s look at an electrical schematic of an LED.

When a voltage is places across the LED it emits light. The long leg of the LED is the positive lead and the short leg is the negative lead. Putting a positive voltage on the negative lead and grounding the positive lead will not do anything. Putting a positive voltage on the positive lead and grounding the negative lead will cause the LED to “light up” and emit light.

It is important to note that different LEDs require different voltages to emit light. The higher the voltage, the brighter the light shines. A red LED, for example, needs at least 1.63 volts before it begins emitting light and will burn out if you put more than 2.03 volts across it. A green LED, on the other hand needs at least 1.9 volts and can go as high as 4.0 volts before it overheats.

Fortunately, we can use a resistor in series with the LED to control the brightness. The higher the resistor value, the less light the LED will emit. In the picture below a yellow LED is combined with different resistor values.

Note that a 330 Ohm resistor, which has the least amount of resistance of all resistors shown, caused the LED to be brighter. The 100K Ohm resistor, which is about 1000 times more powerful than a 300 Ohm resistor, barely causes the yellow LED to turn on. Note in this diagram the red wire coming in from the left is supplying a 5 volt DC power and the black wire is providing a ground connection. With the breadboard (the white board that everything is plugged into) the two outer rows provide a connection to all of the holes along the blue line. The ground line is the row on the right of the board and the 5 volt line in the next row in line designated with a red stripe

In the diagram above a 220 Ohm resistor is used to limit the voltage going across the green LED. We put 3.3 volts on the red bus on the left and ground on the blue bus on the right. By putting a resistor in hole 17 on the red bus, it connects one end of the resistor to the 3.3 volt supply. By putting the other end of the resistor in the left most pin in row 16 we can then put the positive lead of the LED in any of the holes on row 16 to connect the resistor to the LED. We then put the negative end of the LED in tow 16 on the other side of the air gap and tie it to ground with a wire running from any of the 16 pin holes to any pin on the blue line running up and down. Off screen we connect a voltage supply (or battery) to the red and blue lines with wires somewhere on the breadboard.

To calculate the resistor needed for an LED, we need to know the voltage drop across the LED and the voltage of our supply. For an Raspberry Pi the voltage supply is 5 volts.

To calculate the resistor value we use Ohm’s Law which basically is voltage is the product of current and resistance. If we have multiple voltage drops (as with a resistor and an led in series) the equation to calculate the resistance can be expressed as …

A good website to calculate this is available at https://ohmslawcalculator.com/led-resistor-calculator . If we assume a 5 volt source and a 2 volt drop across the LED with 1 milliamp of current going through the LED and resistor we get a 3000 Ohm resistor (otherwise known as a 3K resistor). If we have a 4 volt drop (as is the case with a green LED) we would use a 1K resistor. In this example we would place a 3K resistor in series with a red LED and a 1K resistor in series with a green LED to have them with the same brightness. It is important to note that putting the resistor closer to the 5 volt power or closer to the ground line makes no difference. The only important thing is to put the resistor in series with the LED which means that they share one common plug in point on the breadboard.

In the above diagram the blue wire is attached to ground on the Raspberry Pi and the purple wire is attached to GPIO pin 14. For the Raspberry Pi 5 the GPIO pinout is the same as previous versions of the Raspberry Pi.

Note that the GPIO lines are arranged on both sides of the connector block and are numbered from 0 through 27. Some of these pins have special functions like pulse width modulation (PWM) or serial transmission (TXD/RXD) while others are generic input and output pins. Pins 5, 6, 16, 17, 22, 23, 24, 25, 26, and 27 are generic pins and can be programmed to be digital input or output lines. When a line is programmed to be an output line it is either enabled to be HIGH (or 5 volts) or LOW (or zero volts).

Let’s start by driving one LED using GPIO pin 17 as shown in the diagram

In this example we are going to use the command line to turn on and off the LED. To do this we will ssh into the Raspberry Pi and execute the pinctrl command. This command allows us to set a pin high or low with a simple command.

$ pinctrl set 17 op

defined GPIO pin 17 as an output pin

$ pinctrl set 17 dh

turns on the LED by driving GPIO pin 17 with 5 volts.

$ pinctrl set 17 dl

turns off the LED by driving GPIO pin 17 to zero volts.

We can program this in a shell command by creating an infinite loop, turning on the LED, sleeping for a while, turning off the LED, and sleeping again before repeating

pinctrl set 17 op

while true

do

pinctrl set 17 dh

sleep 1

pinctrl set 17 dl

sleep 1

done

The first pinctrl command defined GPIO pin 17 as an output only pin. The while true creates the infinite loop. Everything between the do and done statements will be executed over and over. The second pinctrl command sets pin 17 to high with the dh option. The sleep 1 sleeps for a full second. The third pinctrl command sets pin 17 to low followed by another sleep function for another second.

We could change this program to drive multiple LEDs of different colors as is done with a traffic light by using multiple GPIO pins.

In this example we are driving the Red LED with GPIO pin 17, the yellow with pin 18, and the green with pin 22 (with an extra blue LED on pin 23). We can change the code by repeating the pinctrl commands directing the different pins to turn on and off the lights

# define GPIO pins as outputs

# loop through turning on and off lights

while true
do
pinctrl set 17 dh # turn on red LED
sleep 1
pinctrl set 17 dl # turn off red LED
sleep 1


done

The lines in red are the added lines to drive the two additional LEDs. Using the command line can have some difficulties and is not the best way of performing this operation. To perform the pinctrl command you might need to be a root or super user. Not everyone has the rights or privileges to perform this function. In the next post we will look at using a programming language rather than a command line to drive the LEDs.

vsphere_virtual_machine creation

In a previous blog we looked at how to identify an existing vSphere virtual machine and add it as a data element so that it can be referenced. In this blog we will dive a little deeper and look at how to define a similar instance as a template then use that template to create a new virtual machine using the resource command.

It is important to note that we are talking about three different constructs within Terraform in the previous paragraph.

  • data declaration – defining an existing resource to reference it as an element. This element is considered to be static and can not be modified or destroyed but it does not exist, terraform will complain that the declaration failed since the element does not exist. More specifically, data vsphere_virtual_machine is the type for existing vms.
  • template declaration – this is more of a vSphere and not necessarily a Terraform definition. This defines how vSphere copies or replicates an existing instance to create a new one as a clone and not necessarily from scratch
  • resource declaration – defining a resource that you want to manage. You can create, modify, and destroy the resource as needed or desired with the proper commands. More specifically, resource vsphere_virtual_machine is the type for new or managed vms.

We earlier looked at how to generate the basic requirements to connect to a vSphere server and how to pull in the $TF_VAR_<variable> label to connect. With this we were able to define the vspher_server, vsphere_user, and vspher_password variable types using a script. If we use the PowerCLI module we can actually connect using this script using the format

Connect-VIServer -Server $TF_VAR_vsphere_server -User $TF_VAR_vsphere_user -Password $TF_VAR_vsphere_password

This is possible because if the values do not exist then they are assigned in the script file. From this we can fill in the following data

  • vsphere_datacenter from Get-Datacenter
  • vsphere_virtual_machine (templates) from Get-Template
  • vsphere_host from Get-Datacenter | Get-VMHost
  • vsphere_datastore from Get-Datastore

The vsphere_datacenter assignment is relatively simple

$connect = Connect-VIServer -Server $TF_VAR_vsphere_server -User $TF_VAR_vsphere_user -Password $TF_VAR_vsphere_password

$dc = Get-Datacenter
Write-Host ‘# vsphere_datacenter definition’
Write-Host ‘ ‘
Write-Host -Separator “” ‘data “vsphere_datacenter” “dc” {
name = “‘$dc.Name'”‘
‘}’
Write-Host ‘ ‘

This results in an output that looks like…

# vsphere_datacenter definition

data “vsphere_datacenter” “dc” {
name = “Home-lab”
}

This is the format that we want for our parameter.tf file. We can do something similar for the vm templates

Write-Host ‘# vsphere_virtual_machine (template) definition’
Write-Host ‘ ‘
$Template_Name = @()
$Template_Name = Get-Template

foreach ($item in $Template_Name) {
Write-Host -Separator “” ‘data “vsphere_virtual_machine” “‘$item'”‘ ‘ {
name = “‘$item'”‘
‘ datacenter_id = data.vsphere_datacenter.dc.id
}’
Write-Host ‘ ‘
}
Write-Host ‘ ‘

This results in the following output…

#vsphere_virtual_machine (template) definition

data “vsphere_virtual_machine” “win_10_template” {
name = “win_10_template”
datacenter_id = data.vsphere_datacenter.dc.id
}

data “vsphere_virtual_machine” “win-2019-template” {
name = “win-2019-template”
datacenter_id = data.vsphere_datacenter.dc.id
}

We can do similar actions for vsphere_host using

$Host_name = @()
$Host_name = Get-Datacenter | Get-VMHost

as well as vsphere_datastore using

$Datastore_name = @()
$Datastore_name = Get-Datastore

The resulting output is a terraform ready parameter file that represents the current state of our environment. The datacenter, host, and datastores should not change from run to run. We might define new templates so these might be added or removed but this script should be good for generating the basis of our existing infrastructure and give us the foundation to build a new vsphere_virtual_machine.

To create a vsphere_virtual_machine we need the following elements

  • name
  • resource_pool_id
  • disk
    • label
  • network_interface
    • network_id

These are the minimum requirements required by the documentation and will allows you to pass the terraform init but the apply will fail. Additional values that are needed

  • host_system_id – host to run the virtual machine on
  • guest_id – identifier for operating system type (windows, linux, etc)
  • disk.size – size of disk
  • clone.template_uuid – id of template to clone to create the instance.

The main.tf file that works to create our instance looks like

data “vsphere_virtual_machine” “test_minimal” {
name = “esxi6.7”
datacenter_id = data.vsphere_datacenter.dc.id
}

resource “vsphere_virtual_machine” “vm” {
name = “terraform-test”
resource_pool_id = data.vsphere_resource_pool.Resources-10_0_0_92.id
host_system_id = data.vsphere_host.Host-10_0_0_92.id
guest_id = “windows9_64Guest”
network_interface {
network_id = data.vsphere_network.VMNetwork.id
}
disk {
label = “Disk0”
size = 40
}
clone {
template_uuid = data.vsphere_virtual_machine.win_10_template.id
}
}

The Resources-10_0_0_92, Host-10_0_0_92, and win_10_template were all generated by our script and we pulled them from the variables.tf file after it was generated. The first vm “test_minimal” shows how to identify an existing virtual_machine. The second “vm” shows how to create a new virtual machine from a template.

The files of interest in the git repository are

  • connect.ps1 – script to generate variables.tf file
  • main.tf – terraform file to show example of how to declare virtual_machine using data and resource (aka create new from template)
  • variables.tf – file generated from connect.ps1 script after pointing to my lab servers

All of these files are located on https://github.com/patshuff/terraform-learning. In summary, we can generate our variables.tf file by executing a connext.ps1 script. This script generates the variables.tf file (test.yy initially but you can change that) and you can pull the server, resource_pool, templates, and datastore information from this config file. It typically only needs to be run once or when you create a new template if you want it automatically created. For my simple test system it took about 10 minutes to create the virtual machine and assign it a new IP address to show terraform that the clone worked. We could release earlier but we won’t get the IP address of the new virtual instance.

mason jar bourbon

I taste tested a few of my mason jar aging experiments this weekend and the results were surprising.

2016-01-30 11.30.25

The Whistlestop with a light char was my favorite. It almost makes me want to try an uncharred piece of oak just to see what it does. The flavor changes after three weeks into a smoother bourbon. The color is a light golden brown and gets darker and darker every week.

2016-02-13 14.15.19

The light char got rid of the acidic after bite that the white whiskey has and makes it a little smoother. It still smells very much like moonshine but has other smells associated with it.

The dark char has a smoky almost burnt flavor. My hopes are that this will fade over time. I could tell a big difference between the light and dark char. I might need to experiment with different levels of char and how long the chips are allowed to cook in the cast iron box to get different levels of char.

The hickory wood is my least favorite. The flavor was not what I expected and took on almost a rancid flavor. I was glad that I had crackers close by. The flavor was not smooth and not something that I would repeat. I will give it a few more months but I have little or no hope that this will work. It does make me want to try other woods to see what the differences are. I do have some apple and pecan chips that might be worth experimenting with.

I decided to fill my 5 liter cask with Weller Special Reserve and see if I could smooth the flavor with the oak barrel. I first hydrated the cask with water for a week and rinsed it out. I then put three 1.5 liter bottles in the cask and let it sit for a week. The flavor changed but not as much as the mason jar experiments. My guess is that the cask is a light char. Since I got it as a present I have no clue how much char there is inside. I like the flavor and look forward to seeing how it mellows as the weeks go on.

2016-02-06 11.59.14

Status update:

mason jars: 3 weeks on the shelf, flavor changed after week 1.

oak cask: 1 week on the shelf, flavor smoother after 1 week.

 

different kind of homebrew

For Christmas I got a small keg to age something in. I did not want to just dive straight into aging bourbon without experimenting first so I did a little research.

2016-02-06 11.59.14

It turns out that aging distilled spirits is not something new but has been around since the history of our country. Who knew? Some of the interesting sites that I found suggested first trying a small quantity in a mason jar with wood charred and placed in the jar with the whiskey. A few of those sites are

There are also a ton of companies that will “help” you start your project.

So loaded with research material and a bunch of mason jars, I thought what did I have to loose?

2016-01-30 10.39.39

I went ahead and collected what I thought would be all of the necessary components. Given that I love to experiment I wanted to try oak and hickory chips as well as white whiskey, moonshine, and bourbon as the base.

The two types of chips that I got were Jack Daniels Oak Barrel chips used for BBQ smoking (Ace Hardware) and Hickory chips for flavoring.

2016-01-30 10.41.052016-01-30 10.41.29

 

 

 

 

 

 

The blogs that I read suggested burning the chips and placing them in a mason jar with the white whiskey. I wanted to do this in a controlled way so I measured 2 cups of white whiskey and 50 grams of chips. I experimented burning the chips with a dark and light char as well as burning them by hand with a butane torch and with a smoking box in side a grill.

2016-01-30 10.45.04 2016-01-30 10.45.20 2016-01-30 10.47.26 2016-01-30 10.54.39

The three liquids that are being experimented with are White Whiskey, Moonshine, and Weller Reserve Bourbon.

2016-01-30 10.40.49 2016-01-30 10.40.56 HDR 2016-01-30 10.41.01

First I put light charred chips into a mason jar and added 2 cups of White Whiskey. Everything that I read suggested getting something with the highest proof because it will absorb the flavor of the wood better than a lower, watered down concentration. The Rio Brazos Whistlestop is 90 proof. The Palmetto Moonshine is 105 proof. The Weller Special Reserve is 90 proof.

2016-01-30 10.55.27 HDR 2016-01-30 10.55.27 2016-01-30 10.57.38 2016-01-30 11.00.48 HDR 2016-01-30 11.00.48 2016-01-30 11.14.21

I put blue painters tape on each jar to label if it was light or dark char, if it was hickory or oak chips, and if it was Weller, Whistlestop, or Moonshine.

Everything that I read said don’t expect much change over the first week or two. The color changes very quickly but the flavor does not change. I stored the mason jars in the garage because the temperature variation helps the wood absorb and express the whiskey. The smaller container ages everything at a faster rate since you have a higher liquid to wood ratio. What would typically take 3 years should take 2-3 months. My hope is to sample the different containers and see if it gets better over the weeks/months.

I did sample the Weller a week later to see if the flavor changed and was very surprised how much it changed. The flavor took on a smoky and woody taste. I am not sure if it is something that I like but it had less of an acidic after burn but also tasted oversmoked. My hope is that it will settle down and smooth out as the liquid pulls from deeper and deeper in the wood.

2016-01-30 11.30.25

After my initial experiment I did put samples on the shelf and filled my 5 liter cask with Weller. Given that Weller and Whistlestop costs the same at our local liquor store I wanted to start with aged bourbon and see if I could change the flavor.

It is important to look at the economics

Simple experiment – $60, mason jars, smoking box, chips, 1 liter liqueur of choice.

Full Barrel – $260, oak barrel, 4.5 liter liqueur of choice, smoking box, chips.

I also ordered some test tubes with cork stoppers ($12 for a dozen) so that I could pull half a shot a week to test the taste. I label the corks with a number representing the week that it was pulled and plan on doing a vertical sampling after month three.

2016-02-13 14.15.19

 

 

quadcopter assembly – part 3

We will continue our journey into building a quadcopter by working on the flight controller circuit.

quadcopter

The flight controller that we will be using is the Acro Naze32 Flight Controller ($31). This controller requires a little assembly prior to using because it comes in parts. The surface mount parts are on the board but the headers need to be soldered to the circuit. Naze32

The board comes with a straight or angled connector. It is confusing which you want to use. If you get the board without the barometer module it is recommended to use the straight connector. If you get the board with the barometer chip then the angled connector is probably best so that you can put a GPS unit in the same space on top of the quadcopter.

In my opinion, the design of the board is counter intuitive and has some design flaws. The kit comes with three connectors that need to be soldered onto the board. The two headers that go through holes on the board are relatively easy even though one of the connectors is millimeters from a surface mount component. What makes no sense to me is the gold connector that you have to side mount pins to. A connection like this typically is easy to mess up and break under vibration. Why put an edge connector here and not put through holes to solder? The pin towards the middle of the board is close to three surface mount components. Overall, I think that the design is somewhat silly. Why ship extra headers at extra cost but skimp on board size and not put through holes for higher reliability? The connector that I am openly ranting about is the connector shown on the far left on the picture below (connected to pins 4,5,6,7, and 8).

flight_controller_2 flight_controller_1

The next step is to lock down all of the screws mounting the arms to the Q450. This is relatively simple and requires a 2.0mm allen wrench.  Once these are locked down we screw the prop mounts onto the motor with a 2.3mm allen wrench. The two photos below show the screws going into the motor then the prop spacer and nut to hold the prop.

motor_prop_holdermotor_with_nut

The next step is to mount the flight controller to the quadcopter assembly. The assembly has an arrow on top pointing to the direction of travel. The circuit board also has an arrow pointing to the direction of travel. We are going to mount the flight controller board on top of the quadcopter using double sided tape (we could use screws and spacers if desired because the holes are on the board and on the quadcopter). If you use screws and spacers you need grommets to reduce vibration. The double sided tape tends to dampen vibration and keep the system from changing during flight. It is CRITICAL that you use enough tape to isolate the electrical components and the board. It is also CRITICAL that the arrows align with each other. This keeps the software and remote controller aligned. Moving the board off axis will cause imbalance in the motor controller and flight controls.

flight_controller_alignment controller_mounting

Once we have the flight controller mounted, we can mount the battery between the two layers. This is done with a velcro strap to allow for quick release. We loop the strap through the two rectangular holes on the bottom board.

battery_1 battery_2

The next step is a little difficult. We need to take the middle wire (red wire) from the 3 pin connector coming off the speed controller and pull it out. We don’t want all four speed controllers providing power to the flight controller. We take the middle pin out from three of our speed controllers and cover them with shrink fit tubing. The reason why we use heat shrink rather than cutting the wire is to have redundant systems to use in the future. We can always take the tubing off and put the cable back into the connector.

connector_2 connector_1

Now that we have three of the connectors modified, we can plug these connectors into the flight controller.

In the class we took a diversion and downloaded the baseflight-configurator using Google Chrome Store. This is done by searching for baseflight-configurator and installing the plug-in. Once the plug-in is installed, launch it and install the USB driver for the computer that you are using. Once this is installed you should be able to connect to the flight controller from a USB to mini-USB connector.

fc_to_laptop

With this we have a connection to the flight controller from our laptop. If you click on the connect with the port configured to be at 115200 speed you should get a green Disconnect button rather than a red Connect button. As you move the quadcopter around you should see the motion mirrored on the laptop.

The first thing that we need to do once we have the baseflight-configurator running, we need to update the firmware and flash it to the controller. We download the firmware from github then flash it to the controller.

From this we go into the configurator and setup things like motor rotation direction, throttle max and mins. Make sure all features are turned off. We then save and it updates the flight controller firmware.

The class instructions starting at page 113 have screen shots of all of these configurations along with explanation of all options and selections.

One side discussion was that a mobius 1080p camera ($82) is a good add on. It allows you to record a flight and does not add much weight to the quadcopter.

Once we have the software operational, we can connect the speed controllers (and thus the motors) to the flight controller. Looking at the configuration diagram for a Quad X configuration we notice that the bottom right motor is channel 1, top right is channel 2, bottom left is channel 3, and the top left is channel 4. This corresponds to the pin block at the front of the flight controller (front being where the arrow is pointing). The numbering starts from the right side with pin 1 and goes to pin 6 at the left. The orange cable is the signal, the red pin (only connected via channel 2) is power, and the brown wires are ground. You can verify this by looking next to pins 6 and see the “-“, “+”, and square wave on the circuit board. In the photo below we have the speed controllers plugged into channels 1, 2, 3, and 4 with channels 5 and 6 unconnected.

fc_motor

 

The next step is to plug back into the laptop and test the rotation direction of the motors. By going into the motor testing tab we can energize the motors and rotate them at different speeds. This allows us to test the direction of the motor rotation and reverse the red and yellow wires going to the motor to have them rotate in the direction that we want.

The cool thing at this point is that we have a working quadcopter. We have a battery pack that is communicating to the flight controller. The flight controllers are pushing power to the speed controllers thus turning the motors. The only thing that we are missing is the rc controller to control motor speed and flight. We are using the laptop as the rc controller for calibration.

The next step in the class is to get your rc transmitter paired with the on-board receiver. Given that we had a Spektrum transmitter and receiver, it was different from everyone else. For ours we had to follow the directions in the Spektrum manual. Page 10 shows how to bind the receiver with the transmitter. We used the bind plug method (Binding Using the Receiver and Receiver Battery). We plugged the bind plug into the bind section of the receiver and unplugged connector 2 from the flight controller and plugged it into the receiver. We put the transmitter into bind mode and waited for it to sync with the receiver. Once this one done, the transmitter acknowledged the connection and we could power down the receiver.

The receiver has labels on the connectors. Looking from the bottom with the printing on the left, the bottom row is the bind/dat row. The next row is labeled Thro which correlated to channel 1. The Aile (aileron) is channel 2. The ELEV is channel 3. The RUDD is channel 4. The GEAR is channel 5. The AUX1 is channel 6. Once we map these to the receiver, we need to program the transmitter appropriately.

receiver

With the receiver connected, we power on the quadcopter by plugging in the battery (while connected to the laptop) and can calibrate the rc transmitter so that the controls min out at 1000 and max out at 2000. This is done for the four channels that represent thrust (THRO), pitch (elev), roll (aile), and yaw(rudd). By moving the controls on the transmitter we can see the controls change on the computer. The motors should also spin while you are playing with the controls. You should be able to verify the different motors spinning as you adjust the controls.

tx_cali2 tx_cali

At this point we have a transmitter that communicates to the receiver. We have a receiver that is communicating to the flight controller. We also have a flight controller that is energizing the speed controllers and making the motors spin. The only thing that we are missing is a cover to protect our electronics and propellers.

The cover that we are using is a cover printed by the instructor. The cover is ABS so it is easy to modify with drill holes and cut excess edges off. You can then tape or velcro the top to the quadcopter frame. The instructor puts his receiver taped to the top cover. We are going to put our receiver between the two decks with double sided tape attached to the bottom. You can operate without a cover but your electronics are exposed and hitting the ground could get moisture or dirt into your circuit board.

cover2 cover1

We will use a dremel tool to route out parts of the cover to allow it to fit on top of the assembly and fix it to the frame using velcro.

The props are put onto the motor shafts. The rings under the quadcopter are stabilizers for the propellers to keep them from vibrating. The ring goes onto the shaft first followed by the propeller then the metal washer and metal nut. The metal washer is a bridge to protect the plastic propeller and help keep the nut tight on the shaft. Use a wrench to tighten down the nuts before flying every time that you fly. During flight, half the nuts are trying to get tighter and the other half is trying to get looser.

prop1

 

With this we have flight! Plugging in the battery and powering on the transmitter allows us to fly our new quadcopter!

Now that we are at the end of the class, let’s review the overall cost. The class itself was $345. This cost covered about half of the cost of building a quadcopter. The overall cost to build this system from scratch is just over $700.

The up front costs for this class are:

  • $300 – rc controller
  • $43 – Lectron Pro 11.1 volt Lithium Ion Battery
  • $45 – Prophet Sport Li-Pro 35W Peak Battery Charger
  • $345 – class fee

total cost: $733

Included in the ($345) class you get

  • $4 – clear electrical tape
  • $2 – solder
  • $18 – apc composite 9×4.5 MR (2) and MPR (2) props
  • $6 – XT60 connectors
  • $13 – Diatone Innovations Q450 V3 quadcopter frame
  • $21 – Afro ESC 20A speed controller (4)
  • $3 – zip ties / velcro / double sided tape
  • $13 – non-adhesive shelf liner
  • $220 – Multistar 2213-980 14-pole outrunner motor (4 at $55 each)

total in parts: $300 that comes with the class

optional components are:

  • $20 – prop balancer
  • $8 – lipo battery monitor
  • $60 – watt meter

Overall, this was a very good class. It was good talking about the theory and practical ways of building a quadcopter. The class does not focus on flying but does talk about when, where, and how to fly. You are on your own to learn how to fly and repair the quadcopter as you crash while learning.

 

quadcopter assembly – part 2

In the last post we started by documenting a class that details how to build a quadcopter.

quadcopter

 

In this post we will look at the Diatone Innovations Q450 V3 platform ($13).

q450

The first step is to solder the power connector with the female connector to the board. We solder the red lead to the “+” and the black lead to the “-“. We also put some solder on the pads that will be used for the motor controllers. On the Q450 that we got there are eight pairs of connectors. We prepared the outer four “+” and “-” pads with solder to accept the motor connections.

q450_withPower

The next step is to attach the speed controller circuit (ESC) to the extension arm and solder the non motor connection leads to the board. The ESC is attached to the extension arm using zip ties. Nothing else needs to be done to attach it since it should stay in place and not slip during flight.

The ESC that we are using is the Afro ESC 20A ($21 each and we need four of them). The system has three types of connectors. One goes to power, one goes to the electronics, and one goes to the motor. In the picture below the red, yellow, black go to the motor. The black and red on the right are the power connections that we will solder to the Q450 board. The purple, red, yellow ribbon cable is the control cable that will be attached to the controller.

afro_esc2

 

We use a simple zip tie and a non-adhesive shelf liner (part of $13) to keep the ESC in place as shown in the photo. We then cut the power cables (right red and black cables in photo above) and solder them to the Q450 board (shown below).

arm_with_escesc_to_q450

Once we have the power cords soldered to the Q450 board we screw the arm onto the Q450 to relieve the cable strain on the newly soldered wires. The connection should look like the photo below.

arm2

The biggest difficulty that we had was the spacing between the mounting hole for the arm and the angle that the cables came in. At times the black wire covered the screw hole and we had to re-solder the wire to attach from a different angle.

Once we have the arms installed, the next step is to mount the motors and test the electrical. We are using the Multistar 2213-980 14-pole outrunner motor ($55 each, we need 4).

motor

Each motor is attached to the arm with four screws. When we initially tried fitting the screws through the arm a couple of them did not want to go through. The arms are injection molded and had a little “overhang” on the screw hole. Using an allen wrench we were able to clear the excess plastic and mount the motors on the arm.

 

 

and now for something completely different – building a quadcopter

Everything technical needs a diversion. This will be a log of building a quadcopter based on a class that I attended this weekend. The class is hosted by the Houston Hackerspace TxRxLabs. It is a two day class that results in a working quadcopter at the end of the class.

“Everything you need to know to start building your own multicopters. This is a hands-on class in which, by the end of the class, you will have built your own RC quadcopter.”

quadcopter

The pre-notes for the class can be found here. The most important thing to bring is a remote control unit similar to what is used for RC cars, boats, and planes. We purchased the Spektrum DX6 ($200-$300) from a local hobby shop in Houston. The majority of the class purchased the Taranis FrSky X9D ($300). The major benefit of the Taranis is that it is a 16-channel system rather than a 6-channel system for about the same price.

The instructor presentation is a good overview of the class.

The class started out with a discussion on where it is appropriate and not appropriate to fly drones. The best place to start flying is to fly on private property, local parks, or a certified flying field. There are places where you should not fly. www.airmap.io is a list of no fly zones. A good rule of thumb is nothing within 5 miles of an airport or over anything government facilities (state and local).
no_fly_zoneAlso keep in mind where you are flying and what would happen if you loose power. For example, don’t fly over a highway or places with large crowds. The quadcopter has weight and can travel upto 50 plus miles per hour.

www.meetup.com/sotexdug is a local drone flying club. www.rchouston.com is another local flying club but not specific to quadcopters. They rate and list local flying fields.

 One important thing to focus on is making sure that your propeller is not too heavy on one side. This will cause stress and instability and excess wear and tear on your motor. A prop balancer is a good investment ($20). Cheaper balancers are also available and can be used by hand ($6). It is important to get something that will work with a 9 inch prop. The props that we are using for this class are APC Composite 9×4.5 MRP props ($9 for two props).

To balance the prop you mount the prop on the balancer and watch which side drops to the floor. You can add weight to the top part of the prop using small clips of clear electrical tape ($4). propBalancer

In this example it took 3-4 small pieces of tape to get the prop to remain relatively level. It is important that the tape not get too close to the leading or trailing edge of the prop. The tape should also be placed on the inside edge of the prop and not on the outside edge. The inside edge is the edge where the air flow is at a minimum. This changes based on how you mount the prop on the motor and rotation direction of the prop. The tape is relatively strong and should stick.

tapeOnProp

The next discussion was around battery life, best practices, and recommendations. Try not to discharge the cell below 3 volts and don’t store them uncharged. Charge them before you put them away for the week. They will loose charge sitting in the bag and if you get below the minimum charge it will not retain as much charge in the future. We purchased the Lectron Pro 11.1 volt Lithium Ion Battery (2200mAh ($69 for three pack) and 3500mAh ($43 for one) batteries). You only need one but we got two so that we could extend the flight time.

A good tool to have is a lipo battery monitor that shows the quality of your battery ($8 for a pair). A good rule of thumb is to store the batteries in a cool location. An ammo can is a good place to store the batteries because bad batteries tend to do bad things (fire, explode, insert what you want here).

You will also need charger that is compatible with the battery that you purchase. We selected the Prophet Sport Li-Pro 35W Peak Li-Po Battery Charger ($30-$45). The charger has a 2S and 3S plug on the front. We will use the 3S connector because the batteries that we purchased are 3 cell batteries.

 Servos are something worth looking into. If you are going to mount a camera onto your quadcopter to help with navigation you will need to tilt your camera up when you go faster and level when you slow down. If you don’t tilt your camera it will be pointing into the ground and not in the direction of flight. Most servos operate at 4-6V DC. For a nav camera a small motor with a separate battery might be better. You don’t want to loose your vision or have vision draw too much current from the rotors.

The speed controller is what controls the rotation of the motors. They are driven by a pulse width modulation (PWM) signal from the remote controller. They work on 5V and typically draw 500mA but do generate a significant amount of heat if used over a long period of time.

When selecting a motor it is important to know the prop characteristics, the current draw, the rotational speed at nominal operations. There are a variety of motors that you can select as well as a variety of props. You can look at the wattage and current that is being consumed. A watt meter ($60) is a good tool to have to fine tune the prop and motor relationship. It is not necessary but good to have when designing a quadcopter.

When looking at a prop, it is important to make sure that all props are the same. Don’t mix and match props on the same quadcopter. When looking at a prop it has lettering and numbering on one side, a smaller hole and a bigger hole. The bigger hole faces the motor and the smaller hole with lettering is the outer edge of the prop. The numbers on the prop designate the size and pitch. In our case we have two 9×4.5 MR and two 9×4.5 MRP props. This is a 9 inch prop when measured from tip to tip. The 4.5 is the pitch of the prop. This combination designates the lifting power of the motor-prop combination. The P designation is for pusher and the non P designation is for pulling.

If you are designing your own new system a good rule of thumb is that the quadcopter should hover level at half throttle. Many prop manufacturers have charts that show thrust in grams with rotational speed and amps/wattage for different motor-prop combinations. You can hook up a rig with a kitchen scale to measure force as well as current draw when looking at changing the motor and prop selection.

We will be using the Acro Naze32 Flight controller board ($30) for this class. You can get an upgraded board with barometer and compass ($40) integrated to measure elevation and direction. You can hook up a GPS to this system as well to get absolute position and fly waypoints. The PWM channel decoder integrates to the RC Receiver (and transmitter) and translates the controls into PWM outputs that go to the speed controller for the motors. The Naze32 is designed to work with six motors but we will be using four in the class.

Naze32

 The first step in assembly is to prepare connectors for the batteries. We will be using the XT60 connector ($6 for five pairs) to bridge between the battery and controller. We use heat shrink tubing on the connector to keep from shorting while we are soldering. The resultant female side should look like the photo below.

 xt60-2 xt60-1

Make sure that you put the red into the “+” connector and the black into “-” to ensure polarity.

 The next step is to cut the old connector from the battery and put the XT60 male connector on the battery. Make sure that you cut one, and only one, side at a time. Cutting both leads will short out the battery and ruin your day as well as the cutters and battery. In the photos below we cut the red wire, soldered the new connector on, and applied the heat shrink tubing. This needs to be done to make sure that the soldering iron does not short out the negative lead while we are attaching the black wire.

 battery-1battery-2battery-3

At this point we have a battery with the XT60 male connector and a wire with an XT60 female connector.

Mounting local drive with guest extensions

In the last entry we created a Linux install by creating a new virtual machine and booting from an iso image. This works but is very time consuming every time we want a playground. In this entry we will clone an existing machines using thin cloning, modify the clone, add guest services extensions, mount the E:\ drive to reading, and stage an installation of the 11g Oracle database.

The first step is to clone our existing machine. We don’t want to create a new one because the first one took almost two hours. If we left click on the oel6u5 example and right click we can select Clone…

Screenshot 2015-07-02 17.36.32

 

We are given the option of a full clone or a linked clone. A full clone takes all of the files that we created (the 40G root disk which is thin provisioned) and makes a new copy of it. The linked clone tracks differences from the old instance and the clone instance. As changes are made to the new instance, they are recorded in a new directory. The old instance is forked and any new changes happen in a new file. The old file preserves a spot in time where the two were the same. Screenshot 2015-07-02 17.36.45

 

The linked clone comes back almost immediately since no files are copied to create the new instance.

Screenshot 2015-07-02 17.36.51

 

What we want to do is mount the E:\ drive as a media folder inside of our guest operating system. To do this we must go to the settings and select shared folders. We Add a shared folder access point and map it to the E:\ drive. We automount it and make it read-write.

Screenshot 2015-07-02 17.36.59 Screenshot 2015-07-02 17.37.10 Screenshot 2015-07-02 17.37.18

 

While we are in the setting we also need to remote the CD/DVD since we are finished installing the operating system and want to boot off our new instance. We do this by selecting Storage, selecting iso file that we mapped, and clicking on the blue icon at the bottom with a minus sign in it. This removes the CD from our mapping and we boot from the hard drive that we used for our installation.

Screenshot 2015-07-02 17.37.51 Screenshot 2015-07-02 17.40.30 Screenshot 2015-07-02 17.40.33

Once we reboot, we log in as the user oracle and add the guest services extensions. This is done by going to the top menu bar in the VirtualBox window and selecting Insert Guest Additions CD image from the Devices menu. This mounts the CD and asks you if you want auto-run the content.

Screenshot 2015-07-02 17.41.00 Screenshot 2015-07-02 17.41.50 Screenshot 2015-07-02 17.42.05 Screenshot 2015-07-02 17.42.15 Screenshot 2015-07-02 17.42.23 Screenshot 2015-07-02 17.43.13

Note that kernel modifications were made to map the local drive to a mounted resource. We can eject the guest services CD and verify that the file system is mounted.

Screenshot 2015-07-02 17.43.27 Screenshot 2015-07-02 17.43.49

It is important to note that the /media/sf_E_DRIVE is readable only by root. We can copy data from this location to a local location as is needed for database installation or just access the data as root.

Screenshot 2015-07-02 17.44.16 Screenshot 2015-07-02 17.45.58

Before we install the 11g database we will want to change the hostname of this machine. We will keep the ip address the same but change the hostname by editing the /etc/hosts and /etc/sysconfig/network files. We will also need to change ownership of the staging directory back to oracle with the chmod -R command to make it owned by oracle for the installation.

Screenshot 2015-07-02 17.49.42 Screenshot 2015-07-02 17.50.13 Screenshot 2015-07-02 17.51.12 Screenshot 2015-07-02 17.52.13

In this example we change the hostname from oel6u5ex to db11g since we are staging to install the 11g instance of the database. We could have changed it to db12c if we were going to stage the 12c instance of the database. The process and procedure is the same with the exception of the hostnames and which database binaries we put into the staging area.

up next: installing the 11g database into our sandbox

Installing OEL6U6

In our previous post we downloaded VirtualBox, downloaded V41362-01.iso, and configured a single core, 4G of RAM, 40G of hard drive system with two network interfaces. We mounted the Oracle Enterprise Linux Release 6 Update 5 as a virtual CD-ROM once it finished downloading from edelivery.oracle.com. We stored on our E:\iso directory on our sandbox system to use again if needed. We created the virtual disk in the E:\VirtualBox VMs directory and are ready to boot the operating system to start the installation process.

To be honest, I reverted back to OEL6U5 because I had trouble getting the OEM6U6 to install and configure properly. I went with something that I know works and the features/differences between update 5 and update 6 are not that significant when it comes to the Oracle database.

To start the installation process we select an iso image by clicking on Storage and selecting the CD/DVD iso that we are going to boot from. In this case we select the V41362-01.iso file from our E:\iso directory and click on the green Start button at the top left.

Screenshot 2015-07-02 16.04.47Screenshot 2015-07-02 16.06.27 Screenshot 2015-07-02 16.04.25  Screenshot 2015-07-02 16.06.44

 

Once we click on start it takes us to the boot menu for the operating system. We select install and follow the menu prompts.

Screenshot 2015-07-02 16.06.58Screenshot 2015-07-02 16.07.26Screenshot 2015-07-02 16.07.31Screenshot 2015-07-02 15.33.28

Screenshot 2015-07-02 16.07.54 Screenshot 2015-07-02 16.07.59 Screenshot 2015-07-02 16.08.03 Screenshot 2015-07-02 16.08.08 Screenshot 2015-07-02 16.08.27

Configure the network so that eth0 has a static ip address of 192.168.1.121, netmask 255.255.255.0, and default router is 192.168.1.254 (this is my Uverse router). The default dns is 8.8.8.8 with the backup being 8.8.4.4.

Screenshot 2015-07-02 16.08.36 Screenshot 2015-07-02 16.08.44 Screenshot 2015-07-02 16.09.17 Screenshot 2015-07-02 16.09.31 Screenshot 2015-07-02 16.09.45 Screenshot 2015-07-02 16.09.55

 

after setting the timezone and root password, choose to overwrite all data on the existing disks and select a software development platform to install. The software development platform is selected to give us a compiler as well as a user interface. If you select the basic server you do not get a user interface.

Screenshot 2015-07-02 16.10.07

Screenshot 2015-07-02 16.10.17 Screenshot 2015-07-02 16.10.24

Screenshot 2015-07-02 16.10.31 Screenshot 2015-07-02 16.10.39 Screenshot 2015-07-02 16.10.47 Screenshot 2015-07-02 16.11.12

Once the system comes back you can reboot and finish the installation.

Screenshot 2015-07-02 16.24.26Screenshot 2015-07-02 16.25.33   Screenshot 2015-07-02 16.26.03Screenshot 2015-07-02 16.25.48Screenshot 2015-07-02 16.25.57Screenshot 2015-07-02 16.25.43Screenshot 2015-07-02 16.26.17Screenshot 2015-07-02 16.26.29Screenshot 2015-07-02 16.26.37     Screenshot 2015-07-02 16.26.46

At this point we have a valid system and can login, alter the /etc/hosts table, alter the /etc/sudoers file, and run yum update to download the latest patches.

Screenshot 2015-07-02 16.40.52 Screenshot 2015-07-02 16.41.05Screenshot 2015-07-02 16.41.28  Screenshot 2015-07-02 16.41.53Screenshot 2015-07-02 16.43.09Screenshot 2015-07-02 16.43.42   Screenshot 2015-07-02 16.46.18

The yum update will probably take as long as the installation process took. Overall this takes about an hour or two depending upon your network connection speed and amount of RAM that you allocate.

Screenshot 2015-07-02 17.32.54

We now have a fresh install of Oracle Enterprise Linux 6 Update 5 with the latest patches. I suggest that you clone this instance and put it on long term storage somewhere. We don’t need to spend an hour or two recreating this again.

up next: Mounting the E: drive inside the virtual machine to stage other software installations.

 

Downloading and setting up installing OEL6

In this entry we will go through downloading and installing Oracle Enterprise Linux Release 6 update 6. We are selecting this version over RedHat or Ubuntu or Debian because most of the Oracle documentation talk about how to install and configure on OEL6. We could do this for OEL7U1 or OEL5U?. We just selected OEL6U6 because it is the most recent with the best examples on the web.

Two things to consider when installing guest operating systems on VirtualBox are iso images and image sizes. To make things easier we consolidated software into two directories. The first is an iso directory. This directory is for operating system installations. The second directory is for the binaries like the database or identity servers. It is easier to isolate the two because one is used to jumpstart a new instance. The second directory can be mounted and pulled into an instance to install software. The second are that we need to consider is the directory to hold the virtual images that VirtualBox creates.

For our sandbox machine, we installed a 2T disk to hold iso images, binaries, and virtual images. In our example, this is drive E.

Screenshot 2015-07-02 14.04.00

We have consumed about 500G of a 2T drive

Screenshot 2015-07-02 14.03.47

There are three directories that we created: iso, oracle, and VirtualBox VMs. What we want to do is download the operating system iso files from edelivery.oracle.com and put it in the iso directory as is shown.

Screenshot 2015-07-02 13.59.21

To keep things a little more organized, we use a naming convention to identify the iso file. Oracle creates a file with a filename like V52218-01. This means nothing to me but OEL6U6 x86_64.iso has relavance. Note the file convention that we use contains both. The V(number).iso tells us the version that was downloaded from the edelivery site and the OEL6U6 tells us that this is the Linux Release 6 Update 6 version of the OS. Note that some of the conventions are reversed. For the OEL7 iso we had the V(number) inside the parenthesis and the OEL7 outside. Either works as long as you can tell which is which easily.

To download the iso file, you need to go to edelivery.oracle.com and select the Oracle/Linux VM from the top of the screen. There are three options in the pull down: Main, Oracle/Linux VM, and Oracle 1-click. The Main and Oracle 1-click allows you to download the installation binaries for things like the database or E-Business suite. The Oracle/Linux VM allows you to download OracleVM, Linux, and Solaris binaries. Unfortunately, the license requirements and conditions are different prior to downloading the software. Oracle requires you to select what you are going to download and agree to user and license restrictions.

goto http://edelivery.oracle.com and select Oracle Linux/VM to get to the operating system download.  Screenshot 2015-07-02 13.56.16Screenshot 2015-07-02 13.56.20

 

 

 

 

 

Login with your oracle.com credentials.

 

Screenshot 2015-07-02 13.56.31Screenshot 2015-07-02 13.56.40

 

Accept the license to search for the OS

Screenshot 2015-07-02 13.56.52

 

 

 

 

 

 

 

 

 

Look for Linux on a 64-bit systemScreenshot 2015-07-02 13.56.59

 

 

 

 

 

 

 

The OS downloads will come back in release order. Re-sort by Updated date to look for the latest version. Screenshot 2015-07-02 13.57.12 Screenshot 2015-07-02 13.57.19

Select the Release 6 Update 6 version and download the iso images. Note that there are three. The largest is the DVD image that we typically want to boot from.

Screenshot 2015-07-02 13.57.36  Screenshot 2015-07-02 13.57.53

The download takes a while. Remember that you are downloading a 4G iso image. There is no need to download the source, only the bootable iso image.

Once the images are downloaded we need to configure VirtualBox to read this image and boot from it. To start this, we click on the New icon at the top left of the VirtualBox console.

Screenshot 2015-07-02 14.34.35 We call this instance OEL6 example, select Linux as the OS and Oracle 64-bit as the version.  Screenshot 2015-07-02 14.34.50

 

 

We change the memory for this instance to 4G. We can get by with much less but if we are using this for a database, 4G is the minimum recommended.

We create a 40G drive as a virtual, dynamically created drive. Note that we could create this as a VMDK file which makes it compatible with VMWare. In our example we use the VDI since is compatible with OracleVM. Either should work.

Screenshot 2015-07-02 14.34.55 Screenshot 2015-07-02 14.34.59 Screenshot 2015-07-02 14.35.03 Screenshot 2015-07-02 14.35.23

 

We now have a virtual container that we can boot an iso image into. We do need to modify the network as well as mount the iso image as a CD-ROM for booting.

Screenshot 2015-07-02 14.36.58

To map the iso image, we click on the storage and map the iso image as a CD-ROM. Click on the Circle on the right with a Plus sign on it. This pops up the add new CD/DVD question and file selector when we click on Choose disk.

Screenshot 2015-07-02 14.43.17 Screenshot 2015-07-02 14.43.22 Screenshot 2015-07-02 14.43.30 Screenshot 2015-07-02 14.43.35

 

Next we configure the network to have a bridged interface on adapter 1 as well as a host only network interface on adapter 2. This should give us an eth0 as a bridged network and eth1 as a host only interface.

Screenshot 2015-07-02 14.43.45 Screenshot 2015-07-02 14.43.54

From here we click on Start at the top left of the VirtualBox console which gets us into installing the operating system.

Up next: Installing OEL6U6