I am now blogging from dotslashnotes.com
See you there..
I am now blogging from dotslashnotes.com
See you there..
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..).
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.
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 http://elinux.org/RPi_USB_Wi-Fi_Adapters 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.
Before to start with the actual setup, you need to take note of the following details of your Wi-Fi connection:
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):
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
update_config=1network={
ssid=”YOUR_NETWORK_SSID”
# scan_ssid type can be: value of 1 means broadcast and value of 2 means hidden
scan_ssid=1psk=”YOUR_WIRELESS_PASSWORD”
# Protocol type can be: RSN (for WP2) and WPA (for WPA1)
proto=RSN# Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)
key_mgmt=WPA-PSK# Pairwise can be CCMP or TKIP (for WPA2 or WPA1)
pairwise=CCMP# Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)
auth_alg=OPEN}
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.
The following tutorial is based on the one available at the following link (http://playground.arduino.cc/Learning/Tutorial01).
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.
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.
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.
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 = Serial.read(); // 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 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. println(Serial.list()); // 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() { background(currentcolor); stroke(255); update(mouseX, mouseY); rect1.display(); rect2.display(); } void update(int x, int y) { if(locked == false) { rect1.update(); rect2.update(); } 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; port.write('H'); } else if(rect2.pressed()) { //OFF button currentcolor = rect2.basecolor; port.write('L'); } } } 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() { stroke(255); fill(currentcolor); 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.
In this post I am going to describe how to setup a web streaming server and motion detector using a Raspberry PI with the PI Camera Module.
Before to start, I am assuming that you have already your Raspberry PI Camera Module setup and working.
Step 1: Download the software
The software that we are going to install is called Motion; this is both a motion detector and streaming software. You could potentially install Motion using the apt-get command from the terminal. However, if you want to use Motion with the Raspberry PI Camera Module you need a special version of Motion (called Motion – MMAL Camera) – see this post for more info and credits.
Therefore, what you are going to do is the following:
Ok then, let’s start..
sudo apt-get install motion
Press Y when it is requested to install all the required dependencies. Now, we can remove Motion because, as I wrote above, we are going to use Motion – MMAL Camera.
sudo apt-get remove motion
At this point, we can download the pre-compiled version of Motion – MMAL Camera:
wget https://www.dropbox.com/s/xdfcxm5hu71s97d/motion-mmal.tar.gz
Unzip:
tar zxvf motion-mmal.tar.gz
Step 2: Config the software
As you can see, the archive contains two files: the executable and a config file. Before running the software you need to make some changes to the config file. Make sure you are in the same directory where the config file is and open it:
sudo nano motion-mmalcam.conf
The config contains a lot of settings that you are free to modify as you like. However the most important ones are the following:
As you can see, Motion offers a lot of setting that you can play with…
Step 3: Run the software
Once you are happy with your config you can run motion using the following command:
sudo ./motion -n -c motion-mmalcam.conf
Now, if you want see the streaming open a browser (use Firefox or Opera but do not use Chrome because it does not work for me) and go to the following address:
and you should be able to see the streaming! If you want to see the config tool go to:
You can access to the web streaming from different devices such as iPhone, Android, etc..
That’s it. When a motion is detected Motion will generate pictures and/or videos according to what you chose in the config file.
Adding speech recognition capability to your Arduino project is easier than you can imagine. I am currently working on an 4WD Arduino robot project. My robot can be controlled using only my voice. So far, I have implemented the following commands: go ahead, go back, turn left/right and stop.
If you want to add voice recognition to your project, you need to bear in mind that Arduino is not powerful enough to run a speech recognition code. But this is not a big issue. There are two alternative ways to do that:
The Speech Recognition shield is a quite expensive solution. Moreover, I am already using a Motor Shield with my Arduino so I cannot use another shield.
That’s why I decided to go for the second option. My Arduino robot is connected to my PC with a Bluetooth connection, but you can use a USB cable or a wireless connection as well.
Before to start, you will need the following:
Once you are ready to start, you can download the BitVoicer manual from their website. Here it is the link.
The manual contains all the information you will need. It also provides two examples.
In the first example, the audio is captured by the computer’s microphone. A LED is connected to the digital pin 4 of the Arduino will turn on and off in response to a voice command captured by the computer’s microphone. In the second one, the microphone is directly connected to the Arduino board.
Once you understand how to implement these two basic examples, you will be ready to work on more advanced speech recognition project with your Arduino.
In the previous post I explained step by step how to set up a VPN connection in Raspberry Pi. When you want to connect to the VPN you have to run the following command:
sudo openvpn config-filename-goes-here.ovpn
where config-filename-goes-here.ovpn is the VPN configuration file. The only problem is that every time you want to connect to the VPN you have to manually execute this command. It would be much more convient to run it automatically during the system startup. So let’s do it..
Firstly, you need to create a script in /etc/init.d directory:
sudo nano /etc/init.d/VPNConnection
where VPNConnection is the name of the script (you are free to choose any name that you prefer).
Once the nano editor is open, just copy and paste the following content:
#! /bin/sh
# /etc/init.d/VPNConnection### BEGIN INIT INFO
# Short-Description: Simple script to start a program at boot
# Description: A simple script from http://www.stuffaboutcode.comwhich will start / stop a program a boot / shutdown.
### END INIT INFO# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case “$1” in
start)
echo “Starting VPN Connection”
# Connect to the VPN
cd /etc/openvpn
sudo openvpn config-filename-goes-here.ovpn
;;
stop)
echo “Stopping VPN Connection”
# Disconnect
killall openvpn
;;
*)
echo “Usage: /etc/init.d/VPNConnection {start|stop}”
exit 1
;;
esac
Now you can save and close the editor. The next step is to make the script executable:
sudo chmod 755 /etc/init.d/VPNConnection
Before to proceed any further test if the script works as expected. Try to connect to the VPN using the following command:
sudo /etc/init.d/VPNConnection start
and then test the stop command (disconnect from the VPN):
sudo /etc/init.d/VPNConnection stop
The final step is to register the script to be run at boot and shutdown:
sudo update-rc.d VPNConnection defaults
Next time you will boot the system you will be automatically connect to the VPN.
If you want to remove the script from the start-up:
sudo update-rc.d -f VPNConnection remove
Let me know if you have any comments or suggestion!
In this ./note I am going to show you how set up the VPN connection provided by Private Internet Access in Raspberry PI (but the same steps are valid for any other Linux distribution).
I found these instruction in the Private Internet Access forum (https://www.privateinternetaccess.com/forum/).
1. If you don’t have done this already, you need to install OpenVPN.
sudo apt-get install openvpn
2. Move to the OpenVPN directory in /ect:
cd /etc/openvpn
3. Download from the Private Internet Access website the zip folder. This folder contains all the config files for OpenVPN.
wget https://www.privateinternetaccess.com/openvpn/openvpn.zip
4. Unzip the folder using unzip. If you don’t have unzip already installed in your system run the following command:
sudo apt-get install unzip
and then unzip:
sudo unzip openvpn.zip
5. In order to see the list of servers to which you can connect run:
ls -l
6. As you can see each server config file has .ovpn extension. Now you can run the final command to connect to the server:
sudo openvpn config-sever-filename.ovpn
Once the previous command is executed you are required to insert your username and password of your Private Internet Access account. If you want to avoid to insert username and password every time you want to connect to the VPN you can follow these steps:
1. Create a .txt file in the /etc/openvpn folder (same folder of the .ovpn file) . You can name this file ‘pass.txt‘
2. In the first two lines of the file put your username and password, like:
username
password
3. Save and close the file.
4. Open up your .ovpn and add the following line at the bottom:
auth-user-pass pass.txt
5. Save and try to connect again. You should not be required to insert username and password this time.
That’s it.
In a next post I will show how to connect automatically to the VPN at boot.