Category Archives: Guides

A Cross-Compiler for Your Raspberry Pi

Your pet dog knows it has to “Fetch” the Frisbee you throw out and to “Sit” when you command it to do so. The dog knows this since it has been trained to learn some commands. As its association with you grows, so does its vocabulary. As the dog is an intelligent creature, it sometimes chooses to ignore your commands, depending on its mood.

Fortunately, the Raspberry Pi or RBPi does not have moods to ignore your commands. Not possessing any intelligence of its own, it faithfully obeys (or tries to) what you throw at it. As a processor, your RBPi can understand only machine level language or MLL made up of two logic states ‘0’ and ‘1’, whereas you usually send it commands in C, BASIC, Python or similar high level languages or HLL.

Linux, the Operating System used in your RBPi has a compiler that translates your HLL codes into the MLL understood by the processor. As not all processors are the same, you must inform the compiler as to what processor it should translate the code for. Therefore, when you write code for your RBPi, the compiler creates a binary file, which consists of the machine code suitable for the processor in your RBPi board.

When you write your program code in HLL, there may be unknown errors called bugs that prevent the program from running smoothly on your RBPi. You have to spend time in debugging your program until the desired result is obtained. Most of the time, the bugs are not obvious and you are not sure why the program crashed or did not operate.

The amount of memory available in the Raspberry Pi and its CPU capabilities are limited. Therefore, when you have to debug and compile a long program, these limitations become a bottleneck. Debugging and compiling a lengthy program on a desktop or a laptop PC running Linux, is far faster than trying to compile it on an RBPi. The only problem is it will not be compiled for the RBPi processor, but rather for the processor within the PC.

The way out is to use a cross-compiler. This will run on the PC platform, but will generate the code necessary for the processor used in the Raspberry Pi. Using crosstool-ng is the simplest way to build a cross-compiler. A set of scripts is used to bring up a menuconfig type of interface allowing you to select your compiler settings. With the necessary inputs, the crosstool-ng downloads what else it needs, patches itself, configures itself, builds the cross-compiler and installs it for you. How to create the cross-compiler is detailed here.

Crosstools are notorious for the large amount of space they take up on the hard disk. This is due to the many files downloaded and intermediary build results necessary to be created when building up the crosstool. Be prepared with a 4-5GB amount of empty space on your HDD, as creating the crosstool-ng cross-compiler will take up at least 3.5GB. The Linaro C-compiler works well for the Raspberry Pi, although this is an experimental version.

How does a Fan Regulator Work?

A fan regulator is a crucial component that serves to increase or decrease the speed of your fan according to your needs. You have a choice between conventional and electronic regulators. The technology along with the circuitry that controls the fan speed is quite complex.

Conventional Regulators

Older versions of conventional regulators were quite bulky to look at. A square box jutting out of a board with a circular knob or toggle switch did not make for very sleek appearance. The box contained the circuit elements of the regulator system. You had to adjust the knob to set the fan at the desired speed. Modern day conventional regulators present just a toggle on a board that incorporates the switches for the other electrical devices for the room. You do not get to see the regulating unit concealed in the wall behind the board.

To understand how a regulator works, you must know something about resistances. Any electrical conductor allows current to pass through it. The conductor however, offers a certain amount of resistance to the passage of current. The resistance depends upon the material of the conductor.

The regulator has spools of wire with different amounts of resistances. When you set the knob at a particular position, you include a certain resistance in series with the fan. A series connection implies the resistance is in line with the fan. This reduces the voltage drop across the fan and its speed to your desired level. The greater the resistance, higher is the voltage drop across it and that lowers the speed of the fan.

Considerations

These regulators are available at a reasonable cost. The difficulty in using them is that the heat generated in the resistance causes wastage of power. Hence, you reduce the speed of the fan at a considerable cost. In fact, you incur a significant loss in power, when you set the regulator for a very low fan speed.

Capacitor Regulators

You can overcome this problem by using capacitor regulators. This type of regulator helps you to save power at all speeds of the fan. The regulating unit is visible as a much smaller knob, compared to those of conventional resistors. You can change the resistance by rotating the knob.

