Tag Archives: Raspberry Pi Projects

Pairing your Raspberry Pi with an SPI OLED

OLEDs are interesting because they produce very crisp and brighter displays than is possible with the regular Liquid Crystal Displays. Being made of thin films of organic molecules, OLEDs use less power than conventional Light Emitting Diodes and LCDs. Driving OLEDs from your Raspberry Pi (RBPi) can be a great project to learn about these nifty solid-state displays and the processes that drive them.

Adafruit offers a lovely little monochrome SPI OLED module with a resolution of 128×32, driven by a SSD1306 driver chip. You can refer to excellent tutorials, libraries and guides on the website if you are driving this display from an Arduino. Although other OLED modules support I2C interface, this module supports only SPI, has pixel and text drawing functions, without any geometric drawing functions.

Although very small, only about 1-inch diagonal, the display is very readable because of the very high contrast of the OLED display. It has 128×32 individual white pixels, and the controller chip can turn each one of them on or off individually. No backlights are needed, as the OLED display produces its own light. This feature enhances the contrast and reduces the power consumption as well. The SSD1306 driver chip of the display communicates over the SPI bus, and requires four to five pins from the RBPi.

The OLED and its driver require a power supply voltage of 3.3V and logic levels of 3.3V for communication. If you are using this with the 5V supply of the RBPi, a 3.3V regulator should be used to power the display. On average, the display consumes about 20mA from the 3.3V supply, but this actually depends on how much of the display is lit. OLEDs usually require a high-voltage drive for the good contrast, but since this switched capacitor charge pump is already built-in into the display, this is one of the easiest OLED modules to interface.

Apart from the SPI specifications of the module, there is also a D/C pin, which controls the Data/Command going into the module. When you pull the D/C pin HIGH (connect it to VDD), the signals present at the pin are treated as data. When you pull it LOW (connect it to VSS), the signals present at the D/C pin are treated as command and are transferred to the command register.

What this essentially means is the opcode and the argument bytes that follow it are treated as a single command, even though this is a multi-byte command. For example, the command for setting the contrast control consists of a one-byte opcode followed by a one-byte contrast value. Therefore, the D/C pin has to be pulled LOW for the entire sequence when sending this command. Similarly, when sending image data, the D/C pin has to be pulled HIGH, which will enable the data to be moved into the image memory buffer.

The project is simplified when you use the following software – Occidentalis 0.2 for boot image, WiringPi-Python for accessing the GPIO pins and Py-Spidev for accessing the python bindings to the spidev Linux kernel driver. For further details, refer here.

Make a time clock with the Raspberry Pi

People working on projects are usually required to keep their time records up to date. However, those who are more engrossed with the technicalities of their work, find that they slip on their time keeping chores. If you fall into that category, let your Raspberry Pi (RBPi) help you out. Along with the tiny single board computer, you will additionally need one RGB LED, an OLED character display and a rotary encoder. Your time will be logged directly into a Google Docs spreadsheet.

The purpose-built time clock has several off-the-shelf components. For the RBPi, use the Occidentalis 0.2 operating system. The 128×32 OLED display uses SPI interface and this OS has the interface bundled in.

The time clock is very simple to operate. When you start it up, it will pull in a list of jobs from a specified Google Docs spreadsheet. To scroll through the list of jobs, simply rotate the knob on the rotary encoder. When you want to record time for specific project, just locate it by rotating the knob and click it. That starts the clock ticking on the spreadsheet. For logging off, simply click once again.

Use any case suitable for the RBPi or make your own. Since the HDMI, audio and video ports will not be used it is acceptable if the case does not provide access to these ports. For those who like to do things professionally, designing the carriage for the RBPi on OpenSCAD could be great fun. Printing the carriage on a Makerbot Replicator will give the required professional touch. Since the RBPi board does not have any mounting holes, you may have to put in edge-clips for holding it. Having posts at the corners of the board will make a snug fit.

Although the documentation of the RBPi mentions some ground pins as DNC or Do Not Connect, using them as extra grounds can be very convenient, just make sure you are using the proper ground pins.

