Case for Raspberry Pi printed with MakerBot Replicator 2


Being able to cheaply produce 3D prototypes makes MakerBot Replicator amazing. We recently acquired a Replicator 2 at work, which we used to print a case for Raspberry Pi Model B Rev 2. Here’s the result.

Open

Here’s some lessons learned:

  • I had a hard time fitting Raspberry Pi into the case. I had to use a box cutter to make several adjustments. I was wishing I had a Dremel.
  • I wanted a transparent case, but the printed case is quite opaque. So much so that it is hardly possible to make out which LEDs on the board are lit (see image below).
  • It took above an hour to print each half of the case. Be prepared to let the printer do its work for a good few hours.
  • The final finish is rough to touch, it appears neatly textured though.
  • The case becomes warm to touch after running Raspberry Pi continuously for a day or so, without much CPU load. At 30% CPU load, held for two hours, temperature within the case rises to 35 °C, CPU/GPU temperature to 60 °C, at an ambiente temperature of 26 °C.
  • We have had our Raspberry Pi reboot spontaneously due to RF interference. We’ll probably need to go for a metallic case.

Closed

Despite all the hard work, a case such as this would have taken us much longer to prototype in the past.

Prototyping a PCB using LPKF ProtoMat S62


The last time I designed my own PCB, in 1995, I used parchment (butter) paper and stickers. The fabrication was contracted out to a third-party. Times have changed, we now have simple circuit design software such as Fritzing, and rapid PCB prototyping machines such as the LPKF ProtoMat S62. Though the latter doesn’t come cheap, it is totally worth it.

The PCB I designed is very simple, and contains only through-hole parts. It is a custom breakout for the Raspberry Pi Model B Rev 2. I found most components in the Fritzing library. The Raspberry Pi component was obtained from the Adafruit Fritzing library at GitHub (AdaFruit.fzbz).

Fritzing Breadboard

This is how the breadboard view looks.

Fritzing Breadboard View

Fritzing Schematic

The schematic after some cleanup looks like this.

Fritzing Schematic View

Fritzing PCB

The two-sided PCB after some work looks like this. I let Fritzing autoroute traces, and then fixed whatever issues its DRC (design rules checker) brought up.

Fritzing PCB View

The prototyping environment lacks PTH (plated through hole) capability. Although holes are drilled, we are unable to deposit copper through holes and vias. To enable easier soldering, I moved traces leading away from the header to the top PCB layer. Since the header is placed on the bottom layer, I would only be able to solder its pins on the top layer.

PCB Milling

Milling was carried out by a colleague at work, who’s trained herself to use the ProtoMat S62 and its accompanying software such as CircuitCam and BoardMaster. She used the Gerber (RS-274X) files I exported using Fritzing.

This is the kind of machine that was used.

ProtoMat S62

Here’s how the finished PCB looks (bottom layer appears first).

PCB bottom

PCB top

Assembled PCB

Here’s the PCB with most components soldered.

PCB bottom

PCB top

Some components are soldered on both sides because they pass signals from one layer to another. As mentioned earlier, we lack PTH capability.

I have a lot to learn about PCB designing and the ProtoMat S62, but it’s a start.

Virtual serial port redirection on Windows 8


Virtual serial ports are a convenient way to test software that accesses hardware over serial ports, particularly when that hardware is not available yet. They can also be useful for logging and tracing purposes.

I maintain a simple tool that allows me to open serial ports, and send and receive data. It is developed using C# and works reasonably well on Linux with Mono. That is the tool I used to test the different redirectors described below.

Free Virtual Serial Ports

Free Virtual Serial Ports version 2.11 by HHD Software works on Windows, right up to version 8.1 64-bit. It is easy to create two bridged serial ports, where data sent to one port arrives at the other and vice-versa. I also love Free Hex Editor Neo by HHD Software.

HW VSP3

HW VSP3 version 3.1.2 does serial to TCP redirection. It requires a TCP server at the other end. One way to set that up is to use ncat utility that accompanies NMAP. I have had the need to play with TCP so often, I have rolled my own little tool.

I found that HW VSP3 sends additional data when a connection is established. It also tended to corrupt data during large transfers. It works all right for small controlled tests.

Paid options

Commercial options that are popular are Virtual Serial Port Driver by Eltima, and Virtual Serial Port Kit by FabulaTech.

Mac OS X tips


This is an ever expanding list of tips for Mac OS X. Leave a comment below if you have tips of your own to share.

Go to a folder in Finder

Hit Command-Shift-G and type in or right click and paste the folder path.

Go to a folder in Terminal from Finder

Start Terminal. Type “cd ” without quotes. Drag folder from Finder (or its status bar) to Terminal. You can also open Terminal directly from Finder. Head over to System Preferences, Keyboard, Shortcuts, Services, and enable New Terminal at Folder and/or New Terminal Tab at Folder. Selected option will appear under the Services context menu of an item in Finder when you right click on it.

