Monthly Archives: December 2014

How do Electronic Potentiometers work?

Nowadays, most electronic gadgets change their settings such as volume, bass, treble, brightness, contrast, sharpness etc., through “up/down” or “+/-” buttons in contrast to the rotary mechanical controls earlier. These are the electronic or digital potentiometers in action.

While the principle of operation remains the same whether it is a mechanical or an electronic potentiometer, the functionality of the two is quite different. While the mechanical potentiometer offers a continuous variation because it is an analog device, the electronic version is a digital type, offering discrete variations. The difference is due to the way the voltage dividing functionality is implemented in the two versions. As opposed to a single resistance in a mechanical potentiometer, the electronic version has several resistors, also called the resistor ladder network, switched into the circuit with multiple switches.

The voltage at the center terminal of the electronic potentiometer, therefore, depends on the resistance presently connected to the circuit with one of the switches. At first glance, it would seem to be a simple matter to increase the number of resistors and switches to reduce the granularity. However, electronic or digital switching requires each switch to have a unique digital address, usually in the binary format, defined by bits (0 or 1). Higher number of switches means larger number of bits, which increases the complexity of the electronic circuit controlling the switches. The switches, instead of being individual mechanical types, are usually semiconductor types and are integrated into a circuit along with their controller and the resistor ladder network.

This results in a neat little package, which can be soldered in-circuit and requires no panel or knob for its control. Usually, the control is via a micro-controller, which reads the increase or decrease instruction from the UP/DOWN buttons on the remote. It then generates a suitable binary word and sends it to the specific electronic potentiometer chip controlling the volume or any other function you want to change. Depending on the binary word, a specific switch turns on, connecting the required resistance to the central terminal of the potentiometer.

Just like their analog counterpart, electronic or digital potentiometers are also available in a variety of tapers such as linear, log, reverse-log, etc. Taper defines how the wiper voltage changes as it is moved from one end of the potentiometer to the other. For a linear taper potentiometer, both analog and digital, the wiper voltage bears a linear relationship to its physical position. For a potentiometer following the logarithmic or the reverse logarithmic taper law, the wiper voltage is nonlinear.

Since an electronic potentiometer is implemented in a chip, manufacturers adopt different ways of achieving the same results. While resistor ladder network is the most popular, the ladder implementation itself may differ for achieving the desired taper. Some manufacturers use operational amplifiers as buffers before or after the network, some use an anti-thump circuit to reduce the plop noise that is heard when one switch opens and another closes.

One major difference between the analog and the digital versions of potentiometers is the power handling capacity. Typically, the digital versions, in chip form, are unable to handle more than a few mill watts. In comparison, analog potentiometers capable of handling a few watts are quite common.

How Do Mechanical Potentiometers Work?

Electronic gadgets of about one generation back (prior to the prolific use of SMD), used rotary mechanical potentiometers for setting different parameters such as volume, tone, brightness, contrast, etc. For adjusting circuit parameters within the gadget, a smaller variation called the trim pot was a common sight. These are outdated now, but those who still own and use these gadgets often wonder how mechanical potentiometers function.

The most common example of a mechanical potentiometer is the rotary volume (also tone, bass, midrange and treble) control in an audio amplifier. Unless your amplifier has a remote control, chances are that for increasing or decreasing the loudness, you turn a knob labeled as “Volume” control. When you want to reduce the sound output from the speakers, you rotate the knob counterclockwise. The sound output increasing when the knob is turned clockwise. On the remote control, the knob is replaced by two buttons, one marked “+” for increasing and another marked “–“ for decreasing the sound output. Another example is the fan speed control, used mostly prior to the electronic versions.

Therefore, a mechanical potentiometer is a device to control a gadget’s complete range of operation. In its most common use, a potentiometer acts as a voltage divider. This three terminal device has a central pin that allows the resistance to be varied. This is called the wiper – named for the way it makes the mechanical connection to the fixed resistor between the other two terminals. If you connect the wiper electrically to any one of the other terminals, you transform it into a variable resistor or rheostat.

That the device acts like a voltage divider is easily verified from the schematic. If the voltage across the fixed resistor is the difference of voltages Va and Vb, the wiper will show a voltage Vw anywhere between Va and Vb depending on its position. Mathematically, (Va ~ Vb) = (Va~Vw) + (Vw-Vb). The device serves to cancel out tolerances of other components, when used in-circuit as a trim pot; thus allowing the required voltage setting to be achieved.