Using the GPIO pin 5 of the RBPi for the push button can be of dual advantage. This keeps the pin 5 available for a Safe Mode boot, for example, when there is a recent firmware release. Simply hold the knob down when booting up and your RBPi comes up in the safe mode. Additionally, there is no chance of the pin being accidentally held low, such as could be the case if it was used for one of inputs to the quadrature encoders.

Use the software from here. The PWM library drives the RGB LED and the RgbLed class animates its color transition loops. The rotary encoder uses the RotaryEncoder.Worker class for polling through the encoder GPIOs and for keeping the application code as simple as possible.

Since the application code utilizes the CPU only to around 20%, its temperature rise is within safe range. The color-coding gives idea of the state of the machine. When no time is being logged, the LED shows purple. As time is logged against a task, the LED pulses slowly and turns blue. When rapidly flashing, you know that the spreadsheet on the Google Docs is being updated.

FishPi: How Raspberry Pi controls an autonomous ocean explorer

FishPi is a project for developing the prototype of a sun-powered autonomous ocean-going surface transport controlled by a Raspberry Pi (RBPi). The project is working on a small boat, to be propelled by solar energy to traverse the Atlantic Ocean and during its journey, the boat will be taking pictures and gathering data.

The goal of the FishPi project is simple. They intend to develop FishPis ranging from vessels running on batteries for a few hours to solar powered vessels full of features and capable of sustaining months at sea. The vessels will be MUSV or Marine Unmanned Surface Vessels, which will be capable of crossing the Atlantic ultimately and unaided.

An RBPi unit will provide all the command and control features of the FishPi vessels. The vessel will have an onboard solar panel, and the RBPi will control the data logging, navigation, power management and control of other devices on-board. The solar panel will charge a Lithium-ion battery pack, which will be driving a ducted propeller system. The Amateur Radio Satellite Network will be used to transmit images from the FishPi to the shore, by using satellites to integrate the ship-to-shore communication system.

During its journey, FishPi will use its environmental monitoring and data-gathering capabilities to measure the temperature of the air and sea, salinity and pH, barometric pressure, light levels and more. It will transmit some of the data along with images relayed in real-time.

For this, the RBPi is attached to a 16-channel PWM, a temperature sensor, a compass, a GPS, a USB webcam, a USB Wi-Fi dongle and a RockBLOCK satellite communicator. All these, except the compass and the webcam, are within a box on the FishPi Proof-of-Concept Vehicle or POCV now.

Initially, the base-station was planned to be connected to the POCV with a 32-core cable. However, this became too complicated and caused a lot of interference, so it had to be abandoned. Presently, the base-station contains another RBPi, connected to a USB hub and a 4-port Wi-Fi Router. The Wi-Fi link allows real-time remote control possibilities with the use of xrdp and the FreeRDP client. Additionally, this allows live video streaming to the world over the internet.

The electronic speed controller, the webcam, rudder, temperature sensor, the GPS and the compass are integrated with the C&CS or Command & Control System of the POCV. Currently, the coding is for manual control only, and the POCV can move forward, backward, to the left and to the right. With the webcam as a visual guide, the POCV can be driven remotely, but so far, this has been tested only indoors.

In the future, this control will be automated to the extent of giving the POCV the command and leaving it to navigate itself. For tracking, routing and waypoints, GPX files are being used while GeoTiff file formats are being used for the maps. Telemetry is an important function for any ocean-going vehicle. The POCV will be communicating both ways via the RockBLOCK Satellite Communication link.

There is always a chance that the vehicle can capsize in rough seas, and therefore, next in line is a self-righting mechanism.

Wear Your Raspberry Pi And Listen To Software Defined Radio

Carrying your radio along is nothing new, since a small and portable radio set is readily available. However, there is a different charm in carrying your single board computer with you while it is playing software-defined radio, and this is exactly what Miller Jacobson did with his Raspberry Pi (RBPi). There are two aspects to this project, the hardware and the software. While the software is simple enough, the hardware is somewhat involved.

