Category Archives: Raspberry Pi

Charlieplexing on the Raspberry Pi

If you suddenly find the need to control many LEDs and do not have the requisite electronics to do so, you can turn to your single board computer, the Raspberry Pi (RBPi) and use it to charlieplex the LEDs.

Charlieplexing is named after Charlie Allen, the inventor of the technique. Charlieplexing takes advantage of a feature of the GPIO pins of the RBPi, wherein they can change from outputs to inputs even when the RBPi is running a program. Simply setting a GPIO pin to be low does not allow enough current to pass through an LED or influence the other pins set as outputs and connected to the LED.

Using Charlieplexing, you can control up to six LEDs with three GPIO pins. For this, you will need three current limiting 470Ω resistors on each GPIO pin. The program charlieplexing.py defines a 3×6 array, which sets the state and direction of the three GPIO pins. The state defines whether the pin is set as digitally high or low, and the direction defines whether the pin is an output or an input.

Since LEDs are also diodes, they will light up only if their anodes are at a higher potential than their cathodes are, and not otherwise. Therefore, to light up a single LED, the program has to set the pin connected to its anode as output and drive it high. Next, the program must set the pin connected to the anode of the LED as input, while it sets the third pin as output and drive it low. Various combinations of the state and direction of the pins will drive all the LEDs on and off sequentially.

The array in the program holds the settings for each GPIO pin. A value of 0 means the pin is an output in a low state, 1 means the pin is an output in a high state, and -1 means the pin is set as an input.

In charlieplexing, it is easy to calculate how many LEDs each GPIO pin can control. The formula for this is, LEDs = n2-n, where n is the number of pins used. According to the charlieplexing formula, three GPIO pins can charlieplex 6 LEDs; four pins can control 12 LEDs, while 10 pins would allow control over a massive 90 LEDs.

Charlieplexing is good for not only lighting one LED at a time, but it is capable of lighting more at the same time also. For this, the program must run a refresh loop to keep the desired state of the LEDs in the array. While refreshing the display, the program must turn on other LEDs that need to be on, before moving on to the next. However, persistence of vision plays a large part here, and the program must be sufficiently fast to make it appear that more than one LED is on at a time.

However, there is a downside to lighting more LEDs at a time. Since more number of LEDs are now on to make it appear that more than one LED is on simultaneously, each LED is actually lit for a lower amount of time, which makes each LED glow less than at its full brightness.

Use the Raspberry Pi as a PLC for Automation

If you thought the popular single board computer, the Raspberry Pi (RBPi) is suitable only for children learning to write programs in computer languages, you need to think afresh. Vytas Sinkevicius is using the RBPi as a PLC for applications in automation. Increasingly, others are also using the RBPi as a PLC replacement in automation applications.

Basically, the RBPi replaces the actual PLC, and works as the main controller. The design specifications for the RBPi PLC are:

  • 8 digital Inputs
  • 16 Analog Inputs each supporting 4-20 mA current loops
  • 4 Analog Outputs each supporting 4-20 mA current loops
  • 12 Relay Outputs for control
  • 90-264 VAC Power Supply
  • 24 VDC Power Supply (Field)
  • Real Time Clock
  • Industrial Grade Enclosure

The enclosure has an aluminum back panel with ABS sides and a clear Polycarbonate cover. The cabinet is 14 inches in width, 16 inches in height, and 7 inches in depth. Installation is simple as DIN rail mounting is followed for all modules. While the local wiring employs ribbon cables, for field wiring the center of the panel has been left wide open. The enclosure uses industrial grade terminal blocks with rising clamp screw types.

A Delta Chrome series power supply block powers the unit. The power unit accepts AC voltages from a wide range of 90 to 264 VAC, and supplies an output of 24 VDC, with several safety approvals. While the input 4-20 mA signals are from powered transmitters, all the PI-SPI-DIN modules are supplied by high efficiency switching power supplies.

A PI-SPI-DIN-RTC-RS485 module forms the heart of the system. Apart from supporting the RBPi, the module also supplies power to the RBPi via the GPIO ribbon cable. For external displays and Modbus I/O modules, there is an RS485 interface and a battery backed Real Time Clock. The PI-SPI-DIN modules also have a buffered 16-pin GPIO bus, which also carries power from the 24 VDC to the modules.

