Projects

Raspberry Pi Project 02 – Ad Blocking DNS and DHCP

Raspberry_Pi_LogoI’ve been at a bit of a loss for a while on what to do with my RaspberryPi B+.  I have a B+ and two RaspberryPi B 2s.  The B2s are so much more useful and powerful than the B+ that the poor B+ has kind of been tossed to the wayside.  I was using it as a server for ZNC, an IRC Bouncer.  When I set up my milti-monitor set up, I tried running X-Chat on the B+ with ZNC but the lag was too much.  I’m not sure if the load was from XChat or from ZNC or from Synergy, but the short of it is, the B+ wasn’t useful to my array of machines and needed a headless activity assigned to it.

Sure, I could let it continue to run ZNC, but dedicating two Pis to IRC seems like overkill, so I moved ZNC to the B2 that I run Xchat on and freed the B+ for whatever I wanted.

Pi-Hole for DNS

I started out by setting up Pi-Hole.  It has a fancy name and is simple to install, but at the core, Pi-Hole is just a DNS server that filters sites based on some predefined public lists.  Specifically, it filters ads.  There is a whole debate to be made on the pluses and minuses of ad filtering, but it is what it is and I’m not getting into that debate here.  Pi-Hole has a white list anyway, for “good ads”.  Mostly, it’s a way to filter on mobile, where it’s not easy to install an ad blocker.

Installing Pi-Hole is as simple as entering the following into the command line over SSH or even on the RaspberryPi itself:

sudo curl -L install.pi-hole.net | bash

Though you will also need to set up the Pi with a static IP and then later point your computer’s DNS records to the IP of the Pi.

On a bit of a side note, DNS is Domain Name Server.  The easy analogy is that it is a phone book to the Internet.  Servers where websites live all have IP addresses assigned in various ways, but in order to keep things simple for humans, these servers get friendly names, like Microsoft.com or Facebook.com.  The DNS is where your computer looks up “Facebook.com” to find out what IP address it’s located at.  In this case, ads come from specific servers and providers, often not related to the core domain.  So Website.com may serve ads from advertiser.org.  With Pi-Hole, your computer looks up both domains when you connect to Website.com, but the RaspberryPi Pi-Hole simply replies “I don’t know where Advertiser.org is located”.  You computer then fetches what it can from Website.com, but displays nothing from Advertiser.org.

ISC-DHCP for DHCP

Sort of tangentially related, I recently changed ISPs.  I went from a 3Mbps DSL to 50Mbps Cable modem.  I keep my home network crazy organized since there are a ton of devices on it.  For every person in my house there are something like 4 devices, and this doesn’t count game consoles, media devices, or my own little IOT devices.  On the old modem, I set up MAC assignments on the router so that wireless devices like my phone, where I can’t assign a static IP, get assigned a specific IP.  I went through and set all of this up on the new modem, but none of the assignments seem to have taken.  I’m not entirely sure why, I have theories, but I’ve instead decided to use this as an excuse to re-purpose my B+ and to learn more about managing a DHCP server.

So what is DHCP.  DHCP stands for Dynamic Host control Protocol.  I mentioned earlier that DNS was the way to connect the firstly domain name to an unfriendly IP address.  DHCP assigns those IP addresses.  Some static devices like routers or desktop computers that never go anywhere can pick and self assign an IP but things like phone that move between networks need to be given a temporary IP address as they come and go.  DHCP handles this.  Every device on a network has a unique IP address, though small networks like the one in your home, all tend to share IP ranges since to the outside world they appear to be one node/thing/device.  DHCP can be used to give out reserved “static like” IPs to these roaming devices though based on the device’s MAC Address.  A MAC Address is a device unique identifier.  For example, when the DHCP server or router sees a specific MAC, it can say “I know you, you get IP 192.168.1.50”.  When a strange device shows up, it will simply say “Here, this time you are 192.168.1.103, which is the next free IP in my pool of IPs”.

The set up for DHCP is a bit more involved than for Pi-Hole.  There is a detailed guide below but I’ll run through the cliff notes version.  There is a lot more that can be done but I’m not going to get super detailed here.  This is essentially for a simple home network with one subnet.  The first steps are to set up and configure the server, it will likely error out in the middle, just keep going with it.

