Category Archives: Guides

What Is the Life Cycle of a Process in Linux?

Processes in Linux follow patterns similar to that of humans. Just like people, processes are born and do carry out regular tasks; taking rest, sleeping in between and finally, being killed or dying. Processes, being the most fundamental aspects in Linux, are necessary to carry out tasks in the system. You create a process by running binary program executable. The binary program executable comes from a piece of code, transitions to a process, while acquiring states during its lifetime and demise.

A process in a computer operating system is an executable program in action. The executable program has machine instructions necessary to carry out a specific task. A corresponding process is born when a program is executed for carrying out a task. A programmer writes a software program using a high-level programming language such as C. This is also called ‘code’ and the programmer compiles it to create an executable program. The compilation process converts the code into a set of machine-level instructions, and it becomes intelligible to the operating system. The compiler for Linux systems is GCC or Gnu C Compiler.

The executable program remains a passive entity, until it is instructed to run or execute by the user. Then it creates a new entity called a process, which is visible by the command ‘ps’. The process is associated with three identifiers – the Process ID or PID, the Parent Process ID or PPID and the Group ID or GID.

In a Linux system, the first process to start is the ‘init’ and it has a PID of 1. All subsequent processes are init’s children, grandchildren and so on. For active process in a Linux system, the command ‘pstree’ will bring up the entire hierarchy, while ‘top’ will show the dynamic view of processes. The Linux kernel uses a scheduler and it controls the execution sequence of all the processes. Linux processes can have one of four states at any given time: running, waiting or sleeping, stopped and zombie.

A process achieves a running state when it is actually executing (running) or waiting for execution in the queue of the scheduler, which means it is ready to run or execute. For this reason, the running state is also known as runnable and is represented by R.

A process is in a waiting or sleeping state if it must wait for an event to occur or some resource-specific operation needs to complete before the process can continue to run. Therefore, depending on the circumstances, the waiting state is further subcategorized into an interruptible or S state and an uninterruptible or D state.

If the scheduler sends a stop signal to a process, the process goes into a stopped state. This might happen, for example, when the process is being debugged or analyzed and this state is represented by T.

When a process has completed its execution, but is waiting to retrieve its exit state, the process is said to be in a zombie state, designated by Z. Once it crosses the zombie state or retrieves its exit status, the process dies or ceases to exist.

Capacitive Proximity Sensing Optimizes Power Use in Gadgets

Tablets and mobile phones run on batteries and have stringent power requirements. These devices benefit from the multitude of ways designers use to optimize their power consumption and enhance their battery life. The usual method is to make applications running on these devices consume as little power as possible. Significant savings ensue if the different processes within these devices go to sleep when the device is not in use, turning on and starting to run only when the user activates them by using the device.

This implies the device has intelligence for detecting the start of its usage and starting the internal processes as required. One of the simplest ways usually followed by designers is to let only the User Interface (UI) run and let all other processes sleep until the UI senses an input from the user. This is usually in the form of a button press or touch, which makes the entire device wake up and start running all the necessary processes.

Advancements in the above method are the intelligence incorporated in the device to detect the approach of the user’s hand. Now, even the UI may be allowed to sleep, keeping awake only the sensor that detects the approach of the hand. Such proximity sensors can detect human hands or any conducting object coming near them without the need of any physical contact.

A device incorporated with such a proximity sensor operates in a low-power mode until the approach of a human hand. In the low-power mode, there is no other activity or process running in the gadget other than that scanning the sensor. Once the proximity sensor detects the human hand approaching, it wakes up the device, which enters an active mode. In this mode, the UI of the device is turned on. Proximity sensors that wake up the device from its low-power mode to an active mode are called wake-on-approach sensors.

Infrared and inductive proximity sensing techniques are commonly used in the industry. However, applications such as laptops, mobile handsets, white goods and home appliances that mostly sport touch panels for their user interface, use capacitive proximity sensing because of their greater reliability and aesthetics. As soon as the user’s hand approaches the interface panel, the proximity sensor wakes up the capacitive device from its low-power mode and it starts to scan all the buttons to detect a touch.