The project has software written in the C language. It emulates a gas detection system with 16 points. There are digital inputs for manual control of fans, and analog inputs for controlling fans with variable speed. The software is undergoing testing presently. It will be published after it is found to work without issues.

Although the total number of IO points is substantial, the GPIO loading on the RBPi is not very high. For instance, the SPI bus uses only three GPIO pins, since the SPI routines allow any arbitrary GPIO lines to be used for chip selects. The I2C bus uses 2 GPIO lines, while the two 4-20 mA modules use two GPIO chip selects. While the PI-SPI-DIN-8DI module uses one GPIO for chip select, the relay modules use an MCP23508 GPIO expander with 4 addresses, but uses only one GPIO chip select. Direction control takes up one GPIO pin on the RS485, while it uses GPIO UART Rx and Tx.

The entire setup of enclosure, power supply, all modules, DIN rails, and RBPi3 cost less than $600. This easily rivals any PLC on the market with the same number of IO points.

Raspberry Pi Shake 4D Detects Earthquakes

Recent years have seen a rise in the interest of home automation and devices for local environmental monitoring. More people are now using solutions related to home science, such as weather stations. Not only does this help in better understanding of the factors that affect local environments, these solutions also offer accurate information in real-time. With the help of these home science devices one can measure what so long one could only feel and sense. Although this includes air temperature and quality, there are other things going on around that no one notices until perhaps it is too late, such as earthquakes.

The current project, the Raspberry Pi Shake or RBPi Shake, allows a deep connection to the environment surrounding you by measuring movements of the earth locally. While some of these movements may be too small to be felt, others could be big enough to set alarm bells ringing.

The RBPi Shake 4D offers all people the ability to observe unseen vibrations happening all around, including those big enough to cause people to sit up and take notice. While these earth movements do affect us somehow or the other, those serious ones often hit the news with increasing frequency. The cause for worry is these movements are not only limited to natural movements such as earthquakes, landslides, and sinkholes. Increasingly, human factors are also to blame with nuclear testing blasts, quarry explosions, fracking, and deep weel waste water injection chipping in impacting several of our loved ones directly. No wonder the Oklahoma Geological Survey acquired a 100 RBPi Shake 4D to monitor movements of the earth.

Offering a clever combination of technologies, the RBPi Shake 4D fits onto an RBPi, the most popular single board personal computer. Sorin Botirla, being a backer of the original RBPi Shake project, is also working on the present project. The objective is to develop a new and complementary web interface for all the models of the RBPi Shake.

The RBPi Shake empowers all citizen and home scientists, including hobbyists. At present, more than 1000 units are stationed worldwide in over 50 countries. This leads to the creation of the biggest citizen scientist earthquake monitoring network in history. Government institutions such as geophysical and earthquake monitoring institutes have also shown interest in the RBPi Shake project, as the RBPi Shake allows watching the effects of nearby constructions, traffic movements with changes during rush hours, and cheering crowds at local concerts or games. Within the home, it allows monitoring of the spin cycles of the washing machine, or the noisy neighborhood kid.

As suggested by its name, the RBPi Shake 4D has four sensors. Together with the geophone, there are three strong motion MEMs accelerometers giving the device a total of four recording channels. The circuit board of the 4D incorporates four 24-bit digitizers, with each sampling the movement of the earth at 100 samples per second. The data transmission rate is four packets per second, and that makes the RBPi Shake 4D compatible to Earthquake Early Warning systems.

An app on the Google play store allows seeing the data from all the Shakes installed around the earth on an Android phone.

Raspberry Pi and Automated Greenhouse

Many people set up greenhouses to grow tropical plants that need plenty of warmth and moisture. Usually these areas are enclosed in steel bracings holding glass/plastic panels that allow sunlight in and prevent moisture from going out. Greenhouse owners control the temperature by opening panels to allow ventilation. In winter, maintaining temperature could be difficult without use of heaters. Manually controlling temperature and humidity could be a tedious task taking away from the actual task of attending to the plants.

Therefore, an environment management system is an excellent way of controlling the weather within the greenhouse. Asa Wilson and his wife used a Raspberry Pi (RBPi) as the main computer for the environment management system for their greenhouse. They set up their greenhouse in Colorado on the western slope of Pike’s Peak. This place is notorious for its strong winds, while the normal growing season is very short.

As their greenhouse is rather small, measuring 10 x 12 ft., Asa uses a single temperature and relative humidity sensor. For larger greenhouses, the temperature and humidity at different locations will need to be monitored for effective control. Based on the input from the sensors, the RBPi controls the exhaust fans placed at opposite corners at the base of the greenhouse. The speed of these exhaust fans can be varied through custom speed control boards. Vents on the roof allow air to be drawn in when the exhaust fans are rotating. For air circulation, Asa uses a large oscillating fan mounted near the roof. The speed of this fan is set manually, and the RBPi can turn it on and off.

The greenhouse roof has four vents. Earlier, each vent could be opened with a single arm. However, that allowed the vents to vibrate in the wind, and they would sometimes close up. Asa designed and used vent controllers with geared motors and housed them in 3-D printed cases. The new vent controllers have two arms to hold each vent panel firmly on both sides, and this prevents any oscillations.

Initially, Asa used the RS232 protocol to let the RBPi talk to all the custom controllers. However, noise generated by the different devices caused communication issues. This led Asa to change over to RS485 drivers, which uses differential mode of communication for driving the signals. This solved the noise issue.

Although this is only a beginning, Asa is pleased with the results of his greenhouse. He is now planning for additional work. He is planning to add twenty more temperature sensors in the growing area for sensing temperature of individual plants, and a thermal controller for monitoring the sensors. He also plans to add seven water valves that will allow fine control on the humidity within the greenhouse.

Other people have also built automated greenhouses. For instance, David Dorhout has an automated watering robot that potters around carrying a 30-gallon tank for watering plants that need watering. Instrument Tek also has a similar greenhouse to Asa’s with an Arduino based system. In addition to watering and fan control, this also controls heat and communicates remotely to a computer.

The CHIP Computer Rivals the Raspberry Pi

Since the 2010s, there has been a new wave of single board computers smaller than the credit card able to perform like any major computer. Offering a range of tinkering and educational adventures, two of the most popular SBCs, the Raspberry Pi and the CHIP computer, are two unique products. While the Raspberry Pi or RBPi was the product of a UK nonprofit supporting children’s education, the Chip started as a successful Kickstarter project that raised more than two million dollars.

The RBPi family includes the RBPi 3 and the RBPi 2, the traditional models ranging in price from $20 to $40. Although simply affordable, the Chip, coming in at $9, is rather more affordable, provided you were buying them in batches for casual use or for instruction. However, the RBPi family boasts of the Raspberry Pi Zero or RBPiZ, which you can buy for $5, making it cheaper than the Chip, and the cheapest computer on the market.

However, both the RBPiZ and the Chip are bare computers in the sense that they do not have power adapters or cords. For connecting each device to a display, along with USB power adapters to power them up, you will need to spend some more. The RBPiZ needs an SD card, as it does not have on-board storage, and therefore, has a higher all-in cost compared to the Chip.

One of the most important features of these devices being connectivity, the Chip offers both Bluetooth and Wi-Fi, making it easy to move around with the Chip when experimenting. The Chip also comes with a composite port for connecting screens physically, a mini USB port, and a standard USB port.

While USB 2 ports are available on most of the RBPi models, they vary from 1 port to 4 ports. Many of the RBPi models also have Ethernet connections, while the RBPiZW, another model of the family, has the wireless connectivity just as the Chip does. Both the SBCs can be upgraded with various boards to give them additional connectivity. That brings the HDMI and VGA connections for the Chip, and full USB connections for the RBPiZ.

While the Chip works with a 1 GHz R8 processor based on the ARM7 architecture, the RBPi family comes with a range of processors beginning with the ARM6 single core to ARM7 quad core, while the RBPiZ has an ARM11 core. Speeds of the processors also varies within the RBPi family, ranging from 700 MHz to 1 GHz. Likewise, the family also has varying RAM capacity, ranging from 256 MB to 1 GB. All the RBPis, except for the RBPiZ, come with a GPU, a multimedia processor of the dual core VideoCore IV family.

As the RBPi family has evolved over the years, the more expensive models of the family are generally superior in performance to the Chip. Although the latest RBPi3 could be several times more powerful than the Chip, it would only be fair to compare the Chip with the RBPiZ, its more direct competitor. The Chip comes with a 4 GB on-board flash memory, while the RBPi boards rely on the SD card to provide the storage.

A Music Server on Your Raspberry Pi

If you are looking to create a music server on your Raspberry Pi (RBPi), Volumio may be a suitable choice. Although several websites give perfect instructions for setting up the RBPi as a media center for watching films and video series, very few provide solutions for audiophiles who would prefer to have a server dedicated to music.

Volumio is available as a Raspbian distribution. Using the application, one can manage the entire music library on a single device attached to the RBPi. Being very easy to use, Volumio supports all types of audio files—Vorbis, AAC, FLAC, mp3, and more. It even works with several DAC expansion cards. The team behind Volumio maintains it providing updates at least once a month, and this shows their seriousness in supporting this wonderful product.

The best way to get Volumio is to download it from their website. It is available as a Raspbian image, and it is necessary to download the image and decompress it. You will need a micro SD card to flash the uncompressed image—use one with a 16 GB capacity. Flashing requires a PC running Linux, Windows, or MAC. There is no need for an Ethernet cable, as Volumio works with a Wi-Fi connection.

It is advisable to use an RBPi3 with Volumio. On the first run, Volumio proceeds to install the application, which can take up quite a few minutes. In the selection presented, choose Wi-Fi and Volumio will try to connect with a network. If it does not find any network, or the network is inaccessible, Volumio will proceed to create its own hotspot. You can access this hotspot from your PC with the name Volumio and password volumio2. Typing the IP of your RBPi3 or the address volumio.local/ will take you to its web interface.

Once you are able to connect to Volumio on your PC, visit the Network tab, and move to the Wi-Fi Network section, where you can enter the code of security. Now you are fully equipped to run Volumio on your RBPi3, and add all your songs.

This is again a very simple process, and the recommendation is to have an external hard drive for this. Simply store all your songs on the external hard drive and let the RBPi3 use it. Navigate to Browse, then to Music Library, and select USB, which will allow you to see the hard drive. Alternatively, access the contents of the hard drive directly from the Album or Artist sections. Another possibility is to use a Network Attached System (NAS). For this, you must access the section My Music.

Still another possibility is to play the titles of Spotify, and you can do this by adding a plugin. This requires you to navigate to the Plugins section, and installing it from there. Once the installation finishes, activate Spotify on the RBPi.

Volumio is compatible to DLNA and AirPlay. Therefore, it is possible to broadcast audio streams from an iPhone. As Volumio offers a digital output, adding a DAC expansion card to the Raspberry Pi brings further gain in quality and listening pleasure.

Keeping Your Raspberry Pi Cool

Any PC motherboard is practically useless until you add some cooling and other accessories. This is because modern processors require cooling as they generate heat when operating. This is regardless of whether the processor is an x86, x64, an ARM based system such as the Raspberry Pi (RBPi), any other Linux or Android chipset, MIPs, or belonging to any other design.

The general explanation is the internal circuitry within the processor is microscopic and does not have the adequate surface area to dissipate the heat it generates while operating. Therefore, heat buildup within the IC can be detrimental, affecting its performance, unless the heat is removed. Designers usually build-in some safeguards against temperature rise to make the processor fail-safe. For instance, the PC has this feature as a part of the BIOS, and combined with the power management software at the OS level, keeps the CPU from being fried.

The RBPi single board computers run on an ARM chipset that follows the Reduced Instruction Set Computing or RISC architecture. Unlike the x86/x64 chipsets that follow the Complex Instruction Set Computing or CISC architecture, ARM chipsets do not need BIOS, but instead rely on a text file to feed it BIOS-like instructions when booting up. Notwithstanding the differences, the RBPis are as much a computer as those based on the Intel or Apple chipsets are, and prone to much the same issues of heat generation.

A research team at Microsoft, working on AI models and methods of shrinking image recognition to run on RBPi SBCs, has found a simple but effective way to reduce the heat the RBPi CPU generates while running their processor intensive workloads.