sudo apt-get install isc-dhcp-server

sudo nano /etc/dhcp/dhcpd.conf

This is where it gets a little trickier.  You will need to edit the options in the config file.

option domain-name “your_domain”
option domain-name-servers

Your Domain can be more or less anything really, it’s often just “Workgroup” by default in Windows.  It should be all one word though.  Domain Name Servers are specific however.  If you are using Pi-Hole, set the IP of the Pi running Pi-Hole into this list.  You can add additional DNS servers with a comma between each one, some suggestions, 8.8.8.8, and 8.8.4.4 are Google’s DNS servers.  OpenDNS uses 208.67.222.222 and 208.67.20.220.  It’s a good idea to have more than one in case there are issues.

The only other thing you NEED to set is the ip information and range found under

subnet 10.0.0.0 netmask 255.255.255.0
{ range  10.0.0.1 10.0.0.200;
option routers 10.0.0.254;
}

You will need to replace the IP information in this block.  the subnet should be the first three octets of your network followed by a .0.  The most common ones in a home network are 192.168.1.0, 192.168.0.0, and 10.110.1.0.  The range is the range of IPs to give out.  If you are going to use static IPs, i would recommend setting this range beyond your static IP ranges.  For example, I have a spreadsheet blocking off reservations through 192.168.1.100, I added some extra for my router to serve as a backup DHCP server and set the range on the RaspberryPi as 192.168.1.175 192.168.1.250.  This means, when a device connects, it will be assigned an IP starting at the next available at .175.

The final option is routers, chances are really good that you have only one, and chances are the IP ends in .1 or .254.  This will assign the router IP so that devices know how to get out to the Internet.

If you want to ensure your Pi DHCP server is assigning IPs over anything else on the network (ie your router) you will need to find the line that reads “If this DHCP is the official DHCP server…” and uncomment the line “authoritative”.

Finally at the bottom, there are blocks to assign static IPs using a format like:

host MACHINENAME
{
hardware ethernet MACADDRESS;
fixed-address FIXED_IP_YOU_WANT_TO_ASSIGN;
}

An easy way, if you are running Windows, to find out MAC addresses of devices is to run Netscan.  This will give you a list of everything connected to your home network.  There are a few ways to decipher which IP/MAC is which.  Some will have the MAC printed on them, often near the network port.  In the case of phones or tablets, it’s simplest to simply disable the WiFi or turn them of and rescan to see which disappears.  Some may show up with names you may recognize.  You can also sometimes search for the first 3 sets of numbers (IE 45:3b:a3) which is manufacturer specific to decipher that “That’s a Sony device, the only Sony thing I own is the Blu Ray player”.

Setting reserve assignments is entirely optional.  The main purpose is to better organize your home network.  If you only have a half dozen devices, it really probably isn’t necessary at all.

Once you are done editing, CTRL+O (for Output) to save the file, and CTRL+X to close it. If you get an error that you can’t write the file then you forgot to do a”sudo” and you will need to do it all over again.

Wrap Up

Things are not quite finished yet.  You will need to start the DHCP server, since it error-ed out earlier.  You can do this using the following commands:

service isc-dhcpd-server stop
service isc-dhcpd-server start

HOWEVER, I still got an error when I did this.  A little searching and I found a similar issue and fix which I used.

sudo pico /etc/default/ifplugd

Then change this:

INTERFACES=”auto”
HOTPLUG_INTERFACES=”all”
ARGS=”-q -f -u0 -d10 -w -I”
SUSPEND_ACTION=”stop”

To match this:

INTERFACES=”eth0″
HOTPLUG_INTERFACES=”eth0″
ARGS=”-q -f -u0 -d10 -w -I”
SUSPEND_ACTION=”stop”

then reboot and after the reboot start the server with:

sudo reboot

service isc-dhcpd-server start

Everything should be working now.  You can run Netscan later and see if IPs are being assigned into the range you chose.  This may not happen immediately since IPs have a lease time and devices may hold on to the old IP for a bit.

Reference:

Pi-Hole

Configuring the Raspberry Pi as a DHCP Server under Raspbian Wheezy

How To : Use The Raspberry Pi As A Wireless Access Point/Router Part 3…B!