In construction, a mechanical potentiometer has a fixed resistor in the form of a circular track, stopping just short of a full circle (usually about 270-degrees). The track is printed on a ceramic or a glass-fiber base. The two ends of the resistance form terminals that may either be PCB solderable or suitable for wire termination. Depending on the requirement, the resistance may be of any value between a few ohms to several hundreds of ohms. The entire arrangement is encased in a housing, which also serves to accommodate the wiper assembly.

The wiper assembly consists of a phosphor-bronze spring that lightly bridges the surface of the resistance track and a circular metal track that forms the third terminal. The spring and track arrangement is attached to a metal shaft, but electrically isolated from it. The spring turns as you rotate the shaft, allowing the wiper to change its voltage.

The trim pot has a similar arrangement, lacking only the metal shaft for rotating the wiper. Instead, the phosphor-bronze spring doubles as the shaft, suitable for adjustment with a trimmer screwdriver. Potentiometers may also be of multiple turns to increase their resolution.

Turtle Graphics on the Raspberry Pi

In 1966, Seymour Papert and Wally Feurzig developed the Logo Programming Language. As a part of this, Turtle Graphics was a very simple way of teaching programming to children. It consisted of a robotic turtle starting at coordinates 0, 0 in the X-Y plane on a computer screen. With a command turtle.forward(20), the turtle would move forward by 20 pixels in the direction it was facing, drawing a line as it moved. To turn the turtle where it is standing, a command turtle.right(30) would make it rotate 30-degrees clockwise. By combining the two commands and a few others, drawing intricate pictures and shapes on the screen was possible.

Now, the Python standard distribution contains a module “turtle” that allows extending the re-implementation of Turtle Graphics. You can run this on your tiny credit card sized inexpensive single board computer, the Raspberry Pi or RBPi. The Python module tries to keep the same merits as available with Turtle Graphics and is nearly fully compatible with it. That means the learning programmer can use the same commands, classes and methods interactively, when using the module.

For example, if you want to find out where your turtle is at present, you can query it with turtle.postion(), and the turtle will respond with its current X & Y coordinates. Now you can command it to move forward or backward, turn right or left and even check its orientation. For a complete list of the turtle commands, look up module-turtle. Apart from moving in straight lines, you can command the turtle to move in a circle of a given radius.

The Python module turtle is a versatile program. Various commands make the turtle do different things. For example, you may want the turtle to move but without drawing any line. Another command can make the turtle leave a stamped mark at its current position. Yet another command can make the turtle invisible, and another can make it draw lines in the color you specify.

Since RBPi is for children who are starting to learn computer programming, the combination of Turtle Graphics and RBPi is a powerful way of teaching them the basics of robotics. The language used by the module turtle is very similar to every-day English, which makes it very easy for children to learn and use.

Children find it difficult to grasp the abstractions on which traditional Euclidean geometry is built. For example, how do you have a point without size or a line that has a length but no thickness? Young people find all this difficult to grasp. However, the turtle being a real concrete object can be seen and manipulated. Turtle geometry being body syntonic, is easily understood since the turtle moves about just as everybody does. That makes it easy to identify with and its actions are well understood by kids.
Seymour Papert has explained the rationale behind turtle geometry in his book Mindstorms.

Another very simple way of learning turtle graphics on the RBPi is through Kids Ruby. Overall, with Turtle Graphics you can teach absolute beginners the concept of storing algorithms and running them so that the computer will simply obey the given commands.

What’s the difference between SD vs SDHC cards?

We use several types of digital devices, which store data on external memory cards. Unfortunately, just as there is a large variety of digital devices, there is a plethora of memory cards to add to the confusion. People juggle with SDHC, SDXC, SD, MiniSD and MicroSD among the most popular cards. Often it is puzzling to ascertain what type of memory card will suit your camera, phone, MP3 player, tablet or other mobile digital device. Most memory cards are flash type with difference in formats, sizes and speeds.

SD vs SDHC:

Apart from Apple products, most digital devices offer means of adding to the internal storage capacity. Typically, this is some variety of the Secure Digital or SD memory card. Although SD has emerged as the most popular flash memory format, there are scores of SD cards of all shapes, sized and speeds to choose from – making it somewhat confusing to pick the right one for your device.

With flash memory cards, the primary aspects that need consideration are their physical format, size and speed. Since each of these variables has its own set of classes, you may find anything from 1GB Class 2 MicroSD card to a 16GB UHS-1 SDXC card.

