Showing posts with label pi. Show all posts
Showing posts with label pi. Show all posts

Raspberry Pi Settlers of Catan Server

So a couple of days ago I decided I wanted my Pi to be a Settlers of Catan server.
I decided on using a custom compiled JSettlers version instead of the C++ pioneer version because of the extra perks it had.

It runs surprisingly well considering it is in java but it makes sense since it is making the clients computer do most of the work. I was also decently surprised with the bots. The server allows you to create practice games against bots or real games where other people can sign up to play with you.

It also has multiple scenarios and lots of documentation. Sometimes it is a little buggy but overall Im pretty happy with it as of right now.

Ive uploaded the version I have compiled and an install script. To run it, first you need to have java and apache (or some other web server) installed. If you dont, run:
sudo apt-get install apache2 openjdk-7-*

**Note, you dont need apache to run, you could use others such as NGinx or no web server at all and just play the game by yourself.

Then download the file, unzip it, and install:
wget "https://stevenhickson-code.googlecode.com/files/PiSettlers.tar.gz"
tar -xvf PiSettlers.tar.gz
cd JSettlers2
sudo ./install-web.sh

and now you should be done, you can go to your IP address in any computer on your network and play it.
Mine is at http://192.168.1.100/settlers/
**Note, if you want to play it outside of your network, i.e. you have a domain name, then you need to open port 8880 on your router to go to the pi.

Here is what it looks like playing a game hosted from the pi on my fedora laptop.

Consider donating to further my tinkering


Places you can find me
Read More..

Using the Raspberry Pi as a Web Server Media Server and Torrent Box

So youve set your Raspberry Pi up.
If not you might want to check out this page first.
So now you want to set your Raspberry Pi up as a media/web/everything else server.

Before any of these, make sure your raspberry pi ip address is static. You can set this by opening up a terminal and typing in:
sudo nano /etc/network/interfaces

(Feel free to use gedit or vim or whatever you want. I like vim)
You should now be looking at a file. Change the line:
iface eth0 inet dhcp
To:
iface eth0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.254

where the gateway is your router and the address is the ip address you want. Save the file and reboot (sudo reboot) and now your ip should be static.

Luckily, SSH is already enabled on the Raspbian image so we wont go into that. However, if you want to SSH externally, you should install something like SSHGuard for protection and then in your router config redirect port 22 traffic to your Raspberry Pi.


Section 1: Webserver

Installing apache is easy. Just open a terminal and type:
sudo apt-get install apache2

This will set up a webserver for you with the files at /var/www being your web directory. Modify those files how you feel like and if you want to make it publicly accessible then configure your router to forward port 80 to your raspberry pis ip address.

Section 2: VNC

This is an optional thing since you can port X over SSH. But if you want vnc. All you have to do is open up a terminal and type:
sudo apt-get install tightvncserver

When it is finished installing it should ask for a password. If it doesnt or you need to change it. Just type vncpasswd to reset it.
Then type tightvncserver and a new instance will start. You can kill it by typing tightvncserver -kill :1

To use this externally, you will have to open up port 5801 (for the first instance, 5802 for the second, etc.)

Section 3: Media Server

Start off by mounting all of your external HDDs. If you have a Raid array that is great, if not, I have a handy little hack for you.
edit fstab by opening up a terminal and typing:
sudo nano /etc/fstab
Add each hard drive to the file, mine looks like this:
/dev/sda1 /media/Kingsley ntfs-3g defaults 0 0
/dev/sdb1 /media/HarvardMulligan ntfs-3g defaults 0 0
/dev/sdc1 /media/Moloch ntfs-3g defaults 0 0

(Make sure the folders in /media exist and their permissions are set properly with chmod, otherwise this wont work)

You really should set up a RAID array or something, but lets say you like to live by the seat of your pants and dont care if one of your HDDs fail and you want to access them all at the same time in one convenient directory. To do this you can use mhddfs. Install it by typing:
sudo apt-get install mhddfs

When its done installing, open fstab back up and after the lines with your HDD, type in something like what is shown below:
mhddfs#/media/Kingsley,/media/HarvardMulligan,/media/Moloch /media/ALLOFIT fuse defaults,allow_other 0 0

So my final fstab file has this at the bottom:
/dev/sda1 /media/Kingsley ntfs-3g defaults 0 0
/dev/sdb1 /media/HarvardMulligan ntfs-3g defaults 0 0
/dev/sdc1 /media/Moloch ntfs-3g defaults 0 0
mhddfs#/media/Kingsley,/media/HarvardMulligan,/media/Moloch /media/ALLOFIT fuse defaults,allow_other 0 0





where mhddfs mounts all of the drives to /media/ALLOFIT (which I previously created and set permissions for) and I can write to that and mhddfs will figure out where to put it for me.
Now just sudo reboot

Interesting tidbit: You can use sshfs (their is a Windows version call win-sshfs) to access these drives securely through ssh. This way you dont have to worry about Samba and you can access these files graphically using the internet.

Section 4: Torrent Box

So now you want to be able to torrent (lets assume completely legally) things directly to your server/external HDDs.
Simply install transmission by opening up a terminal and typing
sudo apt-get install transmission-daemon

Now we need to edit some settings, stop the daemon and open up the settings file by typing:
sudo service transmission-daemon stop
and
sudo nano /etc/transmission-daemon/settings.json