To carry your RBPi around means to free it from the wall-mounted power supply unit. Power to the RBPi then has to come from batteries. Jacobson used lithium ion cells placed in an imported battery box. The enclosure uses four cells and can recharge USB devices and cell phones. It also incorporated charging voltage regulation and protection. He salvaged cells from a dead laptop battery unit, since these generally have quite a few good cells with only one or two cells bad, which render the entire unit useless.

To save space, Jacobson did not use connectors between the RBPi and the battery box. Instead, he soldered wires directly to the DC power jack on the battery box. The other end of the wires he soldered to the +5V and GND pins at the GPIO pins of the RBPi. He took the video output from the RCA port and used right-angled connectors everywhere he could, so that space used was at a minimum.

Jacobson used a second enclosure box, which was nearly the same size as the battery box, and fitted the two boxes one on top of the other, arranging to screw them together. Within the second enclosure box, he drilled holes to mount the RBPi board. He also cut holes on the sidewalls to take out the projecting wires and make the USB and HDMI ports accessible. Some ventilation holes in the enclosure allowed cooling.

For the display, Jacobson used a Nyxio Venture head mounted display. This is a cheap MMV or Mobile Media Viewer with a composite input. It features a slim profile with a full-sized image and has 2GB flash memory for storage. The virtual display simulates a huge virtual 62-inch screen in a 16:9 wide format on a non-radiation LCD panel.

For an input device, Jacobson used a generic wireless mini keyboard and trackpad. These are generally used for giving presentations and connect via a wireless interface. The tiny wireless receiver connects to the USB port of the RBPi.

Jacobson uses a Realtek RTL2832U based TV tuner as the front-end for the Software Defined Radio or SDR. The tuner covers a huge chunk of spectrum in the VHF and UHF range. The processor in the RBPi board was quite capable of handling the processing of the signals from the tuner.

GNU Radio, GNU Radio Companion and multimon are some of the software being used to receive and decode the APRS packets from the tuner. Jacobson is using Python for some of the other components such as for filtering the signals from the noise, extracting the raw audio and removing the DC offset, etc.

Home Protection with Raspberry Pi

Planning to go on a vacation, but afraid of who will look after your home for you? Worry not, for the mighty Raspberry Pi (RBPi) is here. Not only will RBPi look after your entire house, it will send you an email of what is happening in your home and let you see it on your mobile or on a PC. How cool is that?

Most alarm systems incorporate three primary sensors. The first is a temperature sensor to detect the rise in temperature in case of a fire. The second is an intrusion detection sensor to detect if an intruder has gained access to the insides of the house and third is a motion detection sensor. Apart from these primary sensors, you may add smoke detectors and cameras according to your necessity.

The software consists mainly of a database to store all the events with a time stamp, a dashboard to display the status of the sensors, configure them and to program the alarm system. The Raspberry Pi also acts as a web-server to send email alerts and to display the dashboard on a remote computer or Smartphone.

Depending on the size of the home, its vulnerability and the number of sensors being used, you could divide the area into a number of zones. This makes it easier to arm the sensors belonging to a specific zone. For example, a door and few windows of your home may be facing a busy street during the day and you may decide not to arm the sensors in this zone in the daytime. As night falls, the street gets deserted and you may want the sensors in that zone to be armed for the night.

Dividing the home into zones also has the advantage of knowing in which area or areas the alarm has been triggered. The camera for that zone can then be switched on to assess the situation visually.

Since RBPi runs on Linux, and Linux multitasks very well, the software runs in the background. The software is programmed to wake up RBPi about once every minute and check in on each of the armed sensors in all the zones. If there is no activity, it simply updates the logs for the database and the dashboard and goes back to sleep.

If a sensor trips, or generates an activity, Raspberry Pi records it in its logs, and sends you an email with the details. The dashboard then indicates the alarm condition in the zone where the alarm originated. You have a choice of turning off the alarm after checking it out.

