Backing up Raspberry Pi SD Cards on Mac OS X, Linux & Windows

If you want to back up the Raspberry Pi SD card, you cannot simply plug the SD Card into your Mac or PC and copy all the files to your hard drive. Instead, you need to create what it is called disk image. This is because,  when you create a disk image of your SD card, you will preserve not only all the files but also the entire filesystem structure.
Therefore, once you decide to flash a new SD card, you just have to plug it in and it will work.


Firstly, insert the SD card into a USB card reader of  your Mac and open the Terminal and type the following command in order to list all the disks attached to your Mac:

diskutil list

From the list, identify which /dev/disk corresponds to the SD card.

Now just use the dd command to backup of your SD card:

dd if=/dev/rdiskx of=/path/to/image.img bs=1m

where /dev/rdiskx is your SD card and /path/to/image is the path where you want to save the backup. The backup image will be a file .img.

However, it is also possible to create a compressed SD card image (.gz) as follows:

sudo dd if=/dev/rdisk1 bs=1m | gzip > /path/to/backup.gz

To restore an SD card from a backup image, use the following command:

sudo dd if=/path/to/image.img of=/dev/rdisk1 bs=1m


On Linux, similar to Mac, you can use the standard dd tool:

dd if=/dev/sdx of=/path/to/image.img bs=1M

Where /dev/sdx is your SD card.

To create a compressed SD card image use the following command:

sudo dd if=/dev/rdisk1 bs=1M | gzip > /path/to/backup.gz

To restore an SD card from a backup image (.img):

sudo dd if=/path/to/image.img of=/dev/rdisk1 bs=1M


On Windows, you can use Win32 Disk Imager. The following screen-shoot is the main window.

Firstly you need to select which drive is your SD card. In this case my SD card is F:\.

Then, click on the blue icon just next to the F:\ to open a file-explorer window. Here you have to select where you want to save the image file and the type of image (.img, .bin, etc..).

Win32 Disk Imager

You have to confirm the folder and filename are correct. When ready just click the Read button. When completed it will show Done!

To restore the SD card from a backup image, just follow the same process but this time click the Write button.


How to set up Wi-Fi USB dongle on Raspberry Pi using the terminal + Android Tethering

It is relatively simple and cheap to add Wi-Fi connectivity to your Raspberry Pi. You only need to buy a Wi-Fi USB dongle and make sure that is compatible with GNU/Linux. On you can find a list of compatible Wi-Fi adapters.

In this tutorial, I am using Edimax EW-7811UN available for less than 10 £ on Amazon.

Edimax EW-7811UN 150Mbps Wireless Nano USB Adapter

Before to start with the actual setup, you need to take note of the following details of your Wi-Fi connection:

  • Network SSID
  • Wireless password
  • Security (e.g.: WPA2-PSK)

In order to make this project a little more interesting, I am going to use my Nexus 4 as a Wi-Fi Hotspot. Therefore, I am going to share my device’s 3G data connection as a portable Wi-Fi hotspot.

(If you are not using an Android device as Hotspot just skip the following section)

On your Android device (This steps apply to Nexus 4, Galaxy Nexus, Nexus 7 (2013), and Google Play edition devices):

  1. Go to Settings > Under the section Wireless & networks > More > Tethering & portable hotspot.
  2. Go to Set up Wi-Fi hotspot and type your Network SSID, Security (e.g. I selected WPA2-PSK), Password > Save
  3. Tick Portable Wi-Fi hotspot

After a moment, the device starts broadcasting its Wi-Fi network name (SSID). Once you want to stop sharing your data connection, just untick Portable Wi-Fi hotspot.

Now, it’s time to go back to our Raspberry setup.

It is always good practice to update the system to the latest available software. Open your Terminal and type:

sudo apt-get update
sudo apt-get install

Now, type the following command to open the interfaces configuration file:

sudo nano /etc/network/interfaces

You should see the following lines:

auto loiface lo inet loopback
iface eth0 inet dhcp

This is the default setup of your Ethernet connection (eth0). We need to add the following lines for the new Wireless connection that we want to set up (wlan0):

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

Press Ctrl-x to save and exit.

In the terminal enter the following command:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Replace all the content of the file with the following:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev



# scan_ssid type can be: value of 1 means broadcast and value of 2 means hidden


# Protocol type can be: RSN (for WP2) and WPA (for WPA1)

# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)

# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)

# Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)


The lines with # are only comments that should guide you. When you’re done with the editing, press CTRL+x to save and exit.

Now you only need to reboot in order to load the new network set up.

Raspberry will connect automatically during the boot to the Wi-Fi network.

How to: Setup a bluetooth connection between Arduino and a PC/Mac

