Category Archives: Customer Projects

Keep Your Fish Happy with a Raspberry Pi

People who keep fish in aquariums at home know it is important to feed them timely and to keep their habitat clean. Trouble starts when the owner has to leave home for a few days and cannot find a knowledgeable caretaker to take care of the pets. Cabe Atwell tried to solve the problem he faced in an ingenious way – by using the power of the Internet.

Cabe had an automatic fish feeder, but he also enlisted the services of a friend to keep an eye on her goldfish, the friend was not sure of what was required and the automatic fish feeder broke down. Fortunately, the losses were not fatal, but Goldie the goldfish grew to double her size because of overfeeding. This led Cabe to work on a system to allow watching and feeding the pet over the Internet.

Cabe wanted a system that would allow seeing the fish in real time, anytime, by moving a camera around the tank. The next requirement was sensing the tank water temperature and cutting off the power to the tank bubbler and air filters, if necessary. It was also necessary to feed the fish manually, and above all, to do this through a network and ultimately, via the Internet.

Cabe’s research led to the conclusion that a Single Board Computer such as the Raspberry Pi or RBPi and a Pi camera would be most suitable for seeing the fish via the internet. For the other features, an Arduino Uno was more appropriate.

Accordingly, Cabe selected two small Nema 17 mount stepper motors, available on Adafruit, for the driver components. The motor controls came from an Arduino Motor Shield, which made it simpler to drive the motors. Cabe designated one motor for allowing movements in two directions, while the other rotated the food container to dump fish food into the water.

The fish feeder was a modification of the original malfunctioning feeder. It consisted of a drum to hold the fish food. When rotated completely around, a simple trap door opens briefly to let a small amount of feed.

To keep the camera motor traveling too far, Cabe incorporated limit switches in both directions. The limit switches were placed in position using rare-earth magnets, which allowed easy adjustments for the movement range. A surplus belt driven motion platform provided an affordable arrangement for viewing the entire length of the tank.

For sensing the water temperature, a waterproof digital temperature sensor was the most suitable – DS18B20. Although fresh-water fishes are more tolerant of water temperature variations, loss of air-conditioning or heating arrangement can lead to the tank water becoming too hot or cold for the comfort of its occupants.

For the video stream, Cabe settled on VLC since it was easier to use. VLC offered the maximum resolution of 640×480 pixels at 15 frames per second, which Cabe found adequate for keeping a tab on the fish. A simple AC relay took care of feeding power to the air filters and bubbler.

For the future, Cabe wants a better AC control and more sensors for measuring the pH, ammonia and nitrate levels in the water.

Incubating Eggs with a Raspberry Pi

Incubating eggs is a process best left to the mother bird alone or sometimes the father bird. That is because nature has programmed them for applying the appropriate temperature profile necessary to hatch their eggs successfully. However, this vital information is no longer the sole proprietary knowledge of the birds alone. Humans, at least those who rear chicken, probably know as much.

Hens incubate their eggs by sitting on them and instinctively controlling several factors, mainly the temperature and humidity, with their body heat. They also turn the eggs over periodically, which is vital for a successful hatch.

Although there are commercial alternatives available, building your own incubator has its own advantages such as affordability and the ability to add features. Dennis Hejselbak from Denmark has not only made such an incubator, but has also posted complete build instructions here. For those who want to follow, Dennis uses a Raspberry Pi or RBPi, the tiny, versatile single board computer for controlling his incubator. He has made available the necessary Python codes and the wiring schematics as well.

Dennis has built his incubator box from polystyrene, which makes it well insulated. He controls the temperature inside using an incandescent light bulb and an old CPU fan. Wet sponges inside the incubator supply it with the moisture necessary, while a hygrometer keeps an eye on the humidity levels. The RBPi controls the light bulb and the CPU fan based on feedback from a temperature sensor and the hygrometer. Dennis keeps watch on his eggs via a camera attached to the RBPi. He has enabled his RBPi with Wi-Fi and real time pictures of the incubation process are available on his website.

The only process Dennis has not attempted to automate so far is the periodic turning over of the eggs. He does this manually, about three times each day, until the eggs hatch. Although hatching eggs takes about 21 days on average, some eggs may hatch a day or two early and some a day or two late.

As Dennis is using forced air for his incubator, he programs the RBPi to keep the temperature within about 99-99.5°F (37.2-37.5°C). For successful hatching, eggs require 45-50% humidity from day 1 to 18 and 65% for the balance few days. Dennis has placed the temperature and humidity sensors to hang just above the eggs.

As the incubator is a large box, placing the RBPi on its top was not a difficult task for Dennis. This has its advantages as the box needs only a single hole for both the cables of temperature and humidity sensors to pass through – making it easier to insulate. Of course, other holes are necessary for the cable of the light bulb. Dennis handles all monitoring of the RBPi from outside, without having to open the incubator.

The RBPi controls the temperature by turning the light bulb on or off as necessary. A simple electromagnetic relay operated with a power transistor is enough for this purpose, although those who are adventurous among you may opt for a more expensive solid-state relay.

Leap Motion with the Raspberry Pi

Robots have the capability to work where humans would find it inconvenient. In fact, that is one of the reasons people build robots. For example, in areas where high amounts of nuclear radiation would be fatal for a human being, a robot can work happily. Science fiction movies have exploited this feature several times – a robot mimicking the hand movements of its human controller, when watched and manipulated from a safe distance. Now, with a few motion-controlled servos, Leap Motion and Raspberry Pi or RBPi, the tiny Single Board Computer, you too can make a robot with the ability to mirror the movement of your hands. Additionally, you can do this even when you are sitting on the opposite side of the Earth.

The project involves two servos, each mirroring the movement of your individual hands. A Leap Motion controller captures the motion of your arms and sends appropriate instructions to the RBPi, which drives the two servos using a PWM driver. Two 8×8 RGB LED matrices individually attached to the servos react to each finger movement on your hands. The Leap Motion controller communicates with the RBPi via PubNub Data Streams.

The project uses the RBPi Model B+, Leap Motion controller with Leap Motion Java SDK, four numbers of Tower Pro Micro Servo, the Adafruit PWM Servo Driver and an optional display case.

The Leap Motion controller is a powerful device. It is equipped with three infrared LEDs and two monochromatic IR cameras. The cameras capture the movement of your hands and Leap Motion publishes their attributes to a channel via PubNub. The Leap Motion SDK has the attributes pitch, yaw and roll pre-built in it and actually separates the movements of your hands into the three attributes.

For achieving real-time mirroring, Leap Motion sends the attribute information messages nearly twenty times in a second. It sends information about your individual arms and each of your fingers to PubNub. Since the RBPi subscribes to the same channel, it is able to parse these messages for controlling the servos and the RGB LEDs.

To start, you will need to open a Java IDE and create a new project. You will find a guide for the Leap Motion Java SDK here. Follow up this step with installing the PubNub Java SDK. Make your project implement Runnable, which will allow all the Leap activity to operate in its own thread.

Every second, Leap Motion captures nearly 300 frames. Each frame has a huge amount of information about the hands, such as the number of fingers presently extended and hand gestures such as pitch and yaw. To simulate the motion of the hands, one servo mirrors the pitch while the other mirrors the yaw. Incidentally, pitch is the rotation around the X-axis and yaw is the rotation around the Y-axis. Both servos rotate 180-degrees with a sweeping motion. The resulting servo mimics most of the movements your hands make.

Leap Motion outputs values for the pitch and yaw in radians. The RBPi is responsible for converting these radians into degrees and finally into PWM or pulse width modulation between 150 and 600 MHz for driving the servos.Leap Motion with the Raspberry Pi

Raspberry Pi Zero for a Real-Time Sensor Dashboard

Using the Raspberry Pi or RBPi, the single board computer (SBC), and a few applications from Google, you can have a functional dashboard showing real-time parameters from sensors. Google offers its App Engine in the form of a Platform as a Service or PaaS. The advantage is you can deploy and run your own applications using the Google infrastructure without bothering about exclusive ways of setting up hardware, servers, or Operating Systems.

Google also offers the free and powerful Google Charts that you can use as simple charting tools for plotting the data from the sensors into line charts. An HTML5 templates generator such as the Initializr is also useful for generating templates for the dashboard. Initalizr has several useful frontend resources such as Bootstrap and jQuery.

RBPi Zero is the perfect hardware platform to use for this project. This SBC is a full-fledged computer, but smaller than a credit card. It features a single-core CPU running at 1 GHz and 512 MB RAM. Along with a 40-pin GPIO header, the RBPi Zero has USB and a mini HDMI port.

When you connect a few sensors to the GPIO pins, the RBPi Zero sends their data over to the Google App Engine. On the dashboard, you can see the values and the charts updating in real-time as new data arrives from the sensors. Github carries the instructions for building and deploying the project for the RBPi Zero app and the App Engine dashboard.

For this project, Java is the programming language, as both the RBPi Zero and the Google App Engine support it – both use the Pi4J library. However, those who prefer Python can easily change the code, as both RBPi and the Google App Engine support Python as well. As the latest version of Raspbian, the Operating System of the RBPi comes pre-installed with Oracle Java 8, it is easy to deploy and run an executable JAR on the RBPi Zero.

The JAR acts as the go-between with the sensors and the Google App Engine – it reads inputs from the sensors and passes them on to the Google App Engine. You can use the Apache Maven to compile and build the code on the RBPi Zero. Of course, you may also build the code on your laptop or desktop and copy the resulting JAR over to the RBPi Zero.

You can use Cloud Endpoint on the Google App Engine side. This is a powerful service for creating a backend API by using annotations. This includes the client libraries for web and mobiles. It generates a Java based Android client for use with the RBPi Zero application. Google Qauth 2.0 authenticates the API for installed applications.

The RBPi Zero based hardware provides readings from three sensors – voltage generated by a solar cell, temperature from an analog temperature sensor, and illuminance or LUX from a photocell. A 10-bit Analog to Digital converter with SPI interface is necessary to covert the analog signal to a digital format suitable for the RBPi Zero. All the sensors work with a supply of 3.3V, and the RBPi Zero is capable of sourcing this.

Play Chess with the Raspberry Pi

You could be an ardent chess player searching for a worthy opponent. A human opponent may not always be conveniently present, but a computerized player can be relied upon to be available at any time of your choosing. With the Single Board Computer, the Raspberry Pi, or RBPi, you can now play a complicated game of chess, provided you are willing to build a chessboard first.

You will need an Arduino to control the chessboard and an RBPi to run the actual chess engine Stockfish, along with Chessboard, which is the chess rules library. The entire arrangement is completely automated – plug in the different parts, press the green button and you start playing. If there is no automated arm, you must move the pieces manually and the computer signals its move by flashing LEDs. You get 21 levels of play along with the ability to set the personality of the computer – coward or aggressive.

Apart from the personality setting and the 21 levels, Stockfish allows several features. Choose to play with black or with white pieces, and play against the computer or another human. Along with providing hints if stuck, Stockfish recognizes and makes special moves such as Castling, En Passent, and Pawn Promotion. It validates all moves against all rules of chess, signaling errors and allowing re-moves. The chess engine has a maximum rating of GM and an ELO level of 2900.

Although you can use the RBPi alone to control the board and play the chess engine, using an Arduino relieves the RBPi of many functions, speeding up the chess engine running on it. Since the Arduino does not use an Operating System, it is not possible to run Stockfish on it. Although there are chess programs to run on the Arduino, none is as strong as the Stockfish. Moreover, if you are using a computerized arm, the Arduino can take care of operating the motors. The combination of RBPi and Arduino for the chessboard works efficiently.

You can make the board out of wood or plastic according to the materials readily available. A chessboard has 64 squares with alternate black and white colors. To sense the pieces, you need reed switches under each square. These will be wired in the form of a matrix with eight rows and eight columns, with a single reed-switch straddling each junction. By numbering the rows as 1-8 and the columns as A-H, a command E2E4 tells the computer to move the piece from the E2 square to the E4 square.

To let the computer signal its move with LEDs, you will need a second matrix similar to that of the reed switches. Only this time, instead of reed switches, you must place LEDs at the junction points. Using sockets for both the reed switches and the LEDs is advisable as it becomes easy for maintenance. Unlike reed switches, LEDs are polarized, and need to be properly oriented to function. Placing them in sockets helps to re-orient them if they are inserted the wrong way. The Arduino controls both the matrices with data from the RBPi.

Driving Steppers with the RasPiRobot Board

The Raspberry Pi or RBPi is an inexpensive, tiny single board computer running the Linux operating system. As such, the standalone RBPi is not suitable for running motors, but when combined with an expansion board such as the RasPiRobot Board, you can easily run DC motors as well as Stepper motors off the RBPi. For this, you must use the version 2 of the RasPiRobot or RRBv2 board. Please note you can run only 5V steppers with the RBPi RRBv2 combination, as this board does not support 12V motors.
In practice, the RRBv2 board sits over the RBPi fitting over the latter’s GPIO connector. The stepper motor wires connect to the RRBv2 board, using its L & R screw terminals. To do that, you must first strip the wire ends of their PVC insulation, until about 10 mm of bare copper wire is exposed. Unscrew the terminal sufficiently to allow insertion of the copper part of the wire into the hole. Turn the screw clockwise to let the jaws hold the wire firmly.
One of the advantages of using the RRBv2 board is you can run the stepper motors from a battery pack. The board has a switch-mode power circuit to provide stable power to the motors. Additionally, you can even run your RBPi from this on-board power supply. That makes the entire arrangement completely portable.
When connecting the battery pack to the RRBv2 Board, take care to observe the correct polarity of the flying leads from the battery pack. Some battery packs terminate the wires on a plug. Therefore, you must use a matching female socket adapter that has flying leads. In either case, connect the positive or red lead to the screw terminal marked Vin on the RRBv2 board. Connect the negative or black lead to the screw terminal marked as GND on the RRBv2 board. Powering on/off through a battery pack becomes simpler if there is a built-in switch.
If you have connected your RBPi to the RRBv2 board, throwing the switch to the on position will allow the RBPi to start booting. To run the stepper motor with commands from the RBPi, you will need to download the RRBv2 Python library codes. For this, you will have to connect your RBPi to the Internet.
You can use the Ethernet connection to connect your RBPi to the Internet. Alternately, you may use a suitable Wi-Fi dongle. Once online, use SSH to establish connection to the RBPi from a PC and proceed to download the RRBv2 Python library from here and install it.
To run a stepper motor, you can write some simple Python codes, following the tutorial here. For example, you will have to provide the delay between the steps, the total number of steps you want the stepper motor to move and the direction of rotation – backwards or forwards.
The delay between the steps governs the speed of rotation of the stepper motor. For example, as you make the steps larger, the motor turns more slowly to make the total number of steps.

Room Automation and Raspberry Pi

Most people prefer to come back to a cozy room after a full day’s work. For many, this may not always be possible, unless someone turns on the AC at the right time. For those living alone, help is available in the form of a single board computer, the Raspberry Pi or the RBPi. In addition, the RBPi operates the blinds and you can control it from anywhere in the world – the RBPi is connected to the Internet.

For this project, you will need an RBPi with a suitable SD card, a Wi-Fi dongle, a stepper motor. You will also need a power source capable of driving the RBPi and the motor, a stepper motor driver board, an IR receiver, an IR LED and an NPN transistor.

Controlling the AC is a simple affair, with the RBPi simulating the infrared information the remote control normally uses. You need to use the LIRC library for the RBPi to record this IR information via the IR receiver. The infrared LED driven through the NPN transistor duplicates the signal sent by the remote control of the AC. Initially, you must let RBPi learn the IR codes by recording those using commands in the LIRC library. LIRC produces a configuration file that holds the IR codes for your AC. Playing back these codes through the IR LED allows you to control the AC just as its own remote does.

The RBPi and the motor driver board control a stepper motor for driving the blinds. The RBPi merely drives a GPIO pin to let the motor driver board know if it must operate the stepper. The driver board already has the necessary parameters stored within it for driving the motor. By default, the motor remains off so that it does not waste power when it is not needed. The software takes care of this by turning off the Enable pin on the stepper driver board. When you need to operate the blinds, a script on the RBPi turns the GPIO pin on and off.

To operate the unit from remote, you need to connect the RBPi to the Internet via a wireless network. Use the Wi-Fi dongle for this, configuring the RBPi to switch on the wireless connection immediately after booting. Web access to the stepper motor controller is through Nginx and PHP.

The entire setup works when the RBPi connects wirelessly to the network. You access a web interface and use it to send commands to the controller script running on the RBPi. Depending on the commands sent, you can access either the blind opener or the AC control. For opening the blinds, the RBPi sends on or off signals to the stepper motor controller board.

On the other hand, the RBPi sends the appropriate commands to the air conditioner via the IR link. Depending on the code transmitted over the IR link, the AC will switch either on or off. Additionally, with proper codes transmitted from the RBPi to your AC, you can even set the temperature of the room before returning at the end of the day.

Drive a 16-Channel Servo with the Raspberry Pi

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

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

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

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

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

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

Depending on whether you are using a standard or continuous rotation servo, your python code will vary. For the actual code with which you can control the various parameters of I2C and hence the servo, you may refer to this site.

Stackable Pi-Plates for the Raspberry Pi

If you are faced with a paucity of projects for your Raspberry Pi or RBPi, the tiny, credit card sized single board computer, you should get the circuit boards from Pi-Plates and connect your RBPi to the outside world. Pi-Plates offer a family of stackable, add-on boards that provide your SBC with a robust set of features at a minimal cost.

Pi-Plates design their circuit boards to be economical with the GPIO pins they use from the RBPi header. For example, when using the DAQCplate board, it uses only two dedicated GPIO pins. However, you can stack eight of these Pi-Plates to get 64 digital inputs, 56 open-collector outputs, 64 analog inputs and 16 analog outputs. Whether you are an experimenter, a hobbyist or a professional, Pi-Plates have designed these boards to be useful for all. Additionally, these are mechanically and electrically compatible with all revisions of the RBPi. That includes versions A, B, A+, B+ and the new version 2.

At present, Pi-Plates offer four products. The flagship product is the DAQCplate board that has ADCs or Analog to Digital Converters, DACs or Digital to Analog Converters and expanded digital IO. MOTORplate is a new product for controlling motors and you can use it to drive two stepper motors or four DC motors, while its onboard software can handle all drive logic including acceleration profiles. If you want to add custom hardware on your Pi-Plate stack, you can use the PROTOplate board.

When stacking Pi-Plates, you will need a secure structure and this is provided by the BASEplate mounting system. All hardware necessary for mounting to the BASEplate is already available with each Pi-Plate board. Pi-Plate also offers two great kits.

The DAQC kit comprises two BASEplates and one DAQCplate boards for the price of a single unit. This makes a great beginning for those starting with the DAQCplate for the first time.

For those starting with a MOTORCplate, the MOTOR Kit may be very useful. This kit comprises one MOTORplate and two BASEplate boards for the price of a single unit.

For example, the DAQCplate is a data acquisition and control board. Its digital output section has a connector that provides seven open-collector outputs and a pair of 5VDC outputs that you can use for driving loads. You can protect these with a flyback diode connected to the terminals.

You can use these outputs to drive incandescent automotive light bulbs, ultrasonic rangefinders, resistive heating elements, unipolar stepper motors, buzzers, solenoids, relays, DC motors or LED strings. Green LEDs connected to each digital output light up to indicate a high on the output. To light up these LEDs, you do not require connecting anything to these outputs. At the same time, these LEDs will not affect anything that you connect to these outputs.

Darlington pair transistors drive the seven open-collector digital outputs. They can sink a maximum of 350mA and handle a maximum load voltage of 12VDC. With a load voltage of 200mA, the on voltage is typically 1.1V. When using inductive loads such as solenoids or relays, you must connect the high side power supply to the flyback protection terminal.

A Microscope with the Raspberry Pi

If you require a microscope, you can make one as a proof-of-concept using the RBPi or Raspberry Pi. It is simpler if you have a bagful of LEGO parts to build the structure, but you can also go with Plexiglas construction. Apart from being a useful addition to a science laboratory, making a microscope with the RBPi is a good way of learning computer programming and making things with your hands.

The microscope uses an electronic camera for resolving images and its maximum resolution is about 5µm per pixel. That means you will be able to see and analyze dust, salt, hair and fruit flies – objects mainly in the range of a 20th of a millimeter to 5mm. Since at high resolutions only a small area will be in focus, you may confront distortion and color effects, commonly known as chromatic aberration. That precludes seeing cell culture or blood cells.

If you make the microscope construction from pre-produced parts and do not glue them together, it will allow for subsequent modifications, optimizations and adaptations for special applications, if necessary. You will need an RBPi2 with its SD card, a keyboard, mouse, a monitor or TV. You will also need an electronic camera similar to the WaveShare B, along with a 50 cm cable. For the pre-produced parts, you can refer here. The illumination comes from a 1.6W LED lamp working off a 9V block battery, operated through a small switch.

The construction of the microscope starts with a base plate and a sled tray for placing and holding objects or object glasses. Then there is a tower for holding the plate, which acts as the camera mount. You should be able to move the camera plate and the object sled orthogonal to each other for placing the camera precisely above the object.

There are two ways to focus the camera. You can adjust the length of the columns of the camera tower to get a coarse adjustment – this will adjust the distance between the object and the camera lens. For a better focus, you can then turn the camera objective manually. You may have a worm gear arrangement with a toothed rack (possibly from the LEGO collection) and you can use that to adjust the focus. The gear wheel with toothed rack could guide the object tray and the worm gear could be attached to the camera.

For processing images from the camera, there is a large choice of software to use. You can use very good GUIs available for raspivid (video capture) and raspistill (for still images). Alternatively, you can use raspistill along with Mathematica and its image analysis functions, for processing the images for subsequent analysis.

You can also use PiVision, which offers an option to preview the image to see if the camera is properly focused on the area of interest, before capturing the image as a still photo. During preview, PiVision allows changing the options setting for expanding the preview image to get more details and to re-focus, if necessary. Once you have captured the image, remove the unwanted areas by cropping it.