The idea behind a capacitor regulator remains the same, which is to adjust the voltage across the motor of the fan. Now, when you increase the capacitance, the voltage across the capacitor decreases but that across the fan motor increases. Accordingly, the speed of the fan increases. In other words, you need to increase the capacitor value to increase the fan speed. However, since there is no power loss in the capacitors, there is no heat generated, and consequently, no extra expense.

Benefits of Capacitor Resistors

Capacitor resistors present many obvious benefits. They are smaller, lighter and less clumsy to look at than their conventional counterparts are. In addition, these units provide linear control of speed. Since they are energy efficient, they help you to save on your power consumption. Compared to electronic speed controllers, there is no distracting humming sound when the fan is on. Additionally, you can expect to get a reliable performance especially as compared to the electronic regulators.

Why Are Industrial Sensors Going Wireless?

Industries are increasingly opting for low-power wireless photoelectric sensors with extended range of signals that carry for miles. Such improvements have been made possible with the proliferation of low-power micro-controllers that have boosted the range of the sensors and enhanced their battery life.

In general, wireless sensors conserve and extend battery life by switching themselves off when they are not taking measurements. This allows the sensor to spend most of its time not consuming any power. With this simple technique itself, the battery life of the sensor is boosted by a factor of 100 or more in comparison to that of a continuously powered sensor. However, as the sensor does not sense when it is off, the response time suffers.

To understand how much the battery life can be extended, consider a dry contact wireless sensor that typically dissipates about 100 to 200 µW of power. Such a sensor operates on two AA batteries, which last for five years with the dry contact wireless sensor sampling at 10 times or more every second. In comparison, a powered sensor system can remain on continuously and can respond more quickly. It is also possible to run them at higher power levels to produce a longer wireless range.

To provide reliable and interference-free communication, FHSS or Frequency-Hopping Spread Spectrum techniques are used in industrial wireless sensors. Basically, FHSS switches a carrier rapidly among several possible frequencies, using a pseudorandom sequence. When bound or paired devices communicate with each other, data and control packets are interchanged using these frequency channels randomly, but in a pattern known only to the communicating pair.

Typically, the bandwidth necessary for frequency hopping is much larger than that required for transmitting the same information on just one carrier frequency. However, the transmission takes place only on a small portion of the bandwidth at any given time. Since the effective bandwidth of any interfering signal is the same as that for a narrow carrier, frequency hopping greatly diminishes interference from narrowband sources. Usually, a site survey is conducted before installation of wireless sensors to determine if there is RF interference and whether this is strong enough to be a problem.

Modern wireless sensor systems have a radio master device or gateway that polls all its sensor nodes at specific intervals to ascertain radio communications are still operating. If there is no response from one of the sensors, the system reacts deterministically; the system enters a state to maintain control in a fail-safe way.

The radio master connects to multiple sensors allowing many dozens of wireless sensor nodes to work within a single radio network. Using a TDMA or Time-Division Multiple-Access technique, ensures that all the sensors in the network have adequate time to transmit their data and receive their individual instructions. This effectively eliminates the possibility of multiple sensors trying to communicate simultaneously.

One of the major advantages of using wireless sensors and indicator lights is the elimination of complex cable installation. Rearrangement can easily be done if the plant layout changes. The modern wireless sensor with its own battery, radio and sensor in a single housing, allows higher productivity with real-life status of the production line.

Where Do You Use a Touchless Rotary Sensor?

Most touchless rotary sensors use a magnetic position marker for sensing position. The position marker is attached to the rotating part of the application. It also uses a sensor to measure the angle of the marker. The touch-less rotary sensor uses a magnetism-based technique and does not require physical contact between the marker and sensor. Although other noncontact magnetism-based sensors overcome the limitations of potentiometric sensors that use resistance-based track-and-wiper techniques, they still need a shaft to be attached to the housing of the sensor.

Touchless rotary sensors are the most suitable technology when you have:
• An application that requires measurements through a nonmagnetic plate or wall;
• An application working in extreme environments that necessitate the sensor shaft to be sealed;
• An application where the drive shaft vibrates or has a lot of play;
• An application that necessitates very low friction-torque requirements;
• An application where misalignment can be problematic.