You will need to change a couple of settings.
Change your download directory to where you want your downloads, I use my external HDDs:  "download-dir": "/media/ALLOFIT",
Now to set up some security. Change the following text requires the ""s but numbers and true/false dont:
"rpc-authentication-required": true,
"rpc-enabled": true,
"rpc-password": "YourPasswordHere",
"rpc-port": 6669,
"rpc-username": "YourUserNameHere",

You can change the port to anything but its probably a good idea to change it from the default to avoid brute force script kiddies.
Now start the daemon back up by typing
sudo service transmission-daemon start

Now open up a webbrowser on any computer in your network and type in your raspberry pis ip address followed by :port. Ex: 192.168.1.10:6691
If you want to access this externally, just forward the port you chose to your raspberry pi ip address in your router config.

Now you are done.

To use transmission to its fullest potential and automatically download media:
http://stevenhickson.blogspot.com/2013/03/automatically-downloading-torrents-with.html


Check out my other Raspberry Pi Fixes/How tos:
http://stevenhickson.blogspot.com/2012/08/setting-up-omxplayer-gui-on-raspberry-pi.html
http://stevenhickson.blogspot.com/2012/10/fixing-raspberry-pi-crashes.html

Consider donating to further my tinkering.


Places you can find me
Read More..

Playing YouTube videos in the browser on the Raspberry Pi

This will allow you to stream up to 1080p youtube videos in the browser on the Raspberry pi using omxplayer. Its a crude hack but it seems to work pretty well on my system. Install instructions and a demonstration video are shown below.

You can install this by pulling the git repository and running the scripts below.
Commands to install are below (your user should have sudo privileges but you dont need to be root):

You may have to enable user scripts in Midori by going to Menu>Preferences>Extensions>UserScripts and clicking the check box.


sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

**NOTE, this will ask you if you want to install a lot of different scripts because it is a SUITE. You only have to pick the ones you want to use. If you only want to use the youtube scripts, press n on any other question except for the dependencies and youtube.

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh



Demonstration


There is a lot of misinformation out there on how to do this. Using gnash or HTML5 is going to result in a frame rate so slow it can be considered unworkable. Ive tried both of them out and you cant really watch videos with them. XBMC has a youtube plugin but it is buggy and crashes often.

Ive been playing youtube videos using the command line and my voicecommand using the scripts found here.
After seeing a couple people ask about playing youtube in the browser last night, I decided to go ahead and do that and create some user scripts for midori which allow the browser to utilize the same hack.

Here is the technical overview:
I created a script called youtube which uses the youtube-dl -g flag to grab the video URL. It also handles playlists and other parsing. Then it passes that video URL to omxplayer for it to stream. 
Next I registered a new URL protocol yt:// and made it pass its information to the youtube program whenever it runs. 
Finally, I created a user script in Midori which simply replaces all http://youtube.com/watch?* URLs with yt://youtube.com/watch?*.

Feel free to let me know any problems you have and enjoy your Youtube browsing experience.


 Consider donating to further my tinkering


Places you can find me
Read More..

Attaching heat sinks to the Raspberry Pi for overclocking

My Raspberry Pi was getting a little hot when I overclocked it to above 1100 MHz.
So I decided to attach some heat sinks to it.
All you need to do this are the following:

  • Some heat sinks (copper or aluminum depending on your preference)
  • Thermal adhesive, I used Arctic Silver
  • Isopropyl alcohol
  • Lint-free cloth
  • Some clamps
  • A clean surface
Unplug your Raspberry Pi and put your it on a clean surface like so:

I got this heatmap from modmypi.com and put heat sinks over the  three hot spots.
Start by cleaning the black surfaces of the hot spots with the isopropyl alcohol and a lint free cloth.
Once that is dried, its important you dont touch it or get anything on it.

Next get your heat sinks and thermal adhesive ready. Instructions should come with your thermal adhesive but it is commonly to mix a 1:1 ratio on a clean surface. Wait 1-2 minutes for it to thicken just a little bit then spread a thin layer on the processors and attach the heat sinks. Make sure to hold them down with rubber bands or clamps while they cure.

I was able to get a 6 degrees Celsius difference from the commands:
/opt/vc/bin/vcgencmd measure_temp
cat /sys/class/thermal/thermal_zone0/temp

With this done, I have the following stats in /boot/config.txt and they seem to be stable

force_turbo=1
over_voltage=8
arm_freq=1180
sdram_freq=500
core_freq=500
gpu_freq=350


Consider donating to further my tinkering.


Places you can find me
Read More..

Voice Control on the Raspberry Pi

Note: Updated version here:
http://stevenhickson.blogspot.com/2013/05/voice-command-v20-for-raspberry-pi.html

Im finally releasing my Raspberry Pi voice control software.
The beauty of this is that you can use it and customize it without programming anything.
This will work on any linux machine but I find it uniquely suited for the Raspberry Pi and thats what I developed it for.
You just type voicecommand -e to edit the configuration file and add any speech and the coinciding command. You can see all of the little nifty commands it can recognize just with my config file in the video. I use all of these pretty often. It is very mutable and works with lots of other programs.

Watch this video to really get a feel for the program:




The commands should be in the format speech=command. Ex:
music=xterm -e pianobar
Doctor Who=playvideo -r -f Doctor Who

Unfortunately, it is caps sensitive voice control right now, but you can test the input by running
speech-recog.sh
on you machine to see what the speech recognition will give you. It uses Googles api and is really good at recognizing what you say. I used to use espeak instead of festival for the text to speech because of the speed difference. However, after some very helpful comments from people, Ive switched to using Googles TTS api, which is much more pleasant to listen to. The video above is still using espeak but the newest code does not.