When buying a memory card, consider where you are likely to use it. Chances are that your camera, smartphone and your camcorder use different sizes of card. Although you can start with the smallest physical format and use adapters to make it fit in different gadgets, it is better to use the card size that is intended for the device.

The largest format is the standard SD card measuring 32x24x2.1mm. Most digital cameras use this format, with high-end cameras shifting to CompactFlash cards, which are smaller. These days, the least frequently used card is the MiniSD card, measuring 21.5x20x1.4mm. Almost all cell phones and smartphones nowadays use the MicroSD card, which has dimensions of 15x11x1mm.

Memory cards come in a huge variety of storage capacities. However, the maximum capacity of a standard SD card is limited to 2GB. The most popular MicroSDHC or Micro Secure Digital High Capacity cards are available with capacities between four and 32GB. The Secure Digital Extended Capacity or SDXC can theoretically range from 64GB to 2TB. However, currently, the largest capacity available is only 128GB.

Larger the memory capacity, so much more you can store. However, if you have an older device, chances are that it can use only the larger SD card. The classification SD/SDHC/SDXC applies to devices as well. Therefore, double-check the type of cards your device can handle. SDHC cards will not work in a device that can handle only an SD card.

Flash cards are available in various speeds as well. The speed class ranges from Class 2 (slowest) to Class 10 (fastest). Class 2 is useful for standard-definition video recording. With Class 4 to Class 6, you can record high-definition video. When you are recording HD video or consecutive recording, Class 10 is more suitable.

If your camera or smartphone can shoot HD video or if you are going to shoot many high-resolution photos in quick succession, you should buy the Class 10 card. For occasional snapshots or casual videos, Class 4 to Class 6 cards will do fine. Prices vary between different types of cards – high-speed high-capacity cards are more expensive.

Drive a 16-Channel Servo with the Raspberry Pi

To drive servomotors micro-controllers must have PWM outputs. These are output pins on which the micro-controller will generate pulse outputs with controlled or modulated variable widths. Most embedded micro-controller units have one or more of these outputs. The famous single board computer, the tiny credit card sized Raspberry Pi or RBPi also has one IO pin dedicated for PWM. This is the PWM channel available at the GPIO18 of the RBPi and with this, you can drive a single servo at best. However, if you want the RBPi to drive more than one servo, it will need additional circuitry.

A PWM driver IC such as the PCA9685 can drive 16 servos at a time, but requires commands and data through its I2C interface. Fortunately, the RBPi can also communicate using the I2C protocol, enabling it to control 16 servos via the PCA9685. Adafruit has a very convenient breakout board with the PCA9685 on it and that makes it very convenient to connect to the RBPi. Not only can you drive servos with the PWM outputs, you can use the PWMs for controlling LED lighting as well.

To let RBPi communicate with the I2C protocol, it will require a special OS available from Adafruit. This is the Occidentalis flavor and it has all the libraries required for invoking I2C. However, if you are using the stock Raspbian OS, you must install the python-smbus and the i2c-tools using the “sudo apt-get install” command. To learn more about using I2C, refer Adafruit’s rather informative tutorial.

The two packages will allow you to search for any I2C device connected to the RBPi. The easiest way you can connect the servo breakout board to your RBPi is with the help of the Adafruit Pi Cobbler. Here, VCC is the digital supply for the IC or 3.3V, and V+ is the supply for the servomotors (typically 5V).

The actual chip that drives the servos, the PCA9685, needs 3.3V, and connects to the VCC on the cobbler board. Servos usually require much higher currents to operate. Therefore, they are powered from a separate power supply, typically 5V, and are connected to the V+ on the Cobbler. Note that this 5V is different from the 5V supply for the RBPi. The PWM operation on the servos creates a huge amount of electrical noise, which can cause the 5V supply voltage to fluctuate significantly. RBPi may not be able to tolerate such voltage fluctuations, and this may cause it to crash and lock up.

If you are driving many servos, it will be a good idea to add a capacitor to the driver board. There is a spot already marked for such a capacitor. As a thumb rule, you need a capacitor with a value n x 100uF, where n is the number of servos you are driving. Capacitors are manufactured in standard ratings, and you may have to go for the next higher standard value that you have calculated.

Depending on whether you are using a standard or continuous rotation servo, your python code will vary. For the actual code with which you can control the various parameters of I2C and hence the servo, you may refer to this site: https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi