Category Archives: Raspberry Pi

Preventing (or at least reducing) SD corruption on Raspberry PI


Read for more info

The biggest offender for Filesystem writes on any linux system is logging. If you are like me, you don’t really look at /var/log after a recycle anyways. This area, and /var/run, a location where lock files, pid files and other “stuff” shows up, are the most common areas for mess-ups. Take a look at your blinking FS light on the board. Our goal is to make that light stay off as long as possible.

Set up tmpfs mounts for worst offenders.

The following two lines should be added to /etc/fstab:

none        /var/run        tmpfs   size=1M,noatime         00
none        /var/log        tmpfs   size=1M,noatime         00

There’s more, however. By default, linux also records when a file was last accessed.
That means that every time you read a file, the SD card is written to. That is no good! Luckily, you can specify the “noatime” option to disable this filesystem feature. I use this flag generously.

Also, for good measure, i set /boot to read-only. There’s really no need to regularly update this, and you can come back here and change it to “defaults” and reboot when you need to do something.

After this, /etc/fstab should look as follows:

proc            /proc               proc    defaults                    0   0
/dev/mmcblk0p1  /boot               vfat    ro,noatime                  0   2
/dev/mmcblk0p2  /                   ext4    defaults,noatime            0   1
none        /var/run        tmpfs   size=1M,noatime             0   0
none        /var/log        tmpfs   size=1M,noatime             0   0

Go ahead and reboot now to see things come up. Check the Filesystem light on your raspberry pi after it’s fully booted. You should see no blinking at all.

Disable swapping

One protection against SD card corruption is an optional, but potentially “I’m glad i did that” change to disable swapping.

The raspberry pi uses dphys-swapfile to control swapping. It dynamically creates a swap partition based on the available RAM. This tool needs to be used to turn off swap, and then needs to be removed from startup.

Run the following commands to disable swapping forever on your system:

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove

After doing this, call free -m in order to see your memory usage:

pi@raspberrypi ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:           438         59        378          0          9         27
-/+ buffers/cache:         22        416
Swap:            0          0          0

If you reboot, and run a free -m again, you should still see swap at 0. Now we don’t have to worry about tmpfs filesystems swapping out to hard disk!


Read for more info

EMPi – Raspberry Pi

A raspberry Pi that will stand the most intense electromagnetic and electro static environments and cope with EMP (Electro Magnetic Pulse). The sort of environment around tesla coils.


I started with a Pi and a Adafruit Pi-Plate. My first job was to create a optic-fibre link (115Kb/s) for comms to my tesla coils and it also doubles up as a remote and insulated tty console for the PI. The chips I used for the fibre are the Avago 1524/2524 1Mb/s fibre transmitter/receiver.

20140801_132030 20140801_132520






The transmitter is driven from a Microchip TC4428 which takes the 3.3v TX to 5V and gives the current drive for the TX LED .The RX is level shifted and inverted using a BC337 (update – a speed up cap was added to the base as at 115kb Rx errors were seen)


Img_20140815_3184 Img_20140815_3182






I realised that the Pi would have to run on its own power supply, so 6 rechargeable AA cells giving 7.2V were added, along with a 7805 regulator to give 5V for the Pi and a couple of diodes to allow the batteries to smoothly take over when the external power was removed.

As the power connector is open to the EM noise on the out side of the case, there is a diode , a cap and a 30V TVS across the power input.

It also became apparent that there was no way of cleanly switching off the Pi without connecting a network or terminal. So I added a button and a script to shutdown the Pi (although not cut the power).

A Pi Cam was attached and bolted to the case, A small hole lets it see the outside world without letting in too much radiation. I also added in a sedcond button which allows the camera to be turned on and off. The script makes the camera take photos every 10 seconds. (I hope to add video too)














I added a removable panel that cover’s the USB, Ethernet and Fibre ports. This is not ideal as I can’t close it fully when I’m running on fibre.

I also added a shutter that goes across the external power/charging connector to further protect the circuits.

20140814_175821 20140814_181113










A quick test proved that the Pi can run when sat on top of a small tesla coil.


Img-2014-08-14-173A11a Img-2014-08-14-173A10a








The camera also worked, but the breakout was too close for the camera to give good photos.








A monocle (50mm lens with 50mm focal length) was added







Giving a couple of goodish photos of the discharge from under the breakout point. (breakout is the wiggly black line to the LHS)