Touchless sensors offer many advantages over conventional sensors. They have lower operating costs, are rugged, reliable, programmable and simple. Although the initial cost does seem higher than the alternatives, it is not always so. The alternatives often require expensive subcomponents such as ball bearings and or expensive precision shaft couplings.

Since the working core of a touch-less rotary sensor is always sealed from the environment, the sensor parts experience no mechanical wear. Although the magnet is exposed, it can be potted with ingress resistant compounds, especially when it is exposed to fluids. The sensor life is usually measured in MTTF or Mean Time To Failure.

There are two types of touch-less rotary sensors, customer programmable and preprogrammed, making it simple for the user. Where safety and is paramount, preprogrammed and pre-calibrated sensors can be used and their functionality cannot be altered. These are also less expensive as the sensors do not require any look-up table for calibration with microprocessors. Where precision and expanded functions are required for quick calibration of star and end angles, customer programmable touch-less sensors may be used.

To operate properly, both the sensor and the position marker attached to the rotating component of the machine must be appropriately sized and positioned. The magnet position markers come in several body styles. You can either screw them into the rotating component or clamp them onto the rotating shaft. The working distance between the sensor and the magnet is important and dictates the best magnet size. For example, if have a shaft with an axial offset in the X-Y direction, you will need a bigger magnet to compensate for the non-linearity and the drop in the axial tolerance band.

You can mount the sensor unit of the touchless rotary sensor system in the traditional servo-type mounts or in the two to four screw mount. The body of the sensor usually has mounting holes and slots and comes with screws for the mounting. This allows the sensor to be rotated and placed in an optimal mounting position before being secured.

Touch-less sensors typically measure rotary movements from 0-360 degrees with repeatability from 0.1-0.12 degrees. The resolution is typically from 10-14 bits. Most of the sensor units are rated to IP69.

How do photovoltaic cells work?

Your calculator probably has a darkish colored panel just above the display. The panel is made up of solar cells that power up your calculator if there is enough light. You may also have seen some solar panels, which people use for charging up their cell phones. Earlier, these solar cells or photovoltaic cells were exclusively used to power the electrical systems of satellites. However, they are now commonly used in less exotic ways as well.

How do photovoltaic cells convert light to electricity? For this, you must understand the way these cells are constructed. A photovoltaic cell has two silicon plates bonded together. Pure silicon is an insulating material and is unable to conduct electricity. This is because of the atomic structure of silicon, which has place for eight electrons in the outermost shell of its atoms. However, there are only four electrons present.

Therefore, when silicon atoms come together, they share their electrons. Each atom shares one electron with its neighbor and they become a pair. That means at any time, four atoms surround each silicon atom, bringing up its catch of electrons to eight on the outer shell. Since all the electrons are now bound up, there is none left free to move about and carry electric charge.

To make the silicon plates able to carry electric charge, one of the two plates must have some free electrons and the other plate must have some holes or lack of electrons. This is done by the process of doping. While making the plates, one of them is given a few phosphorus atoms as impurities. Since phosphorus has five atoms in the outermost shell of its atom, when combining with the silicon atoms, one of its electrons remains unpaired. This makes the silicon plate with the phosphorus impurity have excess electrons and this is called the n-type silicon.

Likewise, the other plate is doped with boron, which has only three electrons in the outermost shell of its atoms. This leaves the combination of silicon and boron atoms with a deficit of electrons and this is called the p-type silicon. This is like a hole, which will readily grab a wandering electron to fill up its vacant space.

Light is essentially a barrage of energetic particles called photons. Photons impart their energy to the surface where they land, which is why you feel warm when you stand in sunlight. If light or photons are allowed to fall on the n-type silicon plate that has extra electrons, they receive the excess energy from the photons. The extra energy allows them to dislodge themselves from their original positions and wander off until they come to the other plate with the holes, where they are eagerly absorbed.

However, the n-type silicon plate that supplied the electrons now has a deficiency of electrons that it must fill up. For electrons to flow, the circuit must be externally completed. This is usually done by connecting a load to the solar cell through external wires. The plate makes up its deficiency of electrons by borrowing them from the connecting wire. In essence, photons drive the electrons through the entire circuit, and that makes the current flow through the solar cell and the load connected to it.

As soon as light falling on the solar cell is removed, the running electrons lose their drive, and the flow of current stops. Although the output from each cell is usually very tiny, by combining them in series and parallel, an impressive amount of power can be generated.