The panel of a modern TV or tablet PC may have buttons that are nearly invisible when the device is in low-power mode. The touch panels in use today have buttons that remain nearly hidden until they are highlighted by backlighting. However, backlighting requires LEDs that gobble up power very fast even when they are of the high-efficiency types. This reduces the battery life of portable devices such as PCs, tablets and mobiles.

Wake-on-approach proximity sensing and its level of control on the device is highly application dependent. Response time and power consumption are the two key parameters governing the optimization required, where response time is optimized by scanning the sensor repeatedly and in quick succession. However, optimization of power consumption requires the scanning to be slow to allow the device more time for sleeping.

Solar Powered FTP Server with a Raspberry Pi

Why would anyone want an FTP server and that too powered by the sun? Well, with an FTP server, you can access all your digital files from anywhere with an internet connection. The sun-powered bit has two advantages, the sun charges those standby batteries and the expense does not show up in your utility bills.

For the project all the parts used are standard items. The Single Board Computer used is the Raspberry Pi (RBPi), a convenient case with all the right slots for the output ports and a small solar panel. Additionally, you will also need a solar charger and a battery box to house the four AAA sized rechargeable NiMH batteries and a micro-USB cable.

A word about the solar panel; you can buy the solar panel from Cottonpickers. The advantage is you get a solar panel with a built-in battery box and a box for the RBPi together. All you have to do is to slide in the RBPi and plug in the batteries. This model has an on/off switch, so you do not have to pull out the cord to switch off. The batteries keep charging even with the switch in the off position.

A blue LED on charger lights up when the sun is charging the batteries. There is also a USB socket, which you can use for charging other USB devices such as mobile phones. Cottonpickers also supplies a USB cable along with the solar panel, so you have almost everything you need for the project.

The solar panel supplies a little more than 300mA, which means that it is perfect for charging 3000mAH NiMH batteries, since they require a C/10 charging rate. The panel has blocking diodes to prevent the batteries from discharging through the cells.

The RBPi model B, with all its keyboard, mouse, TV and networking plugged in and running consumes about 400mA, which the solar panel can easily meet if the sun is shining in its full glory. When the sun goes down, the battery takes over seamlessly. The solar panel can fully charge four AAA cells of 750mAH capacity within three hours. This allows an operation time of more than one and a half hours on the battery.

Charging four AA cells rated at 3000mAH takes the panel about 10 hours to complete. That means if the panel is left in the sun the whole day, the battery will be fully charged for the night. The options you have are:

Powering your RBPi directly from the sun and use the four NiMH cells as a buffer when the sun hides behind clouds. Let the solar panel charge the battery of cells during the day and you can use your RBPi at night.

Next, you will need a static IP address. This is essential, as the address will let your network firewall know it has to allow incoming FTP requests from there. You will also need a vnc-server and load it up as a service every time the RBPi boots up. For the FTP, use the Very Secure FTP Daemon or VSFTPD. Setup all the software as per the instructions found on CNET and you are ready to go. Don’t forget that your RBPi needs a lot of sunshine!

HMI: How to Communicate With Machines

Accelerating quality, quantity, economic efficiencies and environmental protection are leading to an increasingly connected process flow and factory floor. In combination with decreased personnel, that has led to processing of increased amounts of information by fewer and less application-specific operators in the control center. It requires a well-designed HMI or Human Machine Interface system to decrease the gap between the production process and the operator via an intuitive visualization system, layers of detail that allow a bird’s eye view down to the minute details, and includes training material and documentation that the operator has on his fingertips.

A well-designed HMI system provides numerous benefits. Chief among them are increased safety, quantity, quality and economic efficiency. Apart from minimizing the risk of disruption in the production process, HMI systems also reduce the over downtime while allowing fewer operators to manage more information with less field-specific knowledge.

HMI provides a means of monitoring, controlling, managing and/or visualizing device processes. For example, an operator panel may allow the operator of an industrial machine to interact with the machine in a visual, graphical way. The operator can easily control the machine by using the touch screen or external buttons, as all readouts and controls readouts are graphically displayed on the screen.

