Tag Archives: Raspberry Pi

Working with Gas Sensors and the Raspberry Pi

Many devices predicted by earlier science fiction stories and movies have come true. Among them are gas detectors as envisaged by the TV series Star Trek. If you have a single board computer such as the Raspberry Pi (RBPi), you can use it to detect the type of gas and air quality around you. Of course, you will need to couple the RBPI with a gas sensor, and among the popular gas sensors available are the BME680 from Bosch, and the CCS811 from AMS.

Gas sensors are helpful in sniffing out volatile organic compounds, many of them not only poisonous but also flammable. Volatile organic compounds may be natural or manmade, including paints and coatings that require solvents to spread in a protective or decorative coating. Where earlier the paint and coating industry used toxic chemicals, they are now shifting towards aqueous solvents. Natural volatile organic compounds may come from direct use of fossil fuels such as gasoline or as indirect byproduct such as automobile exhaust gas.

Some volatile organic compounds may also be carcinogenic to humans. Among them are chemicals such as benzene, methylene chloride, perchloroethylene, MTBE, Formaldehyde, and more.

BME680

Bosch developed this tiny sensor BME680 specifically for applications involving mobiles and wearables that require low power consumption. This one sensor has high linearity, and measures temperature, humidity, pressure, and gas with high accuracy. This 8-pin LGA package is only 3 X 3 X 0.95 mm, and Bosch has optimized its power consumption based on the specific operating mode.

With high EMC robustness and long-term stability, the BME680 measures indoor air quality, while detecting a broad range of gases and volatile organic compounds. For instance, the BME680 can detect formaldehyde from paints, and other volatile organic compounds from paint strippers, lacquers, furnishings, cleaning supplies, glues, office equipment, alcohol, and adhesives.

Apart from applications for indoor air quality measurement, BME680 is also useful for applications such as personalized weather station, measuring skin moisture, detecting change in rooms, monitoring fitness, warning for dryness or high temperatures, measuring volume and air flow, altitude tracking, and more.

CCS811

Compared to the BME680, the CCS811 is only a digital gas sensor. It is meant for monitoring indoor air quality using a metal oxide gas sensor. The gas sensor can detect a wide range of volatile organic compounds. The CCS811 includes a micro-controller unit, an analog to digital converter, and an I2C interface.

With optimized low-power modes, AMS has designed the CCS811 for high volume and reliability. It has a tiny form-factor that saves more than 60% in PCB footprint, while producing stable and predictable behavior regardless of air quality at power up.

Similar to the BME680, the CCS811 also measures the total volatile organic compounds and the equivalent of calculated carbon di oxide. However, the consumption of CCS811 being about 60 mW, it may be necessary to have to supply it with an external supply of 3.3V.

Both sensors need the working I2C bus on the RBPi to interface and function. The software library for the two sensors are available here for the BME680 and here for the CCS811.

Facial and Object Recognition with A Raspberry Pi

f you are using the single board computer Raspberry Pi (RBPi) for vision-related tasks such as facial and object recognition, the NCS or Movidius Neural Compute Stick from Intel could help to boost the rate at which the RBPi carries out its tasks—you actually do not need to employ a server farm for the job.

The RBPi is fully capable of running software for facial image recognition, and hobbyists have long being using the SBC for recognizing faces in videos to identifying obstacles in the path of a robot. However, the rate at which the RBPi carries out such tasks leaves much to be desired, and the NCS helps to improve this rate.

The Movidius NCS from Intel plugs into the RBPi via the USB port. Inside the stick is a Myriad 2 Vision Processing Unit (VDU) with 12 specialized cores that accelerate the vision recognition tasks for the RBPi. Although it consumes only a single watt of power, the low-power VDU processor works at 100 gigaflops. Sometimes, the stick may need higher processing power and it could consume 2.5 W.

Users can watch the video Movidius has released for guidance on how to use the NCS. There is also a text guide to help users figure out the nuances of object recognition using the RBPi and the NCS. The video demonstrates the system recognizing a pair of sunglasses and a computer mouse on the table.

To get the demo running, the user needs to download and install a few software libraries. On the hardware side, apart from the RBPI, you also need a Pi camera.

Movidius initially announced the early version of the NCS in April last. They then released a prototype device, which they named Fathom, before Intel purchased Movidius. According to Dr. Yann LeCun, founding father of Convolutional Neural Networks, and director of AI research at Facebook, Fathom was a significant step forward.

Intel then released NCS, which has broadly the same specifications as the Fathom did, with the exception that the former has a 4 GB memory. This is an improvement of four times over that of the latter, and it helps the NCS to support denser neural networks. With NCS, any robot, big or small, can possess vision capabilities that are state-of-the-art.