I hope you will try this out and make some cool things with it. Instructions to install are below.
Im in the process of setting up a repository so until then, here are the instructions (do this in the terminal):


sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


Here are the dependencies required to run and build:
sudo apt-get install libboost1.50-dev libboost-regex1.50-dev youtube-dl axel curl xterm libcurl4-gnutls-dev mpg123 flac sox

**Note: If the file .commands.conf doesnt exist in your home directory and you have an old version of code, the program will exit. You should either grab the newest code from github or create the file yourself.

**To make it listen for longer, edit the file /usr/bin/speech-recog.sh and change -f cd -t wav -d 3 to -f cd -t wav -d # where number is how many seconds it should listen.

Consider donating to further my tinkering


Places you can find me
Read More..

Control anything electrical with the Raspberry Pi using 433 MHz RF

Ive gotten a lot of e-mails in the past about controlling lights, plugged-in utilities, etc. with my voicecommand software on the Raspberry Pi and I decided to make a quick easy guide.

Why would you want to do this?

This is an easy question to answer. I walk into a room and I say Pi . . . Let there be light and behold the lights turn on. Or for those with less dramatic flair, just saying lights and having the lights turn on.
Having voice controlled lights in your house just seems convenient.

How can I do this?

Its easy actually.
Ive created an image for the RPi that already has everything you need on it. This means its easier than ever to control electronics with your voice.

You can download it at:
https://mega.co.nz/#!MM8W1JxR!4PlZ_1-dumasDUCYRI4LuiBwEJgtqhfoin0R8ls90NQ

Once you have the image on your Raspberry Pi, buy some RF 433 MHz light switches or sockets like these: 
Etekcity ZAP 5LX Auto-Programmable Function Wireless Remote Control Outlet Light Switch with 2 Remotes, 5-Pack Outlet

You can plug those into an outlet and plug anything (including a light) into them.

Next you need a 433 MHz transmitter and receiver for the RPi. You can get those here:
433Mhz RF transmitter and receiver kit for your Experiment

Then you can wire them up to the pi using the GPIO and use pilight to control them. You wire them in as below:
The smaller unit is plugged into voltage, ground, and pin 17 while the larger board is plugged into voltage, ground, and pin 18.

Once your transmitter and receiver are wired up, simply point the remote at the receiver, run pilight-debug, and press the button on the remote you want to learn. Now you can copy that string and use pilight-send to send it.
Example:
sudo killall pilight-daemon or sudo service pilight stop
sudo pilight-debug
Then CTRL+C when you see a RF string. Mine looks something like this:
172 688 172 688 172 516 172 688 172 688 516 172 172 688 516 172 172 688 172 688 172 688 516 172 172 688 516 172 516 172 516 172 172 688 172 688 172 688 172 688 516 172 516 172 172 688 172 688 172 5814
**Note** Sometimes I have trouble escaping out of pilight-debug. When that happens I kill it (kill -9) from a different terminal
Now I can turn that light on.
First restart the pilight daemon:
sudo pilight-daemon or sudo service pilight start
Now send the command:
sudo pilight-send -p raw -c "172 688 172 688 172 516 172 688 172 688 516 172 172 688 516 172 172 688 172 688 172 688 516 172 172 688 516 172 516 172 516 172 172 688 172 688 172 688 172 688 516 172 516 172 172 688 172 688 172 5814"
but with your own string. Do this for the on and off settings for as many lights as you want.

Now I can add that command in a script and use voicecommand to run it when it hears the right command!
You can do this with voicecommand -e

You can read more about it at the hackaday projects page here.

And here is a quick video demo:

Consider donating to further my tinkering since I do all this and help people out for free.




Also, a contact of mine recently did a computer vision kickstarter. You should join that if you want to learn more about computer vision.
https://www.kickstarter.com/projects/1186001332/pyimagesearch-gurus-become-a-computer-vision-openc

Places you can find me
Read More..

Syrias children learn to code with the Raspberry Pi

Three years ago, when I was looking for an example of social unrest to highlight the use of social media as a communication tool for protestors in my book, I chose the then new uprising in Syria. Im horrified the conflict still continues. However, I just came across a surprisingly good piece of news from that awful conflict; the use of the Raspberry Pi to teach Syrian refugees in Lebanon to code. Read the full article in the Guardian to learn more.

from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

Turn off or edit this Recipe

Read More..

Voice Command v3 0 for the Raspberry Pi

Voicecommand v3.0 Changes


Ive made some big changes and their are even bigger things in the works. Here is a small list. Ive had some help from a couple of committed users who have come up with some new good ideas which is awesome.


  • There is now a ~ option that finds the word anywhere in a command. For instance ~music==pianobar will work if you say: lets hear some music, play music, or music.
  • !filler is now a string so you can set it manually. If you put it to 0, it will be empty and if you put it to 1, it will be FILLER FILL for compatibility issues.
  • Example scripts have been added in the Misc folder for you to play with. These can send and receive emails and text messages as well as posting to facebook; all using only your voice.
  • Flags can now overwrite the config options and can be reversed by following them with a 0 or enforced if followed with a 1. Ex. if !continuous==1 in your config file, you can force it to run only once with voicecommand -c0
  • The commands and keywords are now case insensitive. So no tricky case matching.
  • Multiple language support has been added. This is based on your country code which I think you can find here (plus en_uk and en_us). Look up your country code and use that. Ex. For US: !language==en_us, for Spain !language==es, for Germany !language==de.
  • You can set a Wolfram Alpha API and maxResponse (the number of branches) like !api==XXXXXX-XXXXXXXXXX and !maxResponse==3. This will give you better answers. You can sign up for a Wolfram Alpha API on their website for free.
  • Logging has been enabled into /dev/shm/voice.log. It throws stuff to this instead of /dev/null
  • The need for tts-nofill has been removed!! Now tts doesnt use any filler unless you send it yourself.