HMIs can be located on the machine, in the form of simple segmented displays or LCD panels of high-resolution. They can be located in portable handheld devices that are battery operated or in centralized control rooms. Machines and process controls can use them to connect the operator with Programmable Logic Control application systems to control sensors, actuators and machines on the factory floor.

For communicating with industrial machines, the usability of the HMI system depends on the processing power of the system, its ability to render reality-like complex screens, quick responses to user inputs and the flexibility for handling several levels of operator interactions. Usually, effective communication requires the HMI to have dynamically changing graphics. This in turn, requires the system to be a high-performance type that supports various resolutions and displays of high refresh rates. For efficient communication between the operator, numerous machines and control systems, it is imperative that multiple connectivity and protocols must be supported.

Industrial automation thrives on real-time communication. Using industrial micro-controllers along with PRU-ICSS or programmable industrial communication subsystems makes it possible to support various popular, certified serial protocols, including those that are Ethernet-based. The PRU-ICSS allows HMI manufacturers easily support industrial communication protocols of multiple types on a single hardware platform. The most important advantage of this platform is that it does not require the support of external ASICs and FPGAs. This offers huge scaling in performance and the integration offers opportunities of software and design reuse.

Portable HMI solutions use several wireless connectivity solutions such as WLAN, Sub-1GHz, ZigBee and BlueTooth. This broad portfolio offers the maximum flexibility when designing for wireless. For example, the WiLink 8 solution provides high-performance BlueTooth and Wi-Fi in one module. The Sub-1GHz performance line is very popular and the most reliable in its range.

Let Raspberry Pi Read You an Audio Book

People who have grandmothers (and grandfathers) are fortunate. Although most of these old people are healthy and strong despite their advancing years, not all are so lucky and may be impaired in some way, mostly because of their failing eyesight and trouble with arthritic hands. Since they have a physical handicap, they find it difficult to operate a laptop, a DVD player or a tiny MP3 player. A Raspberry Pi (RBPi) with a large play button is actually helpful if it can read back an audio book.

This can be done in two ways. The RBPi player can have a single large button to pause and play, or have no buttons at all and be operated by NFC tags. The tags are best attached to empty CD or DVD cases, on which the details of the Audio book are printed in large letters for easy reading. Simply passing a case over the player will cause the specific audio book to start playing from its last state.

The player saves its state after every two seconds. Therefore, when the listener is bored or otherwise wants to stop listening, he or she can simply disconnect the player from its mains socket. Reconnecting it allows the player to get back to playing from its last saved state.

The RBPi player with a single large button works as a play/pause button when pressed. Going back to the previous track is easy if the listener holds the button pressed for more than four seconds. Copying files into the player is also a simple affair with a thumb drive. The files are copied into the thumb drive under a special volume label. As soon as it is plugged into the RBPi USSB port, the books are copied into the SD card and starts playing when the drive is unplugged.

For the single button RBPi player, apart from the RBPi and its enclosure, you will need a blue LED, some wires, a pair of speakers and of course, the large button. Among the software that you will need are – Raspbian image (Wheezy), mpd, mps, mpd-python, pyudev and a python script.

When the RBPi player is first powered up, it boots, starts the python script and waits with the audio book in pause. Since at a time only one audio book is stored, pressing the button starts the player. If the button is held pressed by more than four seconds, the player goes back one track. The player always remembers its last playing position.

As soon as a USB thumb drive is plugged in, the player stops playing, mounts the thumb drive, deletes the old audio book, copies the new one from the special name/label on the thumb drive and rebuilds the playlist. A flashing blue LED signals the end of file copy. Once the thumb drive is removed, the new audio book starts in pause mode, proceeding to play when the play/pause button is pressed briefly once.

Use of mpd allows the RBPi player to support wave, Musepack, MOD, MP4/AAC, MP3, MP2, OggFLAC, FLAC and Ogg Vorbis file formats.

Using a Raspberry Pi to Hack an Apple Time Capsule