Transistors: What Is The Difference Between BJT, FET And MOSFET?

BJTs, FETs and MOSFETs are all active semiconductor devices, also known as transistors. BJT is the acronym for Bipolar Junction Transistor, FET stands for Field Effect Transistor and MOSFET is Metal Oxide Semiconductor Field Effect Transistor. All three have several subtypes, and unlike passive semiconductor devices such as diodes, active semiconductor devices allow a greater degree of control over their functioning.

Depending on their subtypes, operating frequency, current, voltage and power ratings, all the three types of transistors come in a large variety of packages, and all of them are susceptible to ESD or Electro Static Discharge. That means when you handle these devices, you must take adequate precaution against static charges destroying them.

he basic construction of a BJT is two PN junctions producing three terminals. Depending on the type of junctions, the BJT can be a PNP type or an NPN type. The three terminals are identified as the Emitter or E, the Base or B and the Collector or C. BJTs usually function as current controlling switches. The three terminals can be connected in three types of connections within an electronic circuit – Common Base configuration, Common Emitter configuration and Common Collector configurations. All the three connections have their own functions, merits and demerits. The BJT is Bipolar because the transistor operates with both types of charge carriers, Holes and Electrons.

The FET construction does not have a PN junction in its main current carrying path, which can be made from an N-type or a P-type semiconductor material with high resistivity. A PN junction is formed on the main current carrying path, also called the channel, and this can be made of either a P-type or an N-type material. The three leads of a FET are the Source (S), Drain (D) and Gate (G), with Source and Drain forming the ends of the channel and the Gate controlling the channel conductivity. Unlike the BJT, the FET is a unipolar device since it functions with the conduction of electrons alone for the N-channel type or on holes alone for a P-channel type.

The input impedance at the gate of an FET is very high, unlike the BJT, which comparatively has much lower impedance. Additionally, the conductivity of the channel depends on the voltage applied to the Gate, essentially making it a voltage-controlled device, unlike the BJT, which is current-controlled. The voltage applied to the Gate controls the width of the channel, allowing the FET to carry current between the Drain and Source pins. The Gate voltage that cuts off the current flow between Drain and Source is called the pinch off voltage and is an important parameter.

The MOSFET is a special type of FET whose Gate is insulated from the main current carrying channel. It is also called the IGFET or the Insulated Gate Field Effect Transistor. A very thin layer of silicon dioxide or similar separates the Gate electrode and this can be thought of as a capacitor. The insulation makes the input impedance of the MOSFET even higher than that of a FET. The working of the MOSFET is very similar to the FET.

You can read more about transistors in depth here.

Automate Your Home HVAC System from the Internet Using the Raspberry Pi

The HVAC devices in your home, typically the air-conditioner, thermostats, heating and ventilation, use one or more remote handheld devices working on Infrared (IR) technology. As the HVAC devices are from different manufacturers, you will most likely own a multitude of remote devices, making it difficult to handle and set each of them independently.

However, with the Raspberry Pi or RBPi, a small board called the IR Remote Shield and a wireless interface, you can control all the HVAC devices and that too from the Internet. Imagine setting up the environment in your home just as you are leaving office, so that you have a cozy atmosphere to relax at home.

There are two steps in this project. The first step involves teaching the Raspberry Pi and IR Remote Shield combination the codes that the remote handheld devices utilize to control the various functions of each of the HVAC devices. The second step is to connect the RBPi to the Internet through any one of the wireless interfaces such as Wi-Fi, 3G, GPRS, Bluetooth, and ZigBee or 802.15.4. These interfaces are available from Cooking Hacks, and you can choose one.

After you connect your RBPi to the Internet and feed in the IR codes used by your HVAC components, you can use a webserver, a laptop or even your Smartphone to control all your home HVAC appliances from anywhere in the world. But, a few words about Infrared technology first.

Started in 1993, IrDA or Infrared Data Association is the technology popularly used for controlling devices such as air-conditioners, TVs, radios, audio systems and many others. It is based on light rays in the infrared spectrum and invisible to the human eye. Using infrared transmitters and receivers, communication between two devices can be established in direct line of vision. The infra-red transmitters use special types of Light Emitting Diodes and the receiver uses a photocell sensitive only to the infra-red light.