You can login to the server from a remote PC using a username and a password. The web-browser will display the dashboard and a green button lets you know that the RBPi is running your home alarm software and is transmitting the information from the sensors. If the alarm system goes down for some reason, or there is a problem with the connectivity between the Raspberry Pi and your computer, this green button will turn red within a minute. You can now proceed to test, arm or disarm the sensors in each zone. For details of software and setup, refer here.

Gardening with the Raspberry Pi

Many of you may be garden enthusiasts and would welcome the idea of automating some of the maintenance requirements of your plants. For example, keeping tabs on the quantity of water that is required by the plants based on the moisture in the soil, the available sunlight and the environmental temperature might be easy for an experienced gardener. However, gardeners who have just started gardening find it a difficult equation to balance. Even an experienced gardener may have to depend on a novice if taking leave from his garden for a few days.

With a Raspberry Pi (RBPi), most of the above gardening issues can be fixed. The Raspberry Pi can take care of the garden’s watering requirements based on a few environmental measurements. This can bring relief to an experienced gardener forced to leave his beloved plants for a few days. The novice gardener can quit worrying if he is starving his plants or drowning them in water. This is how Devon approached the problem with his Raspberry Pi.

Avid gardening enthusiasts know that too much water to a plant can be as bad as too little. For the Raspberry Pi to determine how much water should be delivered to the plant, it is necessary to know how much moisture is present in the soil in the first place. That, combined with the temperature and the amount of available light can let Raspberry Pi control the pump that delivers the water to the garden.

Since Raspberry Pi is not capable of measuring analog signals that most sensors put out, an Analog to Digital Converter attachment is necessary. For this, using the MCP3008 ADC is a good choice since it allows eight sensors to be used at a time. For sensing the amount of sunlight available, a Light Dependent Resistor or LDR is useful. To measure the ambient temperature with some amount of precision, a temperature sensor such as the TMP35 or TMP37 will do. For sensing humidity in the soil, a homemade humidity sensor using a few long metal nails will be fine.

All the sensors will need a DC voltage supply and a return ground connection, with the signal from each sensor going to one of the channels of the ADC. The 3.3VDC from the Raspberry Pi board is good enough for the sensors. While only one temperature sensor and one LDR is enough, you may need more than one humidity sensor, depending on how big your garden is.

The humidity sensors check the resistance of the soil between a pair of probes inserted into the ground. As the soil dries up, the resistance increases between the two probes of the humidity sensor. If several such probes are placed at different places in the garden, the Raspberry Pi has a fairly good idea of the state of dryness of the soil in the garden.

The final and most important part of the entire system is the pump that delivers water to the garden. Using a tank and a submersible pump eliminates a whole bunch of issues that many gardeners face. You can experiment with drip-irrigation also if you like the idea. Devon has kindly shared the software and the code used, and you can download them here.

How to Paint with Light and Raspberry Pi

You can paint with light if you use a camera with large exposure times, while generating moving images with a Raspberry Pi (RBPi). Light painting is not new and traditionally images were hand-painted with a penlight. With the availability of cheap micro-controllers and addressable RGB LEDs, the idea of light painting has taken on a different meaning.

Since the images are large, producing them requires huge amounts of memory, something that RBPi has ample quantities of. Adafruit has Digital Addressable RGB LED Strips and connecting them to the Raspberry Pi is quite simple except that Raspberry Pi will not be able to supply the high currents that the LED strips demand, therefore, an external power supply will be required to power the strips.

Since the project will move about a lot, strong and reliable connectors will be required to interface between the Raspberry Pi and the LED strips. Connections from the GPIO of the RBPi are best taken via a 26-pin IDC cable and header. The LED strips are connected using two JST 4-pin plug and receptacle cables. The wires of the cables are soldered together in the proper sequence.

Since the RGB LED strip requires updating at very high speeds, this is addressed with a Serial Peripheral Interface or SPI bus. However, the GPIO libraries that RBPi uses with the “Wheezy” OS distribution are not fast enough. Therefore, Raspberry Pi needs a change of OS and must use “Occidentalis”, which is the Adafruit Raspberry Pi Education Linux distro, and includes the SPI support.