According to Intel, the NCS can lower the barriers for those starting with deep learning application development. It actually offers a simple way for users to add a visual recognition system to their prototype devices such as robots, surveillance cameras, and drones.

As the NCS already has 4 GB of internal memory, and handles all the data in a neural network that is locally stored, the NCS does not have to rely on an Internet connection to connect to a server. In actual practice, transferring data to and from a remote server would introduce a huge latency and any high-performing processor to overcome the latency would consume a huge amount of power. The NCS overcomes both the above shortcomings.

The processor on the NCS is more powerful than the RBPi, although it does not actually accelerate the training process of a neural network, which is a computationally intensive process when carrying out vision recognition.

Raspberry Pi Control for Pool Temperature and Motor

Owners of swimming pools often have no idea of the temperature of the water in the pool relative to the surrounding air. They also are unable to control the pump schedules unless they put up a mains timer. However, using a single board computer such as the Raspberry Pi (RBPi) makes it easy to display the temperature on a webpage, while it switches the pump automatically on or off based on a preset schedule.

The pool monitoring system does not need a full version of the RBPi, as the RBPiZW, the Zero W version, will be adequate. For instance, the designer, Matt, designed the pool monitoring system for his summer escapes pool that holds 4100 liters of water. Matt designed the RBPiZW system to measure the water and air temperature and log the measurements to a cloud on the Internet. This allows the system to display temperatures on a web page he is able to access from a mobile phone, while allowing him to switch the pump on or off. The system can also place the pump on an automatic mode to follow a specific schedule.

Pool pumps are usually mains powered and contain a filter. Traditionally, users control this with a mains timer, but that precludes the possibility of switching it on when the solar panel supplies free power. For instance, the user may want to replenish the water at the end of the day after heavy use, and this is not possible without tinkering with the timer unit.

Matt housed his RBPiZW monitoring system in a weatherproof box. It offered room to include a 4-way extension block and has a 10 m mains cable running to it from the house. The box houses the RBPiZW and its 5 V power supply. The sensor wiring enters the box through rubberized slots.

According to Matt, the finished system comprises, apart from the pool and pump, a weather-proof box, a 10 m mains extension cable, an RBPiZW, a 5 V charger, a 4-GB micro SD card, two water-proof temperature sensors (DS18B20) each with 3 m cable, bias resistor for the temperature sensors, an Energenie Socket, and an Energenie Pi-mote as add-on.

The Energenie socket is a remote control socket. Additionally, when combined with the Pi-mote, it allows controlling the socket with Python scripts. Being easy to set up, this combination offered an easy hardware for controlling the pump. Matt had only to plug in the Pi-mote into the GPIO header of the RBPiZW.

The DS18B20 waterproof temperature sensors are single-wire interface and many of them can be connected to the GPIO pins. The waterproof sensors come with all cables attached. Although somewhat more expensive than the regular standard sensors, Matt only needed to solder the three wires from each sensor to the appropriate GPIP pins on the back of the Pi-mote to make them work.

Matt placed one of the sensors in a hedge near the pool for measuring the air temperature, while he dipped the other into the pool water to measure the temperature of the water. Each sensor has a 3 m cable length.

Interfacing the Tilt Hydrometer and Thermometer to the Raspberry Pi

Tilt is a wireless hydrometer and thermometer combination suitable for home brewers that allow instant readout of the specific gravity of your brew. You can see the specific gravity readings on your Apple iPhone, iPad, or Android smartphone. Furthermore, Tilt can talk to your single board computer, the Raspberry Pi (RBPi).

Tilt will talk to most devices sporting the Bluetooth 4.0+ interface. Once you have the data in your device, you can optionally save the data automatically into a cloud using Tilt’s free Google Sheets template. You can also save the data using other third party cloud platforms as well.

For helping home brewers make better beer, the Tilt hydrometer allows automatic checking of its specific gravity and temperature even while it is fermenting. Simply dip the Tilt hydrometer in the beer within your fermenter and leave it inside. Without having to open your fermenter again, you can receive the data on its present status, and this makes brewing simply more consistent and easy to track.

Tilt has a powerful transmitter, allowing it to send data wirelessly even through large thick-walled fermenter. Therefore, you get a better range and reception. With its sensitive sensors such as the improved temperature sensor and accelerometer, you get precise readings. Power consumption is low, which means Tilt does not consume much battery power while operating.

Operating the Tilt could not be simpler, as each unit comes calibrated and a pre-installed battery, ready to go—you only need to download the free app. Now sanitize your Tilt and drop it in your fermenter. You will automatically receive data on your device.