Goto to a folder in Finder from Terminal

Type the command

open .

Connect to WiFi and continue using your wired internet connection

Head over to System Preferences, Network, Set Service Order, and raise Thunderbolt Ethernet (or any other interface) above WiFi.

Live webcam feed in a web meeting

To show a live webcam feed on your screen, try Photo Booth (comes preinstalled). Most off-the-shelf USB webcams work just fine with Mac OS X and Photo Booth.

Combine multiple PDF documents

You can use to Preview to combine multiple PDF documents, rearranging and leaving out pages you don’t need…

Go to folder in Spotlight Search

Once you’ve searched for the document and it is highlighted, keying Enter will open the document, keying Command+Enter will take you to the folder where the document is located.

Keyboard Shortcuts

Fn+F11 reveals the desktop. Useful to quickly drag some files on to the Desktop or vice-versa.

The Linux Programming Interface by Michael Kerrisk; O’Reilly Media


The Linux Programming Interface is a very extensive tome on the ins and outs of the Linux (nay Unix) system programming interfaces, from the maintainer of the Linux man-pages project. The book covers everything from the a.out (assembler output) format to zombie processes.

At more than 1500 pages long, it is not a book to read from cover to cover. As each chapter is fairly self-contained and covers a single topic thoroughly, I recommend diving into the book every time a topic tickles your fancy.

You stand much to gain by reading about a topic in the book rather than only perusing man pages. For instance, the topic on processes shows where the environ global variable points to in a process’s memory layout, describes the environment list data structure, and presents an example showing how to access the environment variables. Much more than you get from “man environ” on the command line.

The book’s 64 chapters cover every Linux programming topic I can imagine. Its breadth does mean that it is shallow on some occasions. I have had need to use, and blogged about, TCP keepalive before, a topic that does not occur in the book. To its credit, it is peppered with references to other books and articles that cover a topic in depth.

Definitely a book I’ll dive into every time I need to use a Linux programming interface I have never used before. I thank O’Reilly media for providing me an e-book to review.

Driving an LED with a Raspberry Pi


I recently began tinkering with a Raspberry Pi Model B rev2. This post shows how you can drive an LED using the GPIO pins on a Pi running Raspbian. If you are unfamiliar with Pi take a look at their quick start guide.

GPIO Pin Numbering

There are two ways to specify the GPIO you want to control. One is based on the numbering of the pin on the P1 connector, the other is based on the Broadcom SOC (BCM2835) GPIO numbering. For instance, pin 12 on P1 connector corresponds to pin GPIO18 on BCM2835.

This can be derived from the screenshots of the schematic below, and is also documented elsewhere on the internet for easier consumption.

P1

BMC2835

RPi.GPIO Python module

The RPi.GPIO module is available on Raspbian. Let’s assume you connect the LED as shown below. I have come to realize that the current driven by GPIO is low enough, that you can drive the LED shown without need for a resistor in series.

Driving a LED using Pi (Fritzing)

This is how you can blink an LED using P1 connector pin numbering, on the command line.

sudo python
import RPi.GPIO as gpio
gpio.setmode(gpio.BOARD)
gpio.setup(12, gpio.OUT)
gpio.output(12, gpio.HIGH)
gpio.output(12, gpio.LOW)

This is how you do the same thing using BCM2835 GPIO numbering.

sudo python
import RPi.GPIO as gpio
gpio.setmode(gpio.BCM)
gpio.setup(18, gpio.OUT)
gpio.output(18, gpio.HIGH)
gpio.output(18, gpio.LOW)

The project Wiki has many more examples.

Using GPIO filesystem

You can achieve the same result from the shell using the GPIO filesystem under /sys/class/gpio. The pin number needs to be the GPIO number specified for BCM2835. You cannot do PWM with this mechanism, except at very low frequencies.

sudo echo "18" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio18/direction
sudo echo "1" > /sys/class/gpio/gpio18/value
sudo echo "0" > /sys/class/gpio/gpio18/value
sudo echo "18" > /sys/class/gpio/unexport

The first two lines initialize and set the direction for GPIO18. The possible values for direction are “in” and “out”. This approach can be used from any programming language, using its text file input/output implementation.

If you have installed mono (sudo apt-get install mono-complete), you can use csharp shell to achieve the same results.

sudo csharp
using System.IO;
if(!File.Exists("/sys/class/gpio/gpio18/value"))
{
File.WriteAllText("/sys/class/gpio/export", "18");
}
File.WriteAllText("/sys/class/gpio/gpio18/direction", "out");
File.WriteAllText("/sys/class/gpio/gpio18/value", "1");
File.WriteAllText("/sys/class/gpio/gpio18/value", "0");
File.WriteAllText("/sys/class/gpio/unexport", "18");

The example above was inspired by the RaspberryPi.NET implementation.