Occidentalis also has sshd that makes it easier to transfer images from a PC to the Raspberry Pi. sshd is the “secure shell” daemon server. It is like a secure version of telnet, allowing a user running the ssh client program on a local computer to connect to another (remote) computer running the sshd server, and logon to the remote computer. Unlike telnet, the communications are encrypted against network sniffers.

A Python Image module is used to convert the image transferred to the Raspberry Pi to an RGB format suitable for the LED display via the SPI devices. Instead of repeatedly processing each row or column of the image on the fly, the entire image is preprocessed into the hardware specific format suitable to the LED strip and stored in the memory of the RBPi as arrays. Refreshing the display is then only a matter of reading these arrays from the memory into the SPI port. More details of the hardware and software are available here.

The motion rig consists of a large PVC pipe bent into a ring on a hula loop. The LED strip is mounted on this and retained with zip ties. The ring assembly, batteries and the electronics is attached to the rear of a bicycle, which provides the motion. The entire arrangement including the bicycle must be painted matt black to be invisible in the photos.

For the power supply, 12V batteries have to be used, and a DC-to-DC converter is required for powering the LED strip and the electronics, all of which operate at 5V. The result of all this labor is limited only by your imagination.

Monitor your health with Raspberry Pi & an E-health sensor

You can monitor various health parameters with your Raspberry Pi or RBPi. All you need to do is to use the e-Health Sensor Platform by plugging it atop your RBPi. This arrangement is especially helpful in performing biometric and medical applications where nine different body parameters are to be sensed: oxygen in blood or SPO2, pulse, body temperature, airflow or breathing, electrocardiogram or ECG, galvanic skin response or GSR or Sweating, blood pressure or sphygmomanometer and patient position or accelerometer.

All this information is available in real time, and can be used to monitor the state of health of a patient. The sensitive data can be stored for subsequent analysis for medical diagnosis. Depending on the application, the biometric data gathered can be sent wirelessly over any of the six different connectivity options available: ZigBee, 802.15.4, Bluetooth, GPRS, 3G or Wi-Fi.

For real time image diagnosis, you can attach a camera and send photos and videos of the patient to the medical diagnosis center. For permanent storage, the data can be sent to the Cloud. Visualization in real time is possible by transmitting the data over to a Smartphone or a laptop directly. There are plenty of applications for the iPhone and Android Smartphones that will allow the patient’s information to be seen.

This opens up a new era of open source medical products. The RBPi provides the new e-Health applications and products a quick proof of concept with the necessary tools. However, one of the key points in such applications is privacy and several security levels are provided with the platform.
The communication link layers use WPA2 for Wi-Fi and AES 128 for ZigBee and 802.14.5. The application layer uses a secure protocol (HTTPS) to ensure a point-to-point secure tunnel between the web server and each sensor node. Banks use this type of communication security protocols for their transactions.

The e-Health Sensor Platform is available from Cooking Hacks. Cooking Hacks, the open hardware division of Libelium, have designed it. The platform helps artists, developers and researchers to measure different biometric sensor data for their experimentation, tests or fun purposes. Compared with the expensive and proprietary medical market solutions, Cooking Hacks provides a comparatively cheap and open alternative.

Cooking Hacks also provides an RBPi to Arduino shields connection bridge, which includes the possibility of connecting the analog and digital sensors to both the boards. This allows harnessing the power and capabilities of the RBPi with the pinot of the Arduino. Further, they also have the arduPi library that allows the use of RBPi with the same code that is used for the Arduino. The arduPi library allows wireless modules, sensors, shields and electronic module or actuator to be interchangeably used for both RBPi and the Arduino.

Note: The e-Health Sensor Platform does not yet have a medical certification. Therefore, it must not be used to monitor patients who are critical and who need to be monitored by medical methods that are more accurate or those whose conditions need monitoring for ulterior professional diagnosis.

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.

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.