Infra-red communication or control uses serial data transfer by emitting pulses of light, which is coded in binary, a language micro-processors are capable of deciphering. Therefore, for deciphering the binary code protocol that the remote is sending, you must hold the remote in front of the receiver on the IR Remote Shield mounted on your Raspberry Pi.

To decode and copy an IR code, press the “Receive” button on the IR Remote Shield. This will allow RBPi to capture the code the remote button is sending. In the software, you will have to tag each code with its individual function, for example, a certain code may be for raising the temperature and another for lowering it.

Once all codes from all the remotes are in the RBPi, it is a simple matter to map the codes and their functions on a web application. As the RBPi is connected to the Internet, any browser on the Internet can call up the web application, and the specific settings for the HVAC units altered. This allows the software program running on the RBPi to send the altered binary code to the specific HVAC unit via its IR link and change its status.

How do battery powered pico-projectors work?

Once upon a time, very long ago, the projector world was ruled by the intense light of arcs. As they were rather unwieldy, xenon lamps took their place. With the unrelenting march of innovation, the era of OHPs or overhead projectors that could project images of transparencies, came into existence. These soon became obsolete as computers evolved and could be directly connected to projectors with LCD screens. The latest in line is the Pico-projector, which uses tiny batteries and the light from LEDs to project large displays.

Although Pico-projectors are small – as small as mobile phones, and sometimes even smaller – they can project large displays, sometimes up to 100 inches. Even though their brightness and resolution is not up to the mark of their bigger brethren, Pico-projectors are relatively new in the innovation chain, and as the market expands, they are expected to develop further.

Several companies have developed their own methods of producing battery-powered Pico-projectors. Of them, the three major technologies are DLP or Digital Light Processing, LCoS or Liquid Crystal on Silicon and LBS or Light Beam Steering. DLP and LCoS use a white light source and a system of filtering techniques to create different color and brightness of each pixel. On the other hand, LBS uses a small liquid crystal display to control the amount of light going to each pixel.

Digital Light Processing or DLP is pioneered by Texas Instruments (TI). Their idea is to use tiny mirrors on a chip to direct the light. Each mirror controls how much light goes onto each pixel of the display. The mirror can be turned on or turned off on command many times a second, and the on to off time ratio defines the brightness of the pixel. For color, there is a color wheel in front of the light source, splitting the beam into red, green and blue. Each mirror controls all the three light beams.

Liquid Crystal on Silicon or LCoS, as the name suggests, uses an LCD to control the amount of light reaching the pixel of the display. For color, two techniques are used. One is the Color Filter where three sub pixels are used, and they each have their own color, Red, Green and Blue. The other is the FSC or Field Sequential Color that requires a fast LCD and a color filter to split the image into RGB, the three main colors sequentially. The LCD is refreshed three times, once for each color. For LCoS, the light source could be an LED or a diffused Laser.

Laser Beam Steering or LBS creates the image one pixel at a time. The technique uses three directed laser beams, red, green and blue. The three beams are combined using optics and are guided using mirrors. So that the eye does not notice the pixel-by-pixel design, the image is scanned at over 60Hz.

LBS has some advantages over the other two techniques. The size is small and power consumption lowest, as the darker pixels require less energy, while the black pixel does not require any energy at all. The image from an LBS system is always focused, even on curved surfaces. On the other hand, lasers are expensive, cause random intensity patterns and are a concern for eye safety.

Brewing beer with Raspberry Pi

Ever since man first tasted naturally made beer, there has been no looking back. Not only man, animals also find beer irresistible. Beer brewers have always been looking for improving on the natural method to make beer tastier. Their work has become somewhat simpler and more high-tech with the introduction of Raspberry Pi or RBPi.

By using open source software and ultra-cheap computer hardware such as the RBPi and the Arduino, people are interconnecting all types of existing devices making them interact with each other. An ardent home brewer and Dutch electrical engineering student, Elco Jacobs has turned his refrigerator into a home beer brewing system. He calls it his BrewPi system and plans to sell kits. He has turned over his instructions and source code on-line for free, since he thinks they might be useful to others even if they do not brew beer.