You may have an old Apple Time Capsule lying around, which you may not be using because it has a failing hard drive. These were expensive at the time Apple first introduced them and for many people, a failed power supply or hard drive might have forced them to stop using the device. If you are not familiar with the Time Capsule, it is a backup arrangement for everything on your Mac. Apple coined the name Time Capsule for the hardware and Time Machine for the software. Windows users will not have seen anything like it, and you can read about Time Capsule on Apple’s official link.

You can bring your dead Time Capsule back to life using the low-cost credit card sized single board computer Raspberry Pi (RBPi). Even if you do not have a Time Capsule to modify, you can simply add a Solid State Drive to your RBPi, house the two in a suitable box and make a Pi Capsule for using on your Mac with the Time Machine software. For information, Linux users may backup to the Pi Capsule using any one of the 21 backup software programs listed here.

Backing up over the wireless may be slow, depending on the Wi-Fi speed. However, you can get much faster speeds using the Pi Capsule over wired Ethernet. Of course, the first time you start a backup, the process will take a long time, so try not to interrupt it. Future backups will be faster because they will be only incremental.

You will need a power supply suitable to power up both your RBPi and the Time Capsule (in case the power supply in the Time Capsule has given up the ghost). Connect the SSD hard drive using a SATA to mini-USB cable via a powered USB hub. It is essential to connect only the wireless mouse and the powered USB hub to the RBPi. Anything else you want to connect to the RBPi, such as the keyboard, SSD, wireless card, etc., goes through the powered USB hub.

For the RBPi, you will need an 8GB SD card with the latest “Wheezy” Linux operating system on it. For instructions on how to load Linux on the SD card, see instructions here. Connect a display through the HDMI. When booted the first time, you will be taken to “Raspi-config” automatically, allowing proper setting for the keyboard connected to the RBPi. Now connect the Hard Drive or the SSD to the RBPi using a SATA to mini-USB cable via the USB hub. For getting the RBPi working with the Time Machine on a Mac, follow the guide here.

Pi Capsule has some extended features over the Apple Time Capsule. For one, it can plug into your TV or any other display. Apart from using it only as backup device, the Pi Capsule is actually a full-fledged computer, which you can simultaneously use for web surfing or emailing. If you are not using an Apple Time Capsule and if you have the ability to make cases, build one to house both the hard drive and the RBPi, taking care to leave openings for the RBPi connectors.

What Are NFC Tags And How Do You Use Them?

NFC stands for Near Field Communication. These are small tags, which can be programmed to talk to your phone. As you swipe your phone over an NFC tag, it triggers preset commands you have programmed into it. NFC tags are quite cheap, for example, you can pick up 10 of them on Amazon for about $13.

Here are some examples of using NFC tags –

• Tag No.1: On key chain. A simple trigger to take you to a specific website
• Tag No.2: On the kitchen counter. It triggers several commands – turn Wi-Fi on, turn Bluetooth off, turn Sync on, turn Brightness up and turn Volume up
• Tag No.3: Besides the bed. Turns volume to silent, turns brightness down
• Tag No.4: In the car. While entering the car, turns Wi-Fi off, turns Bluetooth on, opens Audible App, turns Synch off
• Tag No.5: In the car. While leaving the car, turns Bluetooth off, turns Sync on

Therefore, you can program these tags to make your phone do a bunch of things by simply passing it over the top of a tag. You do not need to open an app and individually change each setting; simply passing your phone over a pre-programmed tag will do the trick. To set up your Android phone, go to settings > More > Check off NFC. Unfortunately, Apple does not support NFC, so you cannot use the tags with iPads and iPhones.

You will need to download the Trigger App. If you have not downloaded this, your phone will take you there the first time when trying to use and NFC tag.

Technically, NFC has the ability for two devices to send data to each other simply by bringing one near the other. Here, the word device stands for a tag and a cell phone. NFC tags, also referred to as smart tags, have chips embedded into them and these can be programmed to transfer just about any instruction or data via NFC.

MOO.com offers business cards with NFC tags embedded within them. The idea is that when you hold your NFC enabled business card to an NFC enabled cell phone, your contact details are automatically added to the phone’s contact book. Therefore, you need to carry only a single card with you, which saves time and money. Moreover, no sensitive data is exchanged and there is virtually no security risk involved.