New Install and Update videos have been added. They can be found here:
http://stevenhickson.blogspot.com/2013/06/installing-and-updating-piauisuite-and.html

Consider donating to further my tinkering since I do all this and help people out for free.
Places you can find me
As always, the updated man page can be found below:

voicecommand

Section: voicecommand man page (8)
Updated: 13 May 2013
Index   

NAME

voicecommand - Listen to user defined strings and run the corresponding command   

SYNOPSIS

voicecommand [OPTIONS]...  

DESCRIPTION

voicecommand was developed for the Raspberry Pi but will work on any linux system with a microphone attached. It is a crude program, which uses basic comparisons to determine if your voicecommand fits a format specified in a config file; it it does, it runs the corresponding linux command. It supports auto-completion and variables as well as command verification, a continuous mode, and other options. For help/comments/questions, feel free to e-mail me at help@stevenhickson.com. I answer sporadically but do eventually respond.


Note: All of the flags that turn something on are off can be reversed and overwritten by following it with a 1 or 0. So for instance if you have !continuous==1 in your config file, you can run voicecommand -c0 to turn continuous off.
 

OPTIONS

?
Same as -h
-b
Turns off the FILL audio. The purpose of this was because the Raspbery Pi (or mine at least) cuts off the first few seconds of audio. This flag turns that feature off. You should only be concerned with this if you hear FILL before everything it says.
-c
Makes voicecommand run in continuous mode, where it will keep listening over and over again.
-d
Sets the duration for listening to the audio for voice commands
-D
Sets the audio hardware. The default is plughw:1,0 -
-e
Edits the voicecommand config file.
The format is voice==command
You can use any character except for newlines or ==
If the voice starts with ~, the program looks for the keyword anywhere. Ex: ~weather would pick up on weather or whats the weather
You can use ... at the end of the command to specify that everything after the given keyword should be options to the command.
Ex: play==playvideo ...
This means that if you say "play Futurama", it will run the command playvideo Futurama
You can use $# (where # is any number 1 to 9) to represent a variable. These should go in order from 1 to 9
Ex: $1 season $2 episode $3==playvideo -s $2 -e $3 $1
This means if you say game of thrones season 1 episode 2, it will run playvideo with the -s flag as 1, the -e flag as 2, and the main argument as game of thrones, i.e. playvideo -s 1 -e 2 game of thrones
Because of these options, it is important that the arguments range from most strict to least strict.
This means that ~ arguments should probably be at the end.
You can also put comments if the line starts with # and special options if the line starts with a !
Default options are shown as follows:
!keyword==pi,!verify==1,!continuous==1,!quiet==0,!ignore==0,!thresh==0.7,!maxResponse==-1
api==BLANK,!filler==FILLER FILL,!response==Yes Sir?,!duration==3,!com_dur==2,!hardware==plughw:1,0,!language==en_us
Keyword, filler, and response accept strings. verify, continuous, quiet, and ignore except 1 or 0 (true or false respectively). thresh excepts a floating point number. These allow you to set some of the flags as permanent options (If these are set, you can overwrite them with the flag options).
You can set a WolframAlpha API and maxResponse (the number of branches) like !api==XXXXXX-XXXXXXXXXX amd !maxResponse==3
You can now customize the language support for speech recognition and some text to speech with the language flag. Look up your country code and use that. Ex. For US: !language==en_us, for Spain !language==es, for Germany !language==de.
-f /my-location/config-file
This allows you to load a different config file located in a different spot. The default one is in your home directory and is ~/.commands.conf
The config file must be formatted the same way.
-h
Shows this man page.
-i
Sets the ignore mode. When this flag is activated, if a command is not in the config file, nothing happens. The default behavior is to try to find an answer or response to that question and then speak it. This turns off that behavior.
-I string
Sets the forced input mode. This allows you to test it without the microphone or get it to parse typed information. It will not run in continuous mode with this.
-k word
Sets the keyword. The default is pi. If this flag is set, the verify and continuous flags are also set since this is only checked during those two modes.
      Ex. voicecommand -c -v -k Jarvis