Elco Jacobs has essentially beefed up his refrigerator with sensors, which send their data to an Arduino board. The Arduino adjusts the controls on the refrigerator for temperature and displays the results on an OLED display. The RBPi has a web server loaded and it provides the web-based interface for viewing. A Python script running on the RBPi allows it to communicate with the Arduino.

By using Jacob’s code, anyone can build a web interface to control an Arduino. The code makes it easy to use an Arduino to control an OLED display and present data on it after filtering the sensor data. When Jacob first started brewing beer at home, he was still a university student. He became interested after learning that to start brewing beer would cost him about 60 euros. He quickly learnt that temperature control was the main thing required when brewing to determine the fermentation rate of the beer and subsequently its flavor.

Hefeweizen, the favorite style of beer for Jacob, is particularly sensitive to temperature fluctuations. The taste of this beer alters radically if the heat to the beer buckets was not under finely tuned temperature controls. However, commercial temperature controls being outside the affordability of a university student, Jacobs wanted something cheap that he could control from the web.

That is how he hit upon the combination of the Arduino (for temperature control) and the RBPi for the web interface). Jacob’s goal is to sell a kit, which will require no soldering. The kit will not have the RBPi and the refrigerator.

By controlling the temperature of the fridge that holds the carboy, BrewPi is able to control the temperature of the fermenting beer accurately. Two zones of temperature are controlled separately, the fridge temperature and the beer temperature. This allow the beer temperature to be held far more steady than if a single thermostat were to be used. However, you can set BrewPi to operate in three modes: constant fridge temperature, constant beer temperature or allow it follow a temperature profile for your beer.

Highlights of BrewPi: four outputs for actuators, single wire bus for all sensors, a OneWire distribution board and lots of pluggable terminals.

What Are Inductors and How Do They Work

An inductor or an induction coil is a tightly woven coil of wire. Now, you would not expect an ordinary piece of wire to show any special property on passage of current through it. A coil with several loops or turns however, exhibits a remarkable property when current passes through it. The current through the coil creates a magnetic field in the immediate space surrounding the coil. The field stores electrical energy during the passage of current and for a very short while, even if you cut off the current.

Another amazing fact of an inductor coil is that if you place the coil in a varying magnetic field, a current starts to flow through it. The amount of current depends upon the rate at which you change the field.

Bulb and Coil Experiment

You can make out this amazing property of an inductor coil from a simple experiment. Consider a simple circuit with a battery, bulb and a switch. The bulb glows when you close the switch while it stops glowing the moment you open or release the switch.

If you now include a coil of wire wound around an iron bar across the bulb, the bulb will light up as you close the switch. However, instead of glowing at a constant brightness, the intensity of the light changes from bright to dim. If you now open the switch, the bulb does not turn off immediately as you would expect. Instead, the brightness gradually decreases before turning off completely.

Explaining the Observations

You can attribute this curious behaviour to the inductor coil placed across the bulb. When you close the switch, current flows from the battery through the bulb, causing it to glow. At the same time, current flows through the inductor coil too. This generates a magnetic field in the space surrounding the coil. The magnetic field varies in the short time the current builds up. The changing magnetic field induces a current to flow through the coil. However, according to the rules of electricity, this current is opposite to the original current sent by the battery. Hence, the effective current through the coil increases with time, while decreasing that passing through the bulb. This causes the bulb to reduce its glow from bright to dim.

When you open the switch, the magnetic field falls. During the fall of the field, the induced current causes the voltage across the inductor to rise for a moment. This causes the bulb to brighten up briefly. When the current reduces to zero, the bulb turns off.

Inductance

The physical quantity associated with this property is called inductance. The value of this quantity is measured in Henrys. Inductance depends upon four features, which include the number of turns in the coil, the degree of overlap, area of the cross section of the wire and the material of the core inside the coil.

You can increase the inductance by increasing the number of turns and the cross section area of the coil. You may also increase the value by increasing the degree of overlap i.e. by using a tightly wound coil.

Uses of Inductors

You must have wondered how traffic signalling works. Traffic light sensors make use of inductors, which form filter circuits along with capacitors. Inductors are essential components in electronic circuits and devices like receivers, transmitters, oscillators and voltage regulators, as well.