If you have different batches of fermenting beer, use multiple Tilt Hydrometers. You can differentiate those using separate colors for each batch. The app does not read multiple hydrometers of the same color. The Tilt has a range of 0.990 to 1.120, and gives an accuracy of ±0.002. The thermometer has an accuracy of ±0.5°C (±1°F).

If you have an RBPi with a Wi-Fi dongle and Bluetooth 4.0+ or BLE, you can use the Tilt Pi to log your Tilt readings. Tilt Pi is an SD card image, which you can download from the Tilt webpage and use to boot up your RBPi3 or RBPiZW. After downloading the image, simply write it to an 8GB or higher SD card.

On the SD card, Tilt has included a SETUP.html file that helps with the Wi-Fi and cloud logging setup. This file guides you in creating the configuration files that allow connecting to your local Wi-Fi network. You will also receive an email giving a link to your cloud data log. Another link will also point to your Tilt Pi dashboard, from where you can change settings, calibration, and view the data on your local network.

The Tilt Hydrometer does not include the RBPi, so you will have to buy one. The built-in Bluetooth and Wi-Fi wireless technology included in the Tilt Hydrometer offers reliable cloud and local data logging. The setup is streamlined, so as soon as the RBPi boots up with the Tilt Pi SD card, the system begins logging data.

Using the Raspberry Pi to Secure IoT

The popular single board computer, the Raspberry Pi (RBPi), can effectively secure systems that traditional protection mechanisms often cannot. Industrial control system networks and Internet of Things fall under this category. You can use the RBPi2B and later models as an adequate medium for running the various security tools.

For this project, you need a Micro SD card of at least 8 GB size, and the bigger it is the better, as you can use the extra space to store a longer log data history, for instance, for logging data from Bro IDS. A case for the RBPi is preferable, and you can use one suitable to your individual taste and style. Although optional, a small form factor wireless keyboard is more helpful to configure the device on the fly, rather than using a full size keyboard.

Once you have configured the RBPi for networking, enable SSH and allow configurations from an SSH client. The hardware you will need includes an RBPi2B or later, an 8+ GB Micro SD card, a case for the RBPi, a Micro USB power cord, and an optional mini wireless keyboard.

Use the RBPi website to follow their getting started guide and install the Raspbian operating system using the New Out of the Box Software (NOOBS). Those familiar with the installation system can also use the traditional method of installing the Raspbian OS directly without the NOOBS, and it should work fine. Other OS distributions for the RBPi may also work, but you will need to try them out.

As the RBPi security solution places great reliance on lightweight open-source software, and the device monitors all traffic, you need to install software that inspects the traffic to learn what is going on. This requires installation on an Intrusion Detection System or IDS. Among the several free products available in the market, the one most suitable for the RBPi is the Bro IDS. The Bro inspects traffic at all OSI layers, and adds additional scripting that increases attack detection.

Bro IDS has some prerequisites before it can install on the RBPi. Install the prerequisites via apt-get, and after completing, download the latest source code for the Bro. Now, setup the environment to build, and to install the build—use configure, make, and make install. This allows you to manually control Bro, or use Broccoli to control it automatically.

Although the Bro IDS comes with an extensive signature base that can detect a number of common attacks, you can enhance its signature with Threat Intelligence. Another advantage in using the Bro IDS is the availability of Critical Stack, and you can integrate the threat intelligence with the Bro.

You can use Critical Stack, a threat intelligence feed, as a free aggregator. It functions as a simple point-n-click integration as it pulls data, such as addresses for Tor Exit Mode IP, known phishing domains and/or other malicious IPs. After pulling the data for threat intelligence, the Critical Stack agent formats it into a scripting language that Bro understands. The Bro IDS can pick up the new script automatically.

The PiServer for the Raspberry Pi

If you were running an institution teaching computer programming to kids using Raspberry Pis (RBPis), then you would normally spend some time updating numerous RBPis with the latest Raspbian and copying over several files for the class. You can save a lot of time using the PiServer, and do away with the SD cards at the same time.

The PiServer is a new piece of software tool that can easily set up a network of client RBPis connected to a single x86-based computer acting as the server. The various RBPis connect over Ethernet, and do not need their SD cards to boot. The server can control all its clients, allowing addition and configuration of user accounts. This provides an ideal setting for the classroom, within the home, or even an industrial setting.

To recall the terminology, the server is the computer providing the boot files, the file system, and authenticates the password of the clients. The clients are several computers that communicate with the server to retrieve the boot files, and the file system from the server. Although several clients connect to one server, they share the same file system. A user, with a unique combination of a username and password, can log into a client system. Once logged in, the user can access the file system on the server. The user may log in from any client system using their credentials, but will always see the server and the same file system. As the system does not give sudo capability to any user on a client, users are unable to make significant changes to the software and its file system.