Pushing Arduino Data to MySQL via PHP Part 2: The Server

tempdataIn the last post, I talked about how to send data from the Arduino to the MySQL server.

Today, I’ll cover how I’m receiving and displaying that data on the server side.  I’ll put the code for the webpages into this post but I’ll put everything together in a nice little package at the end of everything.  I mentioned last post that the end trick was to let the server worry about processing the data instead of the Arduino.  I’m running this on my NAS but it could be run on any standard web server with PHP and SQL.

For the purposes of this code, I’ve placed the files in a directory called “temps” on the root of the web server.  If you want to put them elsewhere, such as “temperaturelog” or “home/temps” or wherever, you’d need to alter the code of the Arduino in the previous points to replace the temps directory with the directory you plan to use.  I’m going to assume that the reader has a basic LAMP (Linux, Apache, MySQL, PHP) stack style server and knows the basics of how to create databases and run things on it.  If not you can Google the basic set up, though I may do a quick write up and reference it here eventually.

You’ll need to create a database called “housetemps” and import the linked structure file into it.  (If you know what you’re doing in PHP you can rename housetemps)   This will create a table int he database called “temperature” with the following columns: id, event, sensor, celsius, humidity, datestamp.  This will give you the basic structure needed to run the php code on the server.  A quick rundown of what these values are used for…

  • id – A standard auto incriminating id value for SQL
  • event – Time and date of when the event happened
  • sensor – A text based identifier for each probe.  This example uses one probe but could be altered for more.
  • celsius – The temperature reading, it doesn’t actually have to be Celsius, that’s just the default of the probe.
  • humidity – Humidity reading in percent humidity
  • datestamp – A date only time stamp, used for sorting the data when you review it later.

Now that you have the core database structure set up, the server needs to know the credentials for connecting to the database.  Since this is used by several files, it’s best to put the info in it’s own file and use an include statement int he PHP to add it.

In the “temps” directory create a file dbconnect.php and add int he following code, changing the values listed for the values used when setting up the database…

<?php
$MyUsername = “USERNAME”;  // enter your username for mysql
$MyPassword = “PASSWORD”;  // enter your password for mysql
$MyHostname = “localhost”;      // this is usually “localhost” unless your database resides on a different server

$dbh = mysql_pconnect($MyHostname , $MyUsername, $MyPassword);
$selected = mysql_select_db(“housetemps”,$dbh);
?>

Next you’ll need a way to get data into the table.  This is done using add_data.php, which is called by the Arduino in the code shown previously.

Make a file in the “temps” directory called add_data.php, and add the following code.

<?php
// Connect to MySQL
include(‘dbconnect.php’);

{
$dateget = date(“Y-m-d”);
// Prepare the SQL statement
$SQL = “INSERT INTO housetemps.temperature (sensor ,celsius, humidity, datestamp) VALUES (‘”.$_GET[“serial”].”‘, ‘”.$_GET[“temperature”].”‘, ‘”.$_GET[“humid”].”‘, ‘$dateget’)”;

// Execute SQL statement
mysql_query($SQL);
}

// Go to the review_data.php (optional)
header(“Location: review_data.php”);
?>

The code is pretty straight forward. The first section includes our previously created log on credentials.  The last section forwards the page on to review the data.  The meat is in the middle with the SQL statement.  The line $dateget = date(“Y-m-d”); creates a Year-Month-Day date for sorting later.  The next line creates the SQL query using variables passed via the url, the third part executes this query adding the data to the database.

The final piece of this whole thing is the review_data.php file.  This file displays the results in a nice looking table.

<?php
// Start MySQL Connection
include(‘dbconnect.php’);
?>

<html>
<head>
<title>Arduino Temperature Log</title>
<style type=”text/css”>
.table_titles, .table_cells_odd, .table_cells_even {
padding-right: 20px;
padding-left: 20px;
color: #000;
}
.table_titles {
color: #FFF;
background-color: #666;
}
.table_cells_odd {
background-color: #CCC;
}
.table_cells_even {
background-color: #FAFAFA;
}
table {
border: 2px solid #333;
}
body { font-family: “Trebuchet MS”, Arial; }
</style>
</head>

<body>
<h1>Arduino Temperature Log</h1>

