Category Archives: Raspberry Pi

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.

Audio HAT for the Raspberry Pi Zero

The Raspberry Pi Zero (RBPiZ) and its successor, the Raspberry Pi Zero Wireless (RBPiZW) are very small single board computers. The Pi Foundation wanted to keep their cost and size to the low side, so they did not include either a 3.5 mm audio jack or any other audio port. Although this may seem like a setback for many users, some of them were went ahead and figured out how to get audio out of the board with a little hacking.

Another reason for not including an audio port is the Broadcom chipset used for the RBPiZ and RBPiZW does not have a true analog output. Instead, there are two pulse width modulated (PWM) pins that spew out digital output at very high speeds. To get audio out of these two PWM output pins, one has to filter the signal to the audio frequency range. This allows one to fake an audio signal by adjusting the duty cycle of the PWM pins.

According to physicists, for simulating any analog frequency from a PWM signal, the PWM frequency should necessarily be at least ten times higher than the highest frequency to be replicated in the analog range. As the audio signals humans can hear range from 20 Hz to 20 KHz, the minimum PWM frequency should ideally be about 200 KHz. However, the PWM output from the two RBPis is 50 MHz, so we can comfortably filter out the audio part while suppressing the higher frequencies.

The schematic of the audio HAT for the RBPis shows that the two stereo audio channels, left and right, are designated as PWM0_OUT and PWM1_OUT. On the PWM0_OUT, R21 and R20 are two resistors acting as a voltage divider to bring down the 3.3 V signal to about 1.1 V peaks. The corresponding voltage divider on the PWM1_OUT is formed of R27 and R26. Therefore, the stereo audio line level can give an output of 1.1 V peak-to-peak.

The RC low-pass filter that prevents the high frequencies from passing through is made up of capacitors C20 and C26, working in conjunction with R21 and R27 respectively. With the values of the components used on the board, the cut-off frequency for this RC low-pass filter is 17865 Hz, which is very close to the upper limit of audio frequencies, or 20 KHz.

That still leaves the DC voltage part of the signal on the lines, and one must remove it to prevent damage to any speakers or headphones subsequently connected to them. This is done by capacitors C48 and C34, which allow only AC part of the signal to pass through, and block all DC voltages.

As the PWM pins are being taken to the outside of the board, one must also protect the RBPi from ElectroStatic Discharge (ESD), which can travel back and destroy the RBPi. This is taken care of by ESD protection diodes.

All the above sounds very good and simple, but on the RBPi, the actual PWM0 signal on pin #40, and the PWM1 signal on pin #45, are not available, as they have not been terminated into exposed pads. To circumvent this problem, the PWM0 signal has to be rerouted through software to GPIO pin #18, and the PWM1 signal to GPIO pin #19.

Talk to your Raspberry Pi

The Raspberry Pi Foundation has tied up with Google for a project called the Artificial Intelligence Yourself or AIY. This is a Hardware on Top or HAT project for the Raspberry Pi 3 (RBPi3) to transform the single board computer into a virtual assistant. This is the first time that Google is offering something exclusively for hobbyists, and the kit comes free with the printed issue 57 of the MagPi—the official magazine of the Raspberry Pi.

The kit with the MagPi magazine consists of a Voice HAT board, a speaker, a stereo microphone board, a large arcade push button, and a set of wires. This is all one needs to add-in voice integration to the RBPi3, turning it into a personal Alexa alternative. Alexa is an intelligent personal assistant developed by Amazon. Intelligent personal assistants are capable of offering real time information, such as news, traffic, weather, apart from playing audiobooks, streaming podcasts, setting alarms, making to-do lists, playing back music, and most importantly, capable of voice integration.

The MagPi magazine contains all the build instructions for putting together the free hardware voice kit; you only need to add the RBPi3 to get it working. There is also a custom cardboard case to house the entire kit along with the RBPi3. Apart from the RBPI3, the AIY voice project will work with an RBPi2 and an RBPiZW as well. Once the hardware is assembled, you will need some software setup, with access to the Google Assistant SDK and Google Cloud Speed API.

The MagPi 57 issue offers several voice integration ideas for the AIY voice kit and you can enhance them or build your own projects. For instance, you can have a voice integration project to answer all your questions just as Alexa does. Alternately, you can create a voice-controlled robot. In fact, some owners of RBPi are building secret AIY projects at Hackster.

According to Billy Rutledge, Google’s director on the project, the AIY project demonstrates a practical method of starting and running a natural language recognizer in conjunction with the Google Assistant. Not only will you have all the functions of the Google Assistant, you can as well add your own pairs of questions and answers.

The Voice Kit and RBPi3 combination acts as a voice recognizer and uses the Google Assistant SDK to recognize speech. For evaluating local commands, it uses a local Python application. You can talk to the Google Assistant, which makes use of the Google Cloud Speech API to answer back. If you wish to use voice capabilities in your future projects, check out the Maker’s guide for more creative extensions.

The arcade style button has additional functions other than initiating the speech interaction. A bright LED mounted within the button signals to verify your device is running properly through different types of blinking. For instant, the LED pulses to indicate the device is just starting up, and the voice recognizer has not started functioning yet. Once the device is ready to be used, the LED blinks every few seconds. The LED glows steadily when the device is listening, and pulses if the device is thinking or responding.