All client RBPis use the PXE or network booting, and therefore, do not require any SD card to boot. The advantages of this type of booting are a large number of clients can boot off a single server, which treats all clients as the same. Additionally, as the server runs on a regular x86 system, it offers higher performance, network speed, and disk speed.

Without the PiServer, creating such a network would involve a lot of work, setting up the required FTP and DHCP servers, and making them interact seamlessly with other components on the network. The entire network is prone to breakdown with a single error. The PiServer takes care of all the intricacies, and has automatic functionalities.

For instance, PiServer can automatically detect any RBPi trying to boot via the network, and locate its Ethernet address. PiServer also sets up a DHCP server, to act as a router to provide an IP address to each client, whether in proxy mode or in full IP mode. For the safety of the network, the DHCP server replies only to those RBPis you have specified.

The PiServer also has the task to create usernames and passwords on the server. Therefore, in the classroom, the teacher can set up all the users beforehand. This allows each user to log in individually and keep all their work separately in the central location. The PiServer uses a somewhat altered Raspbian build, which has the LDAP enabled.

Blinkt! is Compatible with the Raspberry Pi

If you are interested in 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.

Raspberry Pi Helps a Hexapod Robot Walk

Roland Pelayo has used the single board computer, the famous Raspberry Pi or RBPi to help a hexapod robot learn to walk. The RBPi allows the robot to run in an autonomous mode, so it walks without assistance, avoiding obstacles. Alternately, it can also operate in a manual mode, whereby a user with a smartphone can control the robot. Most interestingly, the hexapod walker follows the tripod gait, just as most six-legged insects do.

Roland prefers to use servomotors to control the gait of the hexapod robot. According to Roland, using three servomotors to control the movement of the six legs of the robot, strikes a balance between performance and price. He added another servomotor for moving the eyes of the robot.

The servomotors allow the robot to move in four directions, forward, backward, left turn, and right turn. The robot moves by tilting itself to the left or the right, and then moving the leg lifted by its tilt. Roland has drawn diagrams explaining the movements of the robot. The backward and turn right movement of the robot is basically the reverse of its forward and turn right movement respectively.

Therefore, the front and corresponding back legs of the robot are interconnected to two servomotors, one to the left pair and the other to the right. The third servomotor helps to tilt the robot.

The RBPi allows the hexapod walker to operate in two modes. The first is the autonomous mode, which allows the robot to roam around freely, avoiding obstacles in its path. For instance, if it detects an obstacle in front, the robot walker takes two steps backwards, turns right, and then moves forward again. The second mode is for allowing the user control the movements of the hexapod robot using a smartphone on the same network as the robot is.

Roland has designed the program to allow the RBPi control four servos simultaneously, while reading inputs from a sensor detecting obstacles. The RBPi also connects to a network for the remote wireless control. Using an RBPi for the project was simpler for Roland, as the RBPi features on-board wireless connectivity.

Roland uses three Tower Pro SG-5010 servomotors, two for moving the legs and the third for tilting the hexapod walker. A fourth micro servo motor, a Tower Pro SG-90, helps to move the head and the eyes. An RBPi2 fitted with a USB Wi-Fi dongle helps to control the four servomotors. While the RBPi runs on a small power bank, the servomotors have their own separate power source. An ultrasonic sensor, HC-SR04, performs the obstacle detection.

As the echo produced by the ultrasonic sensor may cross the 3.3 V levels, Roland placed a voltage divider in between to connect to the RBPi, as its GPIO pins cannot accept voltages above 3.3 V.

As Python is already installed on the RBPi, Roland used it to write the program for the Hexapod walker. However, he also needed an extra library called pigpio, mainly for controlling the servomotors. He used SSH to access the RBPi remotely and installed the extra library.

Storm Glass Lamp: Raspberry Pi Simulates a Storm

Several people have used the versatile single board computer, the Raspberry Pi or RBPi, as many types of educational devices. In fact, the original purpose of conceiving the RBPi was to use it as an educational instrument to further computer programming among children in schools. It has been serving this purpose excellently, and has managed to go even farther. For instance, the RBPi inspired someone to make a weather-simulation lamp for recreating the weather at any place in the world.

The RBPi within the Storm Glass lamp uses the API Weather Underground for accessing current and future predicted weather at any place in the world. At first glance, one may be rather skeptic about the project, especially when the current weather can be gleaned simply by looking out of the window. However, perception soon dawns when explained that the project is actually able to predict weather—observing tomorrow’s weather today. Alternately, it is possible to keep track of the weather in a distant location, say, a prospective holiday destination.