An internal protection on the RBPi3 disables it from overclocking when the ARM CPU reaches a core temperature of 85 degrees Celsius. In severe cases of overheating, the internal protection may also shut down the CPU. However, such interruptions are a real problem for any complex machine learning model programs the tiny device is running.

It is usual for a user to place a small heat sink on the RBPi3 CPU to help it to dissipate the heat and keep it cool. However, as the team at Microsoft discovered, this cooling is not adequate for some intensive workloads. According to the principal researcher Ofer Dekel at Microsoft, the cooling kits offered for the RBPi include heatsinks for the CPU and other components, but this is not adequate. Infrared images of the board point out that more work is necessary in cooling the processor.

Adafruit already supplies a miniature fan running on 5 VDC that users can mount on top of the RBPi CPU. However, for those mounting the RBPi on a 7-inch touchscreen display, this tiny fan can be a hindrance.

Therefore, the Microsoft team designed and 3-D printed a different fan mount. The design allows them to mount the Adafruit cooling fan directly on to standoffs available on the 7-inch display. With this arrangement, although the fan is pointing directly at the CPU, it is positioned at an angle beside the CUP rather than sitting directly on top.

Blinkt! is Compatible with the Raspberry Pi

If you are keen on learning how to control RGB LEDs with the Raspberry Pi (RBPi) single board computer, Blinkt! provides a simple way to interface. Blinkt! is a strip of eight superbright RGB LED lights that you can connect to the RBPi without wires, so it is an easy way to start. Blinkt! Has a female connector that matches the male GPIO connector on the RBPi, and that allows the tiny LED board to sit atop the RBPi.

The RBPi can individually control each of the eight APA102 RGB LEDs on the Blinkt! board individually, so you can consider them as matrix of 1×8 pixels. The footprint of the board is tiny enough to allow it sit directly on top of the RBPi and the pair fits inside most of the Pi cases. Although the RBPi controls the eight LEDs with PWM, it does not interfere with the SBC’s PWM audio. Blinkt! comes fully assembled and is compatible with RBPi models 3, 2, B+, A+, Z, and ZW. Pimoroni, the manufacturers of Blinkt!, also provide a Python library for the users.

Combining Python programming and Blinkt! with the RBPi is a great way of understanding how RGB LEDs work and how a computer program controls their operation.

If you are using the RBPi3 for this project, it will already have the male GPIO on the board. However, the RBPiZ and RBPiZW may not have the connector, which means you may need to solder the connector to the board. You need to be careful when plugging the Blinkt! board onto the RBPi taking care to orient it in the right way. The Blinkt! board has rounded corners on one of its side, and this side should face the outside of the RBPi. Once you align the boards properly, push the Blinkt! board in and it should fit snugly on the RBPi.

To make the RBPi control the LEDs on the Blinkt!, it will need to have the right code. The best way to begin is to update the Operating System of the RBPi to the latest Raspbian. Once you have done this, and the RBPi is running, connect it up to the Internet and open the terminal on the RBPi screen.

Typing the code “curl https://get.pimoroni.com/blinkt | bash” without the quotes, should allow the RBPi to download the necessary Python libraries from the Pimoroni website. Now you can use the Python 3 IDLE code editor to use the library to write the Python program and control the LEDs.

While writing the Python program, you will need to begin by importing the Blinkt! library you had downloaded in the first step. Each LED is termed as a pixel so the parameter “set_pixel” allows you to address a specific LED, while “set_brightness” allows setting its brightness. The command “show” turns on the specific LED, and “clear” turns it off.

Even though the LEDs are numbered as 1 to 8 on the board, the program addresses them as 0 through 7. Therefore, the program can pick a light and tell it the color it needs to be, its brightness, and whether it should turn it on or off.

Your Own Home Assistant with the Raspberry Pi

In the past one year, several off-the-shelf home assistants have made their way to the market. Some of the most famous of them are Siri, Google Home, and Amazon Alexa. For people too lazy to move, it is a pleasure to simply announce, “…, resume my audiobook“ or, “…, turn off the bathroom light,” and let the assistant do their bidding. In this melee of big names, there are several home-brew variants as well, some of them built on to single board computers such as the Raspberry Pi (RBPi). Many use them simply to have the time announced to them, along with allowing them to perform home automation tasks.