<p>Select Date:
<?php

$sql = “SELECT DISTINCT datestamp FROM temperature”;
$result = mysql_query($sql);

echo “<select name=’datestamp’ onchange=’location = this.options[this.selectedIndex].value;'”;
while ($row = mysql_fetch_array($result)) {
$current = $row[‘datestamp’];
echo “<option value=’review_data.php?dateselect=$current’>$current</option>”;
}
echo “</select>”;
?>

<table border=”0″ cellspacing=”0″ cellpadding=”4″>
<tr>
<!–    <td class=”table_titles”>ID</td> –>
<td class=”table_titles”>Date and Time</td>
<td class=”table_titles”>Sensor Serial</td>
<td class=”table_titles”>Temperature in Celsius</td>
<td class=”table_titles”>Percent Humidity</td>
</tr>
<?php
// Retrieve all records and display them
$SQL = “SELECT * FROM temperature WHERE datestamp LIKE ‘”.$_GET[“dateselect”].”%’ ORDER BY id ASC”;

//Execute the SQL
$result = mysql_query($SQL);

// Used for row color toggle
$oddrow = true;

// process every record
while( $row = mysql_fetch_array($result) )
{
if ($oddrow)
{
$css_class=’ class=”table_cells_odd”‘;
}
else
{
$css_class=’ class=”table_cells_even”‘;
}

$oddrow = !$oddrow;

echo ‘<tr>’;
//       echo ‘   <td’.$css_class.’>’.$row[“id”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“event”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“sensor”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“celsius”].'</td>’;
echo ‘   <td’.$css_class.’>’.$row[“humidity”].'</td>’;
echo ‘</tr>’;
}
?>
</table>
</body>
</html>

The core of this file was lifted from the previously mentioned guide on Tweaking4All.  The problem I had with their results was that it simply displayed an endless list.  I am polling every 15 minutes, so this list tends to grow unwieldy very quickly.  This is where the datestamp marker comes into play.  I added this little chunk of code at the top of the table.

<?php

$sql = “SELECT DISTINCT datestamp FROM temperature”;
$result = mysql_query($sql);

echo “<select name=’datestamp’ onchange=’location = this.options[this.selectedIndex].value;'”;
while ($row = mysql_fetch_array($result)) {
$current = $row[‘datestamp’];
echo “<option value=’review_data.php?dateselect=$current’>$current</option>”;
}
echo “</select>”;
?>

This creates a menu based on unique values of datestamp.  Selecting a value forwards you to review_data.php with a date attached, then review_data.php only shows data that matches that datestamp.  This allows a single day to be viewed easily.  In the future I may add a bit more to this menu, eventually, the list of dates will also become unwieldy in length.  I also plan to run numerous sensors at once with different names so I’ll likely also add a second menu so the list can be sorted down by sensor name.

I’m also looking to add a bit more functionality to the code in the form of a graph, so it will be easier to see trend lines in the data.  The data I have now is from my office, in a well insulated basement room, so the trend lines are rather boring, but when there are several sensors in different rooms in the main area of the house, or even outside, this data becomes more interesting and useful.  I’ll go into this at a later day though…

 

 

Arduino: Cheap Sensors Cheap Results…

Temperature and Humidity SenorsI mentioned last post I had ordered some cheap Temperature and Humidity Sensors for my Arduino boards.  Well they came in, and so I got to do some nice experimenting with code to test them out.  I already had a bit of code from the DHT Test Sketch (Arduino programs are called Sketches) that would poll one sensor and display the results over serial.  Sort of the ultimate goal here is potentially running several fo these sensors around the house and polling them to gather temperature data and store it in a data base that can be accessed via the web.

The first step is getting a Sketch that would poll each sensor and output the result over the serial monitor, preferably with labels.  I started out cutting and pasting the original single sensor code repeatedly and altering the pin before realizing a loop would be way more efficient for this task.  After some fiddling I came up with the following Sketch which polls pins 2-7 sequentially in 2 second intervals and outputs the data to the serial monitor.  This code requires the basic DHT includes from the DHT library.

//
//    FILE: Six Sensor Temp/Humidity Probe.ino
//  AUTHOR: Josh Miller
// VERSION: 0.1.00
// PURPOSE: DHT library based sketch for multiple Temp/Hum probes on Arduino
//     URL: http://www.joshmiller.net
//
// Released to the public domain
//

