The GPIO connector is the large group of pins on the edge of your Raspberry Pi board. On earlier models, there were 26 pins that made up this connector. Since the Model B+ there are now 40 pins, although the first 26 pins are identical to the previous models, and it's these 26 pins we'll be working with. You won't need to worry about the rest of the pins.
Essentially, the GPIO connector provides access to:
Power supplies
Digital I/O pins
I2C bus
SPI bus
UART Serial bus
Some of the pins on the GPIO have more than one purpose, depending on how they are programmed. The following diagram is a reference guide to all of the pins on the GPIO. The GPIO numbers on the yellow labels relate directly to those on the Broadcom chip, and are numbers generally used within the scripts:
The GPIO connector also provides access to the onboard power supplies. The +5V connection (pins 2 and 4) is essentially the +5V input from the external power supply connected...
Building a laser trip wire
You may have seen Wallace and Gromit's short film, The Wrong Trousers, where the penguin uses a contraption to control Wallace in his sleep, making him break into a museum to steal the big shiny diamond. The diamond is surrounded by laser beams, but when one of the beams is broken, the alarms go off and the diamond is protected with a cage!
In this project, I'm going to show you how to set up a laser beam and have our Raspberry Pi alert us when the beam is broken— aka a laser trip wire. For this, we're going to need to use a Waveshare Laser Sensor module (www.waveshare.com), which is readily available to buy on Amazon for around £10 / $15.
The module comes complete with jumper wires, that allow us to easily connect it to the GPIO connector in the Pi:
The module contains both a laser transmitter and receiver. The laser beam is transmitted from the gold tube on the module at a...
Sending alerts to your phone using SMS
We saw in Chapter 5, Taking Your Pi Off-road, how to send e-mails from the Raspberry Pi so that we can pick them up on our smartphone. But what if we're in an area where we can't get a good mobile Internet signal? All of our elaborate work to protect our things or get status updates from the field goes to waste because we don't get alerted in time.
SMS (Simple Messaging Service)—or text messaging—actually uses the mobile voice channel to deliver the message to your handset rather than the mobile Internet channel, so you're likely to receive your message in areas of poor reception and where there is no data service.
Use your phone as an access control device
We saw in Chapter 4, Wi-Fi Pranks-Exploring Your Network, how we could use our Raspberry Pi to scan the wireless networks to see what devices are around. Most smartphones come with either Wi-Fi or Bluetooth, or both, on them nowadays, which transmits an identifier unique to that device.
We can take advantage of that by using our phone as an access control device, so our Pi can know when we're nearby and act accordingly. For example, let's say if each time you were near your Pi with your smartphone, it could automatically unlock the encrypted container you set up in Chapter 5, Taking Our Pi Off-Road, and then lock it again when we're not nearby. By constantly scanning for our phone's broadcast packets, we can do this.
When a smartphone is searching for nearby routers to connect to, it will periodically broadcast packets of data called Probe Requests. The Probe Requests contain the unique MAC address of the device and often the name of...
Displaying secret codes and messages
Let's say that you need to leave your fellow agents a message in a particular location, but you don't want anyone else to know what it contains. You could write the encoded message on a piece of paper so it could be decoded by hand, but it would be much more convenient to show the encoded message electronically on a display, so it can easily be changed—even from a remote location.
For this project, we're going to use Ciseco's Pi-Lite board, which sits on top of the Raspberry Pi, plugged into the GPIO connector. It features a matrix of 126 LEDs combined with a small microcontroller enabling the device to be easily programmed using the Pi's serial port:
Before we can access the serial port we need to enable it for our own use on the Pi, as by default, it's used for the terminal console. Fortunately, this is now straightforward on the latest Raspbian releases:
Launch the Raspberry Pi configuration...
Better security with a true random number generator
We looked at encryption in the section Keeping your conversations secret with encryption in
Chapter 4, Wi-Fi Pranks - Exploring Your Network;
however, the key to secure cryptography is entropy—a high-quality source of randomness.
Most random numbers used in computer programs are pseudo-random, which means they are generated in a predictable manner using mathematics. In many circumstances this is fine, but for strong cryptography, this is may not be suitable, even with a good random seed, so we need a True Random Number Generator (TRNG).
Usually, this requires expensive hardware, or weird physical events such as noise analysis to generate random number using a high level of entropy. But did you know that your Raspberry Pi—including the Pi Zero—also contains a hardware-based TRNG?
In the Linux environment, the root of all randomness is something called the kernel entropy pool. This is a 4,096-bit secret number stored in...
We kicked off our final chapter with a guide to the Raspberry Pi's GPIO connector and how to safely connect peripherals to it. We followed that up by connecting a laser sensor module to our Pi to create a rather cool laser trip wire that could alert you when the laser beam is broken.
Following along the same theme, we also connected a passive infrared motion detector to our Raspberry Pi, which observed an area of space and detected when our space had been infiltrated.
Because we may not always have an Internet connection to our smartphone when out in the field, we extended our methods of being remotely alerted to include SMS, using a few simple lines of script which connected to the API of an SMS gateway service.
Moving away from protecting our space to protecting our digital assets, we looked at a way for our Pi to know when we're in the vicinity, with a script that scanned for the Wi-Fi address of our personal phone, which if found, could then do something, such as unlocking our encrypted...