Therefore, if you are interested in making your own home assistant run on your RBPi, try the Gladys project. According to the website of the creator, the Gladys Project is an open-source program running on the RBPi and capable of connecting with all devices and checking the calendar to help with everyday life.

Apart from the basic day-to-day maintenance tasks that are necessary in life, Gladys can wake you up in time for work, if you have missed your regular alarm clock. Not only that, it can also play the video you ask it to play.

For instance, Gladys will gladly help in directing you to your work, taking into condition road conditions and travel time, ensuring you are never late, regardless of external factors. If there is a road blockage, say because of a queue on the motorway, which may make you late for work by about half an hour, Gladys will wake you up half an hour early. Also, while you shower and dress for work, Gladys opens the blinds and starts to brew coffee. If you are working around the house, Gladys will read and audiobook aloud, and you can request her to pause while you turn the mixer on.

Gladys detects your return home at the end of the day, and runs the evening routine you have set. As soon as you set your phone on the NFC tag to indicate bedtime, Gladys turns off the lights, and if programmed for it, starts the music playing, sending you into a deep slumber.

You can download Gladys as a pre-built Raspbian image. It is a free download from the website of the Gladys Project. Gladys is compatible with smart devices such as WeMo Insight Switches, Philips Hue light bulbs, and even the Sonos speakers, notorious for being difficult to control without their official app.

The download is in the form of a zip file. Unzip it to get the image file. Now, clone this image on to SD card you want to use with your RBPi. For this, use the program Etcher, which works on all operating systems including Linux, Windows, and Mac.

Connect the RBPi to your local network with an Ethernet cable or Wi-Fi and turn it on. At this point, it is a good idea to expand the partition on the SD card, to allow the system access to the full size of your card; else, it may run out of disk space very soon.

Raspberry Pi Drives the Oton Glass

Imagine standing in front of several road signs but unable to locate the one you want, because they are all written in a foreign language. This is the job for the OTON GLASS, a device to capture the image, translate it to a language of your choice, and read it to you in your ear. Not only will this help travelers abroad, but also help people with poor vision and those suffering from dyslexia.

Oton Glass is the effort of Keisuke Shimakage, who says he was inspired to develop the device by his father’s dyslexia. Keisuke got together a team of engineers and designers from the Media Creation Research Department at the Institute of Advanced Media Arts and Sciences, Japan, and started on the project.

At the heart of the Oton Glass is a Raspberry Pi 3 (RBPi3), along with two tiny cameras, and an earphone. One camera resides on the inside of a spectacle frame, tracking the user’s eyes. As soon as it detects the user blinking with no eyeball movement, another camera on the outside of the frame captures the image of whatever the user is looking at. The RBPi3 then processes the image, running it through an optical character recognition program. If there are any written words in the image, the RBPi3 coverts them to speech, and plays it through the earphone into the user’s ear.

Although the initial prototype of the Oton Glass was slow in capturing and replaying the text into audio, the team was able to cut down the time from 15 seconds to a mere 3 seconds in their second prototype.

The team designed the case in CAD software and 3-D printed it to be able to test it in real life situations. With feedback from dyslexic users, they were able to upgrade the device further.

At present, the Oton Glass is doing the rounds at several trade and tech shows throughout Japan, and is ready for public distribution. Trial is underway with models of the device at the Nippon Keihan Library, Kobe Eye Centre, and the Japan Blind Party Association. The Oton Glass has won the runner-up prize for the James Dyson Award of 2016. It has also generated huge attention at several other award shows and in the media.

In front of the inside camera of the Oton Glass is a lens with a half mirror that reflects the eye of the user, which the camera tracks for movements. The outer camera waits for a trigger from the blink of a still eye resulting from the wearer reading something, and captures the image and passes it to the RBPi3.

The RBPi3 uses an optical character recognition software to filter out any characters in the image. It then uses artificial voice technology to change the words into sounds, whose meaning the user can understand. If the Oton Glass is unable to recognize some characters, it sends them to a remote server to decipher. This allows the Oton Glass to translate anything that the user sees. The device combines camera-to-glasses and looks very much like normal glasses.