Advertisements have QR codes on them, allowing people to scan them to go to their blogs. That requires a barcode scanning app, the light has to be just right and the entire QR code has to be captured properly. With NFC tags, you only need to pass your cell phone over the advertisement to get the required information.

The NFC Task Launcher will allow you to program your NFC tags with your mobile phone. Once you have them programmed, the tags will help you to do almost anything from going to a website to enabling/disabling the Wi-Fi, adding contact details, setting an alarm, embedding information for a location and more.

What Is A Semiconductor Compass?

Chances are that your smartphone has a compass to show you which way is North. A normal compass consists of a magnetic needle suspended on a pivot and the earth’s magnetic field aligns it towards the magnetic North Pole. Since there is no magnetic needle within the smartphone, it is a wonder how this digital compass works. Well, a modern smartphone contains a built-in electronic or semiconductor compass, also called the eCompass. Moreover, this eCompass is calibrated for the magnetic interference from the circuit board and compensated for the tilt of your smartphone.

Probably the first sensor to be incorporated into a smartphone was the accelerometer that selected between the portrait and landscape display orientation. Then came the magnetometer and this evolved into the electronic or eCompass. The electronic compass is used to align the street maps to the geographic heading of the smartphone or to overlay augmented reality. With the high-volume production and use of smartphones, sensors for accelerometer and magnetometer now cost less than $1 each.

However, just having a magnetometer sensor is not enough to provide an accurate compass heading for a smartphone. There are two reasons for this – first, the magnetic field measured with the magnetometer varies significantly with tilt, the angle at which the owner is holding the smartphone. Second, the magnetometer requires to be calibrated not only for its own offset, but also against spurious magnetic fields caused by the nearby ferromagnetic components on the circuit board.

Both the above reasons are taken care of by the accelerometer. This is usually a three-axis component operating in the +/-2-g range with at least a 10-bit resolution. Its output changes by 512 counts as the accelerometer rotates 180° from pointing upward to downward. That gives it an average sensitivity of one count for every 0.35° change in tilt. For tilt-compass purposes, this is an acceptable sensitivity figure.

The other important measurement required from an accelerometer is its 0-g offset accuracy. This is the output of the accelerometer when it is in a free fall and experiencing zero gravity. As this value is an error adding to each accelerometer channel, it adds a bias in the calculate angles of tilt.

The geomagnetic field of the earth has a magnitude of 50µT, with a horizontal component varying over the earth’s surface. It varies from a maximum of about 40µT and goes down to zero at the geomagnetic poles. Therefore, for an eCompass to operate in horizontal geomagnetic fields, for example in the arctic Canada, where the field can be as low as 10µT and an accompanying noise jitter of +/-3°, then the magnetometer required must have a maximum noise level of 0.5µT.

In a smartphone, the software uses the aerospace coordinate system, where the initial eCompass orientation has X-axis pointing North, the Y-axis pointing East and the Z-axis pointing down. The three orientation angles are defined as clockwise rotations about the x, y and z-axis. These are named roll (ø), pitch (Ɵ) and yaw (Ψ) respectively. The earth’s gravitational vector points downwards at a magnitude of 1-g or 9.81ms-2.

Some of the Best Raspberry Pi Add-Ons

To most people, the Raspberry Pi or the RBPi Single Board Computer is only a cheap desktop. That is because by the time you have added a monitor, a keyboard, a mouse and the SD card, it would have cost as much as a cheap laptop and would still be a lot less powerful.

However, the real innovation of the RBPi lies not in its cost, but in its form factor. You can run the tiny RBPi on a few batteries or solar cells and use its exposed General Purpose Input and Output pins. This trio of combinations does not have any precedents in computing, at least not in the price range of the RBPi.

Being a new type of device, the RBPi is a lot easier to understand with some of the readily available components that connect to it to enable some function or to add some feature.