#include “dht.h”

dht DHT;

void setup()
{
Serial.begin(115200);
Serial.println(“Multi Sensor Temp/Humidity Readings”);
Serial.println(“Version 1.0”);
Serial.println(“Modified DHT Library Version”);
Serial.println(“By Josh Miller, josh@lameazoid.com”);
Serial.println();
}

void loop()
{
int i=1;

while (i<7)
{
// READ DATA

int chk = DHT.read11(i+1);
switch (chk)
{
case DHTLIB_OK:
Serial.print(“\t”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print(“Checksum error,\t”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print(“Time out error,\t”);
break;
default:
Serial.print(“Unknown error,\t”);
break;
}
// DISPLAY DATA
Serial.print(“Probe “);
Serial.print(i);
Serial.print(” : Humidity is: “);
Serial.print(DHT.humidity, 1);
Serial.print(“, Temperature is: “);
Serial.print(DHT.temperature, 1);
Serial.println(” C “);

i++;
delay(2000);
}

}
//
// END OF FILE
//

Arduino with 6 Senors...I don’t have my Network Shields yet so I can’t play around with getting these numbers to dump into an SQL database (probably one running on my NAS) just yet.  This basic proof of concept though is great since it allowed me to learn some code and test the basic functionality of the sensors.  This code can be modified for any number of sensors by changing the “while (i<7)” line to “while (i<# of Pins/sensors Used)”.

Wiring up the bread board was also a bit of a tricky task, mostly because of the sheer number of connections being made.  Each sensor gets a +Voltage and Ground connection off the bus bar and a wire from the senor.  The new cheap sensors use a different pin out from my “official” expensive senor, not really a problem, but something to look out for.

After wiring everything up, I could plug the Arduino into my laptop and open the serial monitor on the appropriate baud rate and record the results.  The results are actually a bit worrying but further testing will be needed to verify the integrity of the results…

Multi Sensor Temp/Humidity Readings
Version 1.0
Modified DHT Library Version
By Josh Miller, josh@lameazoid.com

Probe 1 : Humidity is: 58.0, Temperature is: 25.0 C
Probe 2 : Humidity is: 46.0, Temperature is: 27.0 C
Probe 3 : Humidity is: 41.0, Temperature is: 29.0 C
Probe 4 : Humidity is: 40.0, Temperature is: 26.0 C
Probe 5 : Humidity is: 35.0, Temperature is: 30.0 C
Probe 6 : Humidity is: 36.0, Temperature is: 32.0 C
Probe 1 : Humidity is: 58.0, Temperature is: 25.0 C
Probe 2 : Humidity is: 46.0, Temperature is: 27.0 C
Probe 3 : Humidity is: 41.0, Temperature is: 29.0 C
Probe 4 : Humidity is: 40.0, Temperature is: 26.0 C
Probe 5 : Humidity is: 35.0, Temperature is: 30.0 C
Probe 6 : Humidity is: 36.0, Temperature is: 31.0 C
Probe 1 : Humidity is: 58.0, Temperature is: 25.0 C
Probe 2 : Humidity is: 46.0, Temperature is: 27.0 C
Probe 3 : Humidity is: 42.0, Temperature is: 29.0 C
Probe 4 : Humidity is: 40.0, Temperature is: 26.0 C
Probe 5 : Humidity is: 36.0, Temperature is: 30.0 C
Probe 6 : Humidity is: 37.0, Temperature is: 30.0 C
Probe 1 : Humidity is: 58.0, Temperature is: 25.0 C
Probe 2 : Humidity is: 46.0, Temperature is: 27.0 C
Probe 3 : Humidity is: 42.0, Temperature is: 29.0 C
Probe 4 : Humidity is: 40.0, Temperature is: 26.0 C
Probe 5 : Humidity is: 36.0, Temperature is: 29.0 C
Probe 6 : Humidity is: 37.0, Temperature is: 30.0 C
Probe 1 : Humidity is: 58.0, Temperature is: 25.0 C
Probe 2 : Humidity is: 46.0, Temperature is: 27.0 C
Probe 3 : Humidity is: 43.0, Temperature is: 28.0 C
Probe 4 : Humidity is: 40.0, Temperature is: 26.0 C
Probe 5 : Humidity is: 36.0, Temperature is: 29.0 C
Probe 6 : Humidity is: 38.0, Temperature is: 30.0 C

Probe 1 is the official sensor, the one that cost me $10, the other 5 are cheap probes, they cost me like $9 total.  I have to assume that Probe 1 is pretty accurate and probably has gone through some quality testing before being sold.  The other 5, for all I know, are rejects that were swept off of some floor in China by the janitor.  The point is, all of the readings of the cheap sensors are pretty off from each other, especially the humidity.  This may actually be the case if these sensors were in separate rooms or even any distance from each other, however, these senzors are all within a few centimeters of each other on the same bread board.

There may be a few things happening here causing this discrepancy, and I only say this because they are at the very least consistent with themselves.

One, it’s possible, that there isn’t enough juice to run all of the sensors at once.  If they are being under powered, I would likely get bad readings.  I can easily test this by running each sensor independently with the old single probe Sketch.

Two, it’s possible that while no accurate to each other, they are accurate to themselves.  I don’t really know what these numbers actually mean, I am assuming % Humidity and Degrees C.  It may be some sort of internal scale factor and I simple need to adapt the program to return scaled results.  The issue with this will be that each probe is polled in a loop, so there isn’t really an easy way to apply a different scale factor to each sensor individually.

Whatever the case, the Temperature is at least semi precise, which is what I care more about anyway.  I’ll probably continue with the project with the idea that if I really want accurate results I could eventually invest in better sensors.  The next step on the software end will be to add network functionality to record the data.  On the hardware end I plan to use some CAT5 wire to allow the probes to be positioned in various places beyond just the Bread Board.

OSEPP Arduino Starter Kit

Arduino and a Raspberry Pi 2BSo, a month or so ago, while traveling for work, I was bored in the hotel room and found out there was a Fry’s Electronics around the corner from the hotel. I decided to pop in and look around and see if I could find anything interesting. I also wanted to see how much Raspberry Pi 2B boards were there (and if they were comparable to Amazon.) They had a couple of Pis, a large selection of basic electronic components and a pretty decent selection of Arduino shields and parts.

I’d been looking into getting an Arduino for a while and decided what the hell. There may have been single packed Arduino boards but I really couldn’t tell from the cards which was the base board an which was just an add on shield. I ended up with the OSEPP Arduino Basic Starter Kit.  Honestly, since I hadn’t ever used an Arduino, I didn’t own an Arduino, and I had some basic but not super amazing electronics skills, this really was the best choice.

The kid includes a lot of nice basic parts as well as a guide book to get you started using these basic parts.  The box itself promotes the major projects of “Volt Meter”, “LED Game” and “Electronic Buzzer”.  It also runs through the basics of lighting up some LEDs.  The tutorials are decent though I wish there was a little more on the basics of how to work the bread board and the little wires.  It’s not hard to figure out, but it also isn’t super self explanatory if you didn’t have any experience with electronics at all.  the Volt meter tutorial is less exciting than hoped and the Buzzer just runs up the music scales but it could be modified to play a tune using the little piezo buzzer.

WP_20150630_09_21_48_ProThe LED game is neat, but simple.  You make the lights flash in sequence and you must press the button when the appropriate light is flashing, which causes the lights to flash faster.  There is also a 7 segment LED in the kid, which you make count down from 9 to 0.  This actually has a lot of fun potential and I have some ideas for it but I need to figure out how to light up both numbers to display a number (such as say, a temperature).

After exhausting the fun of the starter manual, on my next trip to the area, I bought a temperature and humidity sensor and wired it up.  This was a bit trickier since it required figuring out how to find and download the necessary libraries and modifying the code a bit to get it to read properly.  In the end, I managed to get things working though, which was kind of great since the AC in my hotel room didn’t have a digital read out, so I could know exactly how cold it was and why I was either freezing or sweating.

So, fast forward a bit more again, I’ve got some fun ambitions going and the idea of playing with several Arduino projects.  Unfortunately, while cheap, Arduino boards can add up to expensive.  Unless you buy cheap Chinese knockoffs for $3 apiece off of AliExpress.  I also have some cheap Network boards and temperature sensors coming.  Five boards total, five sensors and two network shields, for around $35, really isn’t too bad of a deal if it all works.

And thus, I have a ton of Arduino boards to play with now.

IMGP5277

 

 

Raspberry Pi Rack

Even before buying any Raspberry Pi computers, I had this sort of vision for neat rack to put several of them in. The idea evolved a bit as the logistics of it got ironed out but after picking up a second Pi (and planning to get a third), I went and built the thing.

Raspberry Pi Rack

Sorry for the mediocre pictures, I didn’t think to take photos until things were running and I didn’t really want to unplug it. It currently holds a Raspberry Pi B+ and a Raspberry Pi2 B, the B+ is running a ZNC server to keep me connected to several IRC channels and the Raspberry Pi 2B is running a small OpenSIM server, though I’ll probably re-purpose it since in testing performance seems to top out at around 2000 Prim cubes and 4 Avatars. The instance I’ve got running on my VPS is much more suitable. On the other hand, it could be a good place to “archive” builds.

Raspberry Pi Rack

The build itself is pretty straight forward. I used (roughly) the following materials picked up at Lowes:

  • 3 pieces of 10×8 plexiglass cut to 5×7 size.
  • 6 6″ #8 thread rods.
  • 8 (2 packages) of #8 rounded caps.
  • 3 packages of #8 nuts
  • 6″ Micro USB cables from Amazon
  • Cat 5 Cable cut and crimped as needed
  • 1 Netgear Switch I had already
  • 1 Choetech 40W Smart power from Amazon.
  • The smaller screws holding the Pis in are 4mm i believe, and it took two packages of them (16 screws and 32 nuts).

The hardest part was working with the Plexiglass pieces. I could have cut it with the Dremel but the edge would have been all crooked for sure. Instead I scored and snapped them, which did leave a jagged edge on one edge but it could easily be sanded off. On a starting note, the Plexiglass comes with a plastic protective layer, this should be left ON until final assembly to protect the clear surface as much as possible.

Anyway, to cut the sheets down, I used a square and a box cutter to but a line where I wanted the break to be on one side, then clamped the sheet down on the edge of the workbench between the surface and a 2×4. The 2×4 was mostly to help protect the surface of the plexiglass from the clamps. The cut edge should be on the up side, right at the edge of the surface and the 2×4 (or whatever) at the edge on top. The Plexiglass should snap more or less cleanly off. I had some small chips left hanging on the shorter 1″ breaks to shorten the shelves to 7″ from 8″. I used a small hammer while the pieces was still clamped down to chip these down a bit.

The real trick was drilling the holes. In the end, I found the best results came from clamping all of the plastic sheets together between some boards and drilling them all at once. There should be a piece of wood completely covering the bottom of the drilling spot to help support the plexiglass as the drill penetrates through.

I had some trial and error trying to drill my sheets separately, so the holes are not perfect. For the mounting holes I laid the Pi itself where I wanted it and uses a pen to mark the holes. I probably could have done a bit better with a paper guide though.

Assembly was pretty easy, just a lot of tedious screwing of nuts as the thread rods were fed through the holes. Each shelf takes at a minimum, one nut above and below to hold them in place and the rounded caps go on the top and bottom. The power supply and switch are not mounted, they are simply sandwiched in place between the shelves, though the supporting long bars were positioned around the Switch to prevent it from sliding left or right or backwards.

The Power supply I picked because it has two standard wall outlets on one side. I used the Dremel to cut holes in the top sheet to allow these plugs to be accessible. I wanted the unit to be as self contained as possible, these plugs give me a place to plug the Switch in. It’s important when choosing a power supply that it has enough power on all ports to power a Pi. A USB HUB doesn’t work since it will distribute power across all the ports. Several ports I looked at had 2 “high output” ports for iPads and iPhones but the rest were lower output.

The USB power cables were 6″ jumpers I found on Amazon and the CAT 5 cable were small jumpers I made myself with ends and a crimper. When I add the back two Pis I’ll need different cables though, likely cables with a 90 degree connector and definitely longer ones.

Raspberry Pi Rack

The whole package sits nicely on top of my desktop box next to my Synology NAS.