The designer created the cap and base for the lamp by 3-D printing them. The glass sitting in between the two actually belongs to that fancy mineral water bottle readily available in the supermarkets, which people casually overlook and are forever unable to justify buying. The base also holds the RBPi, a microphone, a speaker, and other varied components such as a NeoPixel LED Ring and a Speaker Bonnet from Adafruit.

The Storm Glass lamp uses two important arrangements. One of them is the rain maker and the other the cloud generator. The rain maker uses a tiny centrifugal pump working at 5 VDC to pump water via glass tubing into the lid, from where the rain falls. An ultrasonic diffusor/humidifier, also working at 5 VDC, forms the cloud generator. Only the electronics parts of the diffusor, which create the ultrasonic signal, are necessary, and the rest can be discarded. All the equipment goes in together into one spectacular lamp.

By installing Alexa Voice Service within the Storm Glass lamp, and setting it up to use the Weather Underground API to receive data related to weather conditions in a specified place, these conditions are easily recreated within the lamp, functioning as a home automation device.

When taken outdoors, and placed on a nightstand, the Storm Glass can actually recreated he weather conditions outside. It gives a weather forecast for the day by checking the weather periodically online. For instance, if the prediction for the day is rainy, expect some rain to fall within the Storm Glass Lamp. If the predicted says partly cloudy, you will see clouds forming inside, with some sunshine interspersed.

An RBPiZW powers the project, as it needs both Wi-Fi and Bluetooth support. Apart from the Speaker Bonnet, mini water pump, and the ultrasonic diffuser, there is a NeoPixel 12-LED ring, a 2.5 A micro USB power supply, 8 GB micro SD Card, two TIP 120 transistors and two 2K2 resistors. Additionally, you will also need tubing for moving water, lots of hot glue, and the 3-D printed parts to hold all the above together. All the parts operate at 5 VDC, so there is no additional converter, and the RBPIZW controls everything.

Expanding the GPIO on the Raspberry Pi

Although the single board computer the Raspberry Pi or RBPi has nearly 26 GPIO pins in its earlier models and 40 in its latest, there are times when the project demands more of them. In such cases, a GPIO expander is the only solution, and the MCP23S08, a device that Microchip Technology makes provides an easy way to expand the IO pins of a micro-controller using only a 2-wire serial interface.

The MCP23S08 works with the I2C protocol as a slave device, providing 8-bit, general purpose, bi-directional IO expansion for the I2C bus. It supports a 7-bit slave addressing, with the control byte acting as the read/write bit. Of the slave address, the MCP23S08 fixes the four most significant bits to 0100. This leaves the remaining three bits to be defined by the user as the address bits. Therefore, one can connect up to eight MCP23S08 devices on a common I2C bus at any one time.

It is possible to configure individual bits of the 8-bit GPIO port as either input or output. At the same time, it is also possible to enable the internal pull-up resistor on the port pins to interrupt-on-change. A set of configuration and control registers control these operations. Each resistor has its own address and its power-on reset value, as listed on the datasheet of the MCP23S08.

The first register is the IO direction register, and controls the direction of the data IO. On setting a bit in this register, its corresponding pin assumes an input direction, and if the bit is clear, its corresponding pin works like an output.

With the input polarity register, the user can configure the polarity of the corresponding GPIO port bits. When he/she sets a bit on this register, the corresponding GPIO register bit stores the inverted value present on that pin.

Interrupt-on-change control register controls this feature for each pin. When the user sets a bit on this register, the corresponding pin becomes capable of interrupt-on-change. Of course, for enabling this feature, the user must also configure the INTCON and DEFVAL registers as well.

Interrupt control or INTCON register controls the manner in which the associated pin value compares for the interrupt-on-change feature. If the user sets the bit, MCP23S08 compares the corresponding IO pin against the associated bit in the DEFVAL register. If clear, the MCP23008 compares the corresponding IO pin to its previous value.

The default comparison value or DEFVAL register is for configuring the default comparison value. If the user enables a bit in this register, and the associated pin has an opposite value, it will cause an interrupt.

The PI-SPI-DIN series of IO modules has the RBPi reading 2 modules of eight isolated digital inputs for a total of sixteen inputs and controlling four modules of four relay outputs for a total of 16 relays, all using the IO expander chip MCP23S08.

As the RBPi can select only two chip-select lines, each of the PI-SPI-DIN modules has a jumper selection of five chip selects. The two address lines of the MCP23S08 need to be enabled in the setup routine while determining the port pins as inputs or outputs.