Skip to main content

Raspberry Pi projects

Basic configuration

Login with the default pi / raspberry user.

Turning on the wifi, GPIO pins (SPI), set boot options, etc:

sudo raspi-config

Making a status screen or kiosk using a Raspberry Pi

Introduction

This section will show you how to easily create a status screen or kiosk using nothing but a spare display and a Raspberry Pi. This assumes you have a web page that you want displayed on that screen, either running on your own server, locally, or some third party web site. It also assumes you already connected the Pi to the display and successfully installed the built-in Raspbian OS (or other distribution of your choice) on the flash card.

Setting up Chromium

First, install the following packages:

  • chromium
  • x11-xserver-utils
  • unclutter

On Raspbian, you can type:

apt-get install chromium x11-xserver-utils unclutter

Next, you need to disable the screen saver in X Window. Edit /etc/xdg/xsession/LXDE/autostart and comment out the screen saver line with a # at the beginning of the line.

Then, add the following lines to the same file:

@xset s off
@xset -dpms
@xset s noblank
@chromium --kiosk --incognito http://www.your-website.com

And that’s it! After you reboot the Pi, it should start Chromium automatically, and go to the specified web site.

Using your Pi as a HomeKit accessory

First, make sure you have Python 3.3+ installed. You can follow this.

Then, install Python-HAP:

pip3 install python-hap

Finally, you can look at this sample script to get an idea on how to script your HomeKit actions, run it then add it to an iOS device using the Home app. The script will play music when turned on, and stop when turned off.

Running old DOS games

The Pi makes a great DOS gaming machine. You can install DOSBox from the official Raspbian distribution:

apt-get install dosbox

After that you need to configure where DOSBox will find your disk drive. It uses a local folder as the C:\ drive. You can also configure the type of screen resolution, memory and commands to run at bootup. The configuration is found in ~/.dosbox/dosbox.conf.

Once that’s done, just copy your DOS games in the folder you configured, and launch DOSBox.

Log DNS queries on your network

Knowing what goes on in your home LAN can be quite useful, from finding out what those pesky IoT devices are connecting to, and if there’s any weird traffic going on. One way to do that is with an expensive router that has packet sniffing capabilities, but a simpler option is to set your Pi as the DNS server in your router’s DHCP options, and then install Bind9 with the logging options set. This way, your Pi will simply forward DNS requests to your server of choice, but will also log every site any device asks for.

The first step is to install Bind9:

apt-get install bind9 bind9utils dnsutils

The second step is to set your forwarding DNS servers by editing /etc/bind/named.conf.options:

forwarders {
        8.8.8.8;
        1.1.1.1;
};

Then, enable logging by adding the following to /etc/bind/named.conf.local:

logging {
    channel queries {
       file "/somewhere/named.log" versions 10 size 100m;
       severity info;
       print-time yes;
    };
   category queries { queries;};
};

Finally, make sure you restart Bind:

service restart bind9

Read and write RFID tags

For this we will use the RC522 RFID reader which is available from a number of vendors on eBay, along with a couple of wires. See this diagram on how to wire the pins. This is how the wired up Pi should then look like:

Once the board is linked up, make sure you enabled GPIO (see above), and then install the RFID Python libraries:

sudo apt-get install python2.7-dev
git clone https://github.com/lthiery/SPI-Py.git
cd SPI-Py
sudo python setup.py install
cd ..
git clone https://github.com/pimylifeup/MFRC522-python.git
cd MFRC522-python

Now, we can write a read script which will read from a card:

#!/usr/bin/python

import RPi.GPIO as GPIO
import SimpleMFRC522

GPIO.setwarnings(False)
reader = SimpleMFRC522.SimpleMFRC522()

try:
    print("Waiting for tag...")
    id, text = reader.read()
    print("\nID: {}\nContent: {}".format(id, text))

finally:
    GPIO.cleanup()

And a write script:

#!/usr/bin/python

import sys
import RPi.GPIO as GPIO
import SimpleMFRC522

GPIO.setwarnings(False)
reader = SimpleMFRC522.SimpleMFRC522()

if len(sys.argv) < 2:
    print("Syntax: {} <text to write to RFID tag>".format(sys.argv[0]))
    quit(1)

try:
    print("Waiting for tag...")
    reader.write(sys.argv[1])
    print("Data written.")

finally:
    GPIO.cleanup()

That’s all! Save the files as read.py and write.py and run the scripts with a RFID tag near the reader.