Most of these add-on components are not from large companies, but developed by hobbyists who saw the need for and filled it. One of these add-on components is the multi-purpose LED display Pi Lite. This is a simple board full of LEDs allowing people to use the RBPi to turn them on or off individually. This has made the RBPi SBC different from the regular PC and forced people to think differently for using it in its particular niche.

Pi Lite has 126 red LEDs, with a white LED version on its way. You plug the board into the GPIO pins on the RBPi. Pi Lite nearly covers the main RBPi board and has about the same form factor. Of course, you need a little configuration to enable the board to use the RBPi serial port, but that is well documented.

You send commands to the Pi Lite via a minicom terminal. Once connected over the serial port, anything sent over will scroll across in beautiful red light. Not only can you send text, you can also send commands preceded by three-dollar signs. You can turn all pixels on or off, display horizontal and vertical graphs and manipulate individual pixels.

You can improve the connectivity of your RBPi by expanding its ports. As the GPIO pins are exposed, any circuitry can be added to the RBPi. That may cause accidents and fry your RBPi very easily. Although there are several add-on boards that provide access and protection to the RBPI GPIOs, Quick2Wire has a board that uses the I2C and SPI features of the RBPi.

These are the Inter-Integrated Circuit and Serial Peripheral Interface and the board comes in two parts. The main board provides the I2C and SPI ports, adds protection for the RBPi and voltage selectors. Additional boards provide more GPIO ports including analog inputs and outputs that RBPi lacks. You can daisy-chain the boards to allow even more ports to be added to the RBPi.

To control the ports, you need to program the board with the Python programming language. For this, you may have to install the python3-setuptools package. You can find additional details of the above two add-on boards in openmicros.org and Quick2Wire.com.

The Raspberry Pi Command Line Interface

Being Linux based, the tiny Single Board Computer Raspberry Pi or RBPi has a graphical user interface familiar to regular computer users. Again, as most users of Linux will be familiar with, RBPi also has a command line interface where you have to type in the commands you want the SBC to execute. Well, a graphical user interface does have its merits and although the command line interface is a little more intimidating to the uninitiated, it is not a very difficult beast to tame.

One of the major advantages of the command line interface is its scope and speed – it easily accomplishes and most often surpasses what can be achieved with the graphical user interface, and does it faster as well. For most day-to-day tasks, however, the graphical interface is enough and has many useful applications including a web browser, test editor and file manager.

For those who want to delve deeper and learn more about how the SBC actually works, the command line interface is the way to go. Most of the work is done by opening up a Terminal or Shell and typing within it.

As the name suggests, the command line interface is an entirely text-based interface. You type in the commands that you want the SBC to execute, and it gives you a response. Although in the beginning, it will seem a little confusing, it is more like interacting in a natural way, just as we converse with another person. Once mastered, interacting with a computer via the command line interface will let you learn much more about it in the future.

You begin by opening up a Virtual Terminal/Console. Why is the name Terminal used? This is a legacy from the past when computers were gargantuan beasts, centrally located, with remote terminals distributed to the users. When you click on the LXTerminal on the Raspbian desktop, a small bordered box opens up, with ‘pi@raspberrypi $’ written inside it. The box is the terminal and inside it is the command prompt. The command prompt shows the name of the user – ‘pi’, the name of the computer – ‘raspberry’, also called the domain name, and the ‘$’ signifies that pi is a regular user and not the root or superuser (for root, the prompt would change to ‘#’).

The command prompt shows that your RBPi is now ready and waiting for you to type in your command. For example, you can see where you are by asking the computer to Print the Working Directory, by entering ‘pwd’ and hitting Enter. The SBC will most likely return – ‘/home/pi’, unless you have changed your username.

You can change the directory with ‘cd ..’, the computer knows that it has to return to the parent directory – ‘/home’. You may verify this with another ‘pwd’. With the command List Files or ‘ls’, you will be able to see all the files residing in the directory. Use a flag ‘-a’, to list the hidden files or all the files in the directory. Now the command becomes ‘ls -a’. Use ‘ls -l’ to see more information about the files.

For more information and for learning the command line, visit the website linuxcommand.org