The following tutorial is based on the one available at the following link ( 

The cheapest way to connect your Arduino to your PC wirelessly is using Bluetooth. The drawbacks of this solution are the limited range, about 10 meters, and the low bandwidth speed. If your project requires either higher range or more bandwidth you should opt for a more expensive WiFi module.

This tutorial will show you how to setup a Bluetooth Module for use as a serial data connection. I am using this particular module but should be similar with others.

Screen Shot 2013-09-21 at 10.17.31

Before to start, you need to have either a built-in Bluetooth module or a Bluetooth dongle installed in your PC/Mac. In addition you also need to have installed on your system both Arduino Software and Processing.

Firstly you need to set up the bluetooth module whitin your Mac or PC.

Under Mac

Open System Preferences. Under the section Internet & Wireless click on the Bluetooth icon.

Now click on Set Up New Device. The Bluetooth Module will appear as linvor.  Select it and press Continue. You need a specific passcode to pair the Bluetooth module and your Mac. Therefore, click on Passcode Option and enter 1234 (other bluetooth modules may have different codes). Then just wait until the pairing is completed. No other configuration steps are required.

Under Windows 7

Right click the Bluetooth Icon in the System Tray and select Bluetooth Devices. Click on the Add a Device. The search should bring up a bluetooth device called linvor. Select linvor and click Next. When asked select the option Enter the device’s pairing code. Enter the code 1234 (other bluetooth modules may have different codes).

The device should now be successfully added to the computer.

Click Close to return to the Bluetooth Devices list. Right Click on the linvor device and select Properties. Click on the Services Tab and you should see the Serial Port service along with a port number. In my case is COM4. Take note of the port number because you will need it later.


Connect your Arduino to your Computer using an USB cable as usual.

Open your Arduino Software, create a new sketch and copy the following code:

char val; // variable to receive data from the serial port
int ledpin = 13; // Arduino LED pin 13 (on-board LED)
void setup() {
   pinMode(ledpin, OUTPUT); // pin 13 (on-board LED) as OUTPUT
   Serial.begin(9600); // start serial communication at 9600bps

void loop() {
   if( Serial.available() ) // if data is available to read
      val =; // read it and store it in 'val'
   if( val == 'H' ) // if 'H' was received
      digitalWrite(ledpin, HIGH); // turn ON the LED
   } else {
      digitalWrite(ledpin, LOW); // otherwise turn it OFF
   delay(100); // wait 100ms for next reading

Once you have upload the code on your Arduino, disconnect the Arduino USB cable from your computer (this step is important). If you leave your Arduino connected to the computer with the USB cable the Bluetooth connection will not work! You can use an external battery or any other external source to power your Arduino.

Feel free to close the Arduino software. You will not need it anymore.

The following step is to connect the Bluetooth module to the Arduino as follows:

  • Connect the +5V bluetooth module Pin to the 5V  Arduino Pin
  • Connect the 0V bluetooth module Pin to the GND  Arduino Pin
  • Connect the TX bluetooth module Pin to the RX  Arduino Pin
  • Connect the RX bluetooth module Pin to the TX  Arduino Pin

Connect Arduino to a power source and the module Bluetooth led should start flashing.

Open Processing and copy the following code:

//import class to set up serial connection with wiring board
import processing.serial.*;
Serial port;
//button setup
color currentcolor;
RectButton rect1, rect2;
boolean locked = false;

void setup() {
   //set up window
   size(200, 200);
   color baseColor = color(102, 102, 102);
   currentcolor = baseColor;
   // List all the available serial ports in the output pane.
   // You will need to choose the port that the Wiring board is
   // connected to from this list. The first port in the list is
   // port #0 and the third port in the list is port #2.
   // Open the port that the Wiring board is connected to (in this case 1
   // which is the second open port in the array)
   // Make sure to open the port at the same speed Wiring is using (9600bps)
   port = new Serial(this, Serial.list()[2], 9600);
   // Define and create rectangle button #1
   int x = 30;
   int y = 100;
   int size = 50;
   color buttoncolor = color(153, 102, 102);
   color highlight = color(102, 51, 51);
   rect1 = new RectButton(x, y, size, buttoncolor, highlight);
   // Define and create rectangle button #2
   x = 90;
   y = 100;
   size = 50;
   buttoncolor = color(153, 153, 153);
   highlight = color(102, 102, 102);
   rect2 = new RectButton(x, y, size, buttoncolor, highlight);

void draw() {
   update(mouseX, mouseY);

void update(int x, int y) {
   if(locked == false) {
   } else {
      locked = false;
   //Turn LED on and off if buttons pressed where
   //H = on (high) and L = off (low)
   if(mousePressed) {
      if(rect1.pressed()) { //ON button
         currentcolor = rect1.basecolor;
      } else if(rect2.pressed()) { //OFF button
         currentcolor = rect2.basecolor;

class Button {
   int x, y;
   int size;
   color basecolor, highlightcolor;
   color currentcolor;
   boolean over = false;
   boolean pressed = false;
   void update() {
      if(over()) {
         currentcolor = highlightcolor;
      } else {
         currentcolor = basecolor;
   boolean pressed() {
      if(over) {
          locked = true;
          return true;
      } else {
          locked = false;
          return false;
   boolean over() {
      return true;
   void display() {

class RectButton extends Button {
   RectButton(int ix, int iy, int isize, color icolor, color ihighlight) {
      x = ix;
      y = iy;
      size = isize;
      basecolor = icolor;
      highlightcolor = ihighlight;
      currentcolor = basecolor;
   boolean over() {
      if( overRect(x, y, size, size) ) {
         over = true;
         return true;
       } else {
         over = false;
         return false;
   void display() {
      rect(x, y, size, size);

boolean overRect(int x, int y, int width, int height) {
   if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) {
      return true;
   } else {
      return false;

The only line you have to modify is the following:

port = new Serial(this, Serial.list()[2], 9600);

where [2] is the number of the serial port of your Bluetooth device (ex: [3] is COM4 in my case). If you run the Processing code you should see in the logs a list of all available ports. Make sure you select the right one for you.

Once the Bluetooth module is connected to your Computer the LED on the module will stop flashing and be on permanently.

This code creates two buttons. When the left button is clicked it will send an H signal to the board and turn the LED on. Or if the right button is clicked it will send an L signal to Wiring board to turn the LED off.