-l
Sets the duration for listening to the audio for the command keyword. This is different than the -d flag that listens for the voice commands.
-s
Runs a setup operation that attempts to set all of the config options in the config file so that voicecommand works properly
-r word
Sets the response. The default is "Yes Sir?" (For version 1.0, it was Ready?. If this response is more than one word, it should be put in quotes, otherwise it doesnt need to be
      Ex. voicecommand -r Ready?

-t #
Sets the threshold for volume to determine if the keyword was spoken. This should be a floating point number. The default value is 0.7 which works well with the Logitech C310 camera/mic from about 6 feet away.
Ex. voicecommand -t 1.2
-p
Sets passthrough mode on so that instead of running the commands, it just prints them. This is going to be used for the XBMC plugin and Android app.
-q
Sets quiet mode on so that voicecommand never speaks through the audio output. It still prints everything but doesnt ever respond. This includes the keyword response.
-v
Makes voicecommand verify the keyword. This only happens in continuous mode so if this flag is set, the continuous flag will be set as well. The default mode is to not verify. When voicecommand hears any sound above the threshold, it says the response then listens for a command. The default keyword is pi. When the verify flag is set, after the threshold is met, voicecommand verifies that the keyword was spoken.

AUTHOR

Steven Hickson (help@stevenhickson.com)  

BUGS

No known bugs. To report bugs, send a clear description to help@stevenhickson.comSince this program is fairly crude, user typos could cause crashes/failed responses. Please read the man page thoroughly before submitting a bug.  

COPYRIGHT

Copyright © 2013 Steven Hickson. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it as long as you give credit to the author and include this license. There is NO WARRANTY, to the extent permitted by law.  

HISTORY

This is the second major version of this program  

SEE ALSO

http://stevenhickson.blogspot.com/


Read More..

Classifying everything using your RPi Camera Deep Learning with the Pi

For those who dont want to read, the code can be found on my github with a readme:
https://github.com/StevenHickson/RPi_CaffeQuery
You can also read about it on my Hackaday io page here.

What is object classification?

Object classification has been a very popular topic the past couple years. Given an image, we want a computer to be able to tell us what that image is showing. The newest trend has been using convolutional neural networks in order to classify networks trained with a large amount of data.

One of the bigger frameworks for this is the Caffe framework. For more on this see the Caffe home page.
You can test out there web demo here. It isnt great at people but it is very good at cats, dogs, objects, and activities.


Why is this useful?

There are all kinds of autonomous tasks you can do with the RPi camera. Perhaps you want to know if your dog is in your living room, so the Pi can take his/her picture or tell him/her they are a good dog. Perhaps you want your RPi to recognize whether there is fruit in your fruit drawer so it can order you more when it is empty. The possibilities are endless.

How do convolutional neural networks work (a VERY simple overview)?

Convolutional neural networks are based loosely off how the human brain works. They are built of layers of many neurons that are "activated" by certain inputs. The input layer is connected in a network through a series of interconnected neurons in hidden layers like so:
[1]

Each neuron sends its signal to any other neuron it is connected to which is then multiplied by the connection weight and run through a sigmoid function. The training of the network is done by changing the weights in order to minimize the error function based on a set of inputs with a known set of outputs using back propagation.

How do we get this on the Pi?

Well I went ahead and compiled Caffe on the RPi. Unfortunately since it doesnt have code to optimize the network with its GPU, the classification takes ~20-25s per image, which is far too much.
Note: I did find a different optimized CNN network for the RPi by Pete Warden here. It looks great but it still takes about 3 seconds per image, which still doesnt seem fast  enough. 

You will also need the Raspberry Pi camera which you can get from here:
Raspberry PI 5MP Camera Board Module

A better option: Using the web demo with python

So we can take advantage of the Caffe web demo and use that to reduce the processing time even further. With this method, the image classification takes ~1.5s, which is usable for a system.

How does the code work?

We make a symbolic link from /dev/shm/images/ to our /var/www for apache and forward our router port 5050 to the Pi port 80. 
Then we use raspistill to take an image and save it to memory as /dev/shm/images/test.jpg. Since this is symlinked in /var/www, we should be able to see it at http://YOUR-EXTERNAL-IP:5005/images/test.jpg.
Then we use grab to qull up the Caffe demo framework with our image and get the classification results. This is done in queryCNN.py which gets the results.

What does the output look like?

Given a picture of some of my Pi components, I get this, which is pretty accurate:

Where can I get the code?

https://github.com/StevenHickson/RPi_CaffeQuery

[1] http://white.stanford.edu/teach/index.php/An_Introduction_to_Convolutional_Neural_Networks

Consider donating to further my tinkering since I do all this and help people out for free.



Places you can find me
Read More..

Automatically downloading torrents with the Raspberry Pi

This is a script designed to intelligently and quickly find and download something as a torrent.
This is the second script in my AUI (Alternative User Interface) Series.


NOTE: This will work with any linux OS but I am using it on the Raspberry Pi.


This requires curl, libboost1.50-regex, and transmission. The setup script can install curl and boost regex. You will have to install transmission yourself.


I found myself getting frustrated with going to a torrent searching site and looking for a torrent and then downloading it. So I made this script to intelligently find the best torrent option. It doesnt require quotes and will format searches appropriately, even with spaces.

It uses regular expressions to find your download and starts it remotely in transmission.
I use transmission because then you can check the status of your download online.
I recommend this guide in order to set up transmission properly.


Ex.
download movie title
will quickly find and download movie title.

download show title  s01e01
will quickly find and download show title season 1, episode 1.

download wheezy
will quickly find and download the Raspberry Pi Debian Wheezy OS.

To install, download the zip here and run the InstallAUISuite.sh file located in the Install folder. It will ask you the download details in the script.
This will be your transmission username, password, port, and host.


Consider donating to further my tinkering.


Places you can find me
Read More..

Voice Command v2 0 for the Raspberry Pi

Voice Command 2.0 differences

Note: Updated version here
http://stevenhickson.blogspot.com/2013/06/voice-command-v30-for-raspberry-pi.html

Ive made some big changes since my last post with voice control with the Raspberry Pi.
You can now verify the keyword, change the keyword, change the response, put it in quiet mode to not talk to you, and put it in ignore mode to not try to answer questions not in your config file.
The config file format has also been changed from voice=command to voice==command, comments have been allowed in the config file by starting a line with #, and special settings can be done by starting a line with !.
Ive updated the TTS from espeak to Googles API since it sounds a lot better.
Finally, Ive made an update script in the Install folder, that way you dont have to reinstall every time new changes get pushed out to github. All of the source code is at:
https://github.com/StevenHickson/PiAUISuite

Video:

Heres a video demonstrating the new changes:


Special Options


The default special options are as follows:
!keyword==pi
!verify==1
!continuous==1
!quiet==0
!ignore==0
!filler==1
!thresh=0.7
!response=Yes sir?

response and keyword can be any string.
verify, continuous, quiet, filler, and ignore can be 1 or 0 (true or false respectively).
thresh can be any floating point number to set the appropriate volume.

Install Instructions

(this requires git)

sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh


Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


Consider donating to further my tinkering



Ive also created a man page fore voicecommand. You can access it with man voicecommand. It is shown below:

voicecommand

Section: voicecommand man page (8)
Updated: 13 May 2013
Index  

NAME

voicecommand - Listen to user defined strings and run the corresponding command  

SYNOPSIS

voicecommand [OPTIONS]...  

DESCRIPTION

voicecommand was developed for the Raspberry Pi but will work on any linux system with a microphone attached. It is a crude program, which uses basic comparisons to determine if your voicecommand fits a format specified in a config file; it it does, it runs the corresponding linux command. It supports auto-completion and variables as well as command verification, a continuous mode, and other options. For help/comments/questions, feel free to e-mail me at me@stevenhickson.com. I answer sporadically but do eventually respond.
 

OPTIONS

-?
Same as -h
-b
Turns off the FILL audio. The purpose of this was because the Raspbery Pi (or mine at least) cuts off the first few seconds of audio. This flag turns that feature off. You should only be concerned with this if you hear FILL before everything it says.
-c
Makes voicecommand run in continuous mode, where it will keep listening over and over again.
-e
Edits the voicecommand config file.
The format is voice==command
You can use any character except for newlines or ==
You can also put comments if the line starts with # and special options if the line starts with a !
Default options are shown as follows:
!keyword==pi,!verify==1,!continuous==1,!quiet==0,!ignore==0,!thresh=0.7,!response=Yes sir? keyword and response accept strings. verify, continuous, quiet, and ignore except 1 or 0 (true or false respectively). thresh excepts a floating point number. These allow you to set some of the flags as permanent options (though the flags can overwrite them temporarily).
-f /my-location/config-file

This allows you to load a different config file located in a different spot. The default one is in your home directory and is ~/.commands.conf
The config file must be formatted the same way.
-h

Shows this man page.
-i

Sets the ignore mode. When this flag is activated, if a command is not in the config file, nothing happens. The default behavior is to try to find an answer or response to that question and then speak it. This turns off that behavior.
-k word

Sets the keyword. The default is pi. If this flag is set, the verify and continuous flags are also set since this is only checked during those two modes.
      Ex. voicecommand -c -v -k Jarvis

-r word

Sets the response. The default is "Yes Sir?" (For version 1.0, it was Ready?. If this response is more than one word, it should be put in quotes, otherwise it doesnt need to be
      Ex. voicecommand -r Ready?

-t #

Sets the threshold for volume to determine if the keyword was spoken. This should be a floating point number. The default value is 0.7 which works well with the Logitech C310 camera/mic from about 6 feet away.
Ex. voicecommand -t 1.2
-q

Sets quiet mode on so that voicecommand never speaks through the audio output. It still prints everything but doesnt ever respond. This includes the keyword response.
-v

Makes voicecommand verify the keyword. This only happens in continuous mode so if this flag is set, the continuous flag will be set as well. The default mode is to not verify. When voicecommand hears any sound above the threshold, it says the response then listens for a command. The default keyword is pi. When the verify flag is set, after the threshold is met, voicecommand verifies that the keyword was spoken.

AUTHOR

Steven Hickson (me@stevenhickson.com)  

BUGS

No known bugs. To report bugs, send a clear description to me@stevenhickson.comSince this program is fairly crude, user typos could cause crashes/failed responses. Please read the man page thoroughly before submitting a bug.  

COPYRIGHT

Copyright © 2013 Steven Hickson. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it as long as you give credit to the author and include this license. There is NO WARRANTY, to the extent permitted by law.  

HISTORY

This is the second major version of this program  

SEE ALSO

http://stevenhickson.blogspot.com/



Consider donating to further my tinkering
Read More..

Streaming Other HD Video Sites on the Raspberry PI



For those that are interested, this will allow you to stream internet shows like The Daily Show on your Raspberry Pi in HD with no lag.

A week or so ago I posted a hack which allowed people to stream youtube videos in the browser here. Unfortunately, this same method didnt work out of the box for some other video sites. They would stream a couple seconds then just end (I found this to happen with the daily show).



I now have a fix for that and have a script called youtube-safe, which can stream (high-quality with no lag on a decent internet connection) any video site that works with youtube-dl.

If you already have the Youtube scripts in my PiAUISuite installed, you can just update, otherwise you have to go through the install script and select which parts you want (this one being under youtube).

Install Instructions


sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

**NOTE, this will ask you if you want to install a lot of different scripts because it is a SUITE. You only have to pick the ones you want to use. If you only want to use the youtube scripts, press n on any other question except for the dependencies and youtube.

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh



Once that is done, you can watch the daily show in 1080p like so:
youtube-safe "http://www.thedailyshow.com/full-episodes/"

Even better, if you have voicecommand installed on your system, add the following line to the bottom of your config file for it to play the newest daily show with your voice:
~Daily Show==youtube-safe "http://www.thedailyshow.com/full-episodes/"

Ill work on making a browser plugin for this as well.

Consider donating to further my tinkering


Places you can find me
Read More..

Mounting the home directory on a different drive on the Raspberry Pi


I found myself struggling with SD card corruption this week.
I think it was due to a combination of overclocking and an old SD card. Although I use svn or git with most of my code, occasionally I do a lot of work in a day and forget to add a file. After this last time, I decided to move my home directory to a partition on an external HDD just in case.

I will be posting some file recovery methods later in case you have also lost data.

Start by making sure your external drive is connected and open a terminal.
First of all you need to have root privileges to do all this (or use sudo privileges)
Make sure your drive is not mounted. To unmount it:
umount /mntpoint
If you already have your external drive partitioned, skip to Step 4.

Step 1: Partition External Drive

The fdisk command with the -l flag can list all of your drives and partitions. So start by running that:
fdisk -l
Pick the HDD you want to use (mine was /dev/sdb but Ill put sdx and you can fill in appropriately) and run fdisk again to see partition information
fdisk /dev/sdx
You should be in an interactive prompt. Type p to see the partitions. There should be none. If there arent any, skip to Step 3.

Step 2: Deleting or resizing

If you need the old partitions and want to shrink them, type q to exit the fdisk prompt, otherwise skip to Step  3.
If you are using the partitions and just want to resize them, then there are various commands to do that (also its a good idea to have a back up).
For ext3/ext4, just use: resize2fs /dev/sdx #size
Or use parted
parted /dev/sdx (opens interactive prompt)
resize #size
For ntfs: 
ntfsresize --size #sizeM /dev/sdx
Then open back up the fdisk prompt, you need to make new partitions that match.

Step 3: Writing partition changes

(Open fdisk back open if you closed it)
Now just use d #partition to delete any old partitions.
Then type n to make a new partition followed by p to make it a primary partition. If this is the only partition you need, you can make it the whole disk size. If you shrank a partition, you need to make two new partitions, with the first one having a size that matches your resize options.
Now type w to write changes to disk then q to quit. It will probably give you some warnings, it almost always does. Pay attention to them but dont freak out.
Now format the new partition (If you only made one partition #=1):
mkfs.ext4 /dev/sdx#

Step 4: Copying over your home directory files

Mount your new partition:
sudo mkdir /media/tmp
sudo mount -t ext4 /media/tmp
Navigate to your root folder
cd /home
Copy all your data recursively (this option seems to have worked the best for me to get all of the files including .bashrc and .vimrc files)
sudo cp -rp ./ /media/tmp

Step 5: Mounting your new home directory

Once that is finished, you can move the home directory and mount the new one (make sure no program is currently using the home directory or you will get errors).
sudo umount /media/tmp
sudo rm -rf /media/tmp (get rid of the tmp folder)
sudo mv /home /old_home
sudo mkdir /home
sudo echo "/dev/sdx# /home ext4 defaults,noatime,nodiratime 0 0" >> /etc/fstab
Again replacing x# with your drive number (mine was b2).
Now we can test it by mounting home. If this doesnt work, somewhere you messed up
sudo mount /home
After you have confirmed everything is working and copied over and you dont need your old home directory, you can delete it.
sudo rm -fr /old_home


Now you dont need to worry about SD Corruption.
References for help:
http://joshua14.homelinux.org/blog/?p=660
http://linuxtechres.blogspot.com/2007/08/how-to-use-ntfsresize-from-command-line.html



Consider donating to further my tinkering.


Places you can find me
Read More..

Controlling Raspberry Pi via text message

This script enables you to control your computer via text message. Think of it almost as a version of SSH over text message.

It is designed to intelligently and quickly check unread Google voice messages. If certain parameters are passed, it runs the command you send and returns the result.
This is the third script in my AUI (Alternative User Interface) Series.
This requires curl and libboost1.50-regex. The setup script can install curl and boost regex. 

NOTE: This will work with any linux OS but I am using it on the Raspberry Pi so if you are using something else, you will have to compile it yourself (make sure to change the Makefile flags).

The stable version is on github here:
https://github.com/StevenHickson/PiAUISuite

And the working copy source can be found here:
http://stevenhickson-code.googlecode.com/svn/trunk/AUI/TextCommand/


Google Voice unfortunately doesnt have an API available so I started writing my own.
I found this page and this page which were good references. Unfortunately, neither of these actually worked, so I wrote my own based off them. The script will install this and you are free to use it however you want as long as you cite me and follow GPLv3.

It works by using cron to run a script once every minute. The script checks your unread inbox messages and uses curl to make sure certain safety parameters are met. It is very important to check the unread inbox as it only pulls a 1-3 KB file rather than a 150+ KB file. This really adds up once a minute over time. If certain parameters are met, ie it has a valid phone number and command, then it runs the command you give it. The results of the command are then texted back to you. 
This will not work with interactive scripts like more or man



Installation Instructions

(this requires git)

sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


There are other scripts in here that you can ignore. It will ask you the username details in the script.
This will be your Google voice username, password, key, and valid number.

Your Google voice username will be your e-mail. For example:
John.Doe@gmail.com
Your password is your Google voice password:
ThisIsntMyPassword
The key is the valid command-word that proceeds commands to the machine. For example, mine is Cmd. So I text:
Cmd ls
to have the pi text the results of the current directory back.
Your valid number is the phone number you want your google voice to receive commands from (Not your Google voice number!). You must put the country code but not the + sign. Ex:
15553332222

After that everything should work.
Note, I worked out a few major bugs with the install script and it is reposted now. So make sure to get the newest version.

Consider donating to further my tinkering


Places you can find me





Read More..

Cloud storage on the Raspberry Pi



I recently started playing around with cloud storage on the Raspberry Pi. Im already using it as a web server and a media server, why not this as well.

I started hacking up something to make Dropbox work and then decided that was stupid and found some open source solutions instead.

I found two options that were easy to install and seemed to work decently.

The first one is Owncloud


If you already have apache installed and running, this one is easy (If not see here).

All you have to do is install the packages required, download the files and do some simple setup.

sudo apt-get update && sudo apt-get install curl libcurl3 php5-curl sqlite3 php5 php5-sqlite php5-gd php-xml-parser php5-intl

cd /var/www/
sudo wget http://download.owncloud.org/community/owncloud-5.0.2.tar.bz2
sudo tar -xvf owncloud-5.0.2.tar.bz2
sudo chown -R www-data:www-data owncloud
sudo nano /etc/apache2/sites-enabled/000-default
Then change the line AllowOverride None to AllowOveride All in the /var/www/ section.
sudo a2enmod rewrite
sudo a2enmod headers
sudo service apache2 restart

Now just go to your http://ip-address/owncloud/ with a separate computer or go to http://localhost/owncloud/ on the Raspberry Pi and pick a username and password.

Pros:

  • Can access local data from your external drives easily.
  • Can access your dropbox data.
  • Doesnt require its own service.
  • Password protected (storing the salted hash of the password!).
Cons:
  • Unencrypted SQL database that anyone can download.
  • Slow!
  • Doesnt automatically sort through your data like its features imply. You have to manually upload everything.


The second one is Seafile


This one is also pretty easy to install and has a Raspberry Pi specific version.
I put my stuff in a directory in my home folder but you could put it wherever. For more security, consider creating a special user for seafile.

sudo apt-get update && sudo apt-get install python2.7 python-setuptools python-simplejson python-imaging sqlite3
cd
mkdir cloud
cd cloud
wget http://seafile.googlecode.com/files/seafile-server_1.5.1_pi.tar.gz
tar -xzf seafile-server_*
mkdir installed
mv seafile-server_* installed
cd seafile-server-*
./setup-seafile.sh

The last script will install it and ask some easy questions for you to answer to set up things.
To run the seafile server, you have to do the following:

sudo ./seafile.sh start
sudo ./seahub.sh start

This has to be done every time your Raspberry Pi restarts, which is fairly easy using a cron script
crontab -e

then add:
@reboot sudo /home/pi/cloud/seafile-server-1.5.1/seafile.sh start
@reboot sudo /home/pi/cloud/seafile-server-1.5.1/seahub.sh start

Then save and exit.
For more help, see here.
Now just go to your http://ip-address:8000 with a separate computer or go to http://localhost:8000

Pros:

  • Fast!
  • Doesnt run if you dont want it to.
  • Doesnt have all of its files accessible over the normal webserver.
  • Requires username and password.
Cons:
  • Takes time to start up and sometimes seahub.sh doesnt start properly
  • Unencrypted SQL database (Though I havent found a way to easily grab this db).
  • Cant access your dropbox data..

After a quick trial with the two of them, Im going with seafile. I havent removed OwnCloud but Im seriously considering it do to the speed and security issues.

Please let me know your experiences with the two of them and any more options to try out!


Consider donating to further my tinkering.


Places you can find me
Read More..

Using Youtube on the Raspberry Pi without XBMC or gnash

There is an update to this here.

You can install this by pulling the source from git and running the InstallAUISuite.sh file.
Commands to install are below (your user should have sudo priveledges but you dont need to sudo or be root to run the commands unless shown otherwise):

sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


Demonstration:


So this is a quick video to demonstrate youtube working fast and easily on the Raspberry Pi without the use of XBMC or gnash.
I tried out gnash first which didnt work at all.
So then I tried out XBMC and although it is pretty, it is awfully slow so I decided to get youtube to work on my own.
The basis of this is really simple. There is a nifty program out there called youtube-dl that can get the media file from the website and download it. Its great because it does it fast and works for many other websites like the daily show and the colbert report.
So what I did was basically write a little script that analyzes your input and then gets the proper information from the youtube-dl program without downloading the video, then it sends this http stream to omxplayer to play.
It can handle playlists or individual files from multiple websites as well as a bunch of other things.

After that, I started implementing a nice little search feature using C++ and Curl.
Im starting to implement a GUI which will essentially look like youtube kind of. Until then I have this nifty search tool, which was essentially my start to the GUI I am currently creating.

If youve ever used XBMCs youtube, you will notice that this is a lot faster, and in my opinion, easier to use and more natural. Plus it only requires a tiny file on your system as opposed to XBMCs massive footprint.

The nice part of having an easy command line program like this is that it can be incorporated into a lot of other things easily. For instance, I have incorporated it into my voicecommand script as shown in the video.

The source code can be found here. To install see the top.

Sources:
This post for using axel with the youtube-dl.
This page for the youtube-dl source and documentation.

 Consider donating to further my tinkering


Places you can find me
Read More..