Difference between revisions of "Raspberry Pi"

From Robert-Depot
Jump to: navigation, search
(C-Media USB sound device)
 
(150 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
=Setup=
 
=Setup=
 +
==Install OS on SD card==
 +
*Purchase a verified SDHC cards - http://elinux.org/RPi_SD_cards
 +
*Follow EASY setup - http://elinux.org/RPi_Easy_SD_Card_Setup
 
*resizing main partition from booted raspberry pi - http://elinux.org/RPi_Resize_Flash_Partitions
 
*resizing main partition from booted raspberry pi - http://elinux.org/RPi_Resize_Flash_Partitions
*setup C-media usb sound device - http://www.cpmspectre.pwp.blueyonder.co.uk/raspberry_pi/MoinMoinExport/DaffodilUSBSoundAdapter.html
+
==TextMate and rmate for simple remote editing==
=Improvements=
+
*install textmate on os x system
 +
*install ruby on raspberry pi:
 +
<syntaxhighlight lang="bash">
 +
sudo apt-get install ruby
 +
</syntaxhighlight>
 +
*install rmate on raspberry pi:
 +
<syntaxhighlight lang="bash">
 +
sudo gem install rmate
 +
</syntaxhighlight>
 +
*setup ssh tunneling
 +
<syntaxhighlight lang="bash">
 +
ssh -R 52698:localhost:52698 pi@192.168.2.144
 +
</syntaxhighlight>
 +
 
 +
=Debugging=
 +
==Using a USB to TTL cable==
 +
*Install USB drivers
 +
**for os x - http://sourceforge.net/projects/osx-pl2303/
 +
*Connect pins like so: http://www.adafruit.com/images/medium/954close_MED.jpg
 +
*NOTE: LEAVE THE RED WIRE OFF TO USE EXTERNAL POWER SUPPLY. leave the red wire connected to power pi from the usb cable.
 +
*Use <code>screen</code> to connect to pi. From Terminal, start session:
 +
**<code>screen /dev/cu.usbserial 115200</code>
 +
==What port is my raspberry pi on?==
 +
*list all device addresses on a port
 +
**<code>arp -i bridge0 -a</code>
 +
==Set IP address==
 +
*On OS X set ethernet to DHCP with manual addressing. Choose address 192.168.3.1.
 +
*Scan for raspberry pi: <syntaxhighlight lang="bash">sudo nmap -sP 192.168.2.1/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'</syntaxhighlight>
 +
==Set .local name==
 +
 
 +
=Maintenance=
 +
==Backup your System Image==
 +
===backup with rpi-clone===
 +
*uses dd and rsync:
 +
https://github.com/billw2/rpi-clone
 +
 
 +
 
 +
===backup with tar.gz===
 +
http://sysmatt.blogspot.com/2014/08/backup-restore-customize-and-clone-your.html
 +
 
 +
===backup with dd===
 +
*power off the pi, remove the sd card, and insert it in your computer.
 +
*check what drive it is. on os x:
 +
**<code>df</code>
 +
**you should see something like ''/dev/disk2s1'', figure out which is your hard drive and which is the SD card.
 +
*unmount the card.
 +
**<code>diskutil unmount /dev/disk2s1</code>
 +
*duplicate the disk to your hard drive. replace the second argument, ''of=/Volumes/Cistern/RaspberryPi/...'' with the path and filename where you want to backup the image.
 +
**<code>sudo dd if=/dev/rdisk2 of=/Volumes/Cistern/RaspberryPi/wheezy-20130522-backup.img bs=1m</code>
 +
**you can hit '''Ctrl-t''' on your keyboard to see stats about the copy in progress.
 +
*when it is done. eject the disk.
 +
**<code>diskutil eject /dev/rdisk2</code>
 +
 
 +
==Restore from backup image==
 +
*repeat steps above to insert SD card, identify, and unmount.
 +
*duplicate from image file to sd card:
 +
<syntaxhighlight lang="bash">sudo dd if=twomey2-20140130-backup.img of=/dev/rdisk2 bs=1m</syntaxhighlight>
 +
 
 +
==Shrinking too large image==
 +
*http://www.raspberrypi.org/phpBB3/viewtopic.php?t=19468&f=26
 +
==Backup and Restore Raspberry Pi images to smaller SD cards, using a Linux computer==
 +
*http://redey.net/Blog/?p=407
 +
 
 +
==Add a Data Partition==
 +
*shrink http://www.hack-job.org/general/resize-raspberrypi-root-partition/
 +
*shrink http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=60161&p=450676&hilit=shrink+partition#p450676
 +
 
 +
'''4 GB''':
 +
<syntaxhighlight lang="bash">
 +
rtwomey@rtwomey-MacBookPro:~$ sudo fdisk -u /dev/mmcblk0
 +
[sudo] password for rtwomey:
 +
You will not be able to write the partition table.
 +
 
 +
Command (m for help): p
 +
 
 +
Disk /dev/mmcblk0: 3959 MB, 3959422976 bytes
 +
4 heads, 16 sectors/track, 120832 cylinders, total 7733248 sectors
 +
Units = sectors of 1 * 512 = 512 bytes
 +
Sector size (logical/physical): 512 bytes / 512 bytes
 +
I/O size (minimum/optimal): 512 bytes / 512 bytes
 +
Disk identifier: 0x000f06a6
 +
 
 +
        Device Boot      Start        End      Blocks  Id  System
 +
/dev/mmcblk0p1            8192      122879      57344    c  W95 FAT32 (LBA)
 +
/dev/mmcblk0p2          122880    7733247    3805184  83  Linux
 +
</syntaxhighlight>
 +
 
 +
'''16 GB'''
 +
<syntaxhighlight lang="bash">
 +
rtwomey@rtwomey-MacBookPro:~$ sudo fdisk -u /dev/mmcblk0
 +
 
 +
Command (m for help): p
 +
 
 +
Disk /dev/mmcblk0: 16.1 GB, 16130244608 bytes
 +
4 heads, 16 sectors/track, 492256 cylinders, total 31504384 sectors
 +
Units = sectors of 1 * 512 = 512 bytes
 +
Sector size (logical/physical): 512 bytes / 512 bytes
 +
I/O size (minimum/optimal): 512 bytes / 512 bytes
 +
Disk identifier: 0x00014d34
 +
 
 +
        Device Boot      Start        End      Blocks  Id  System
 +
/dev/mmcblk0p1            8192      122879      57344    c  W95 FAT32 (LBA)
 +
/dev/mmcblk0p2          122880    31504383    15690752  83  Linux
 +
</syntaxhighlight>
 +
 
 +
==update firmware with rpi-update==
 +
*https://github.com/Hexxeh/rpi-update
 +
 
 +
=Configuration=
 +
==create local wifi hotspot==
 +
*http://www.daveconroy.com/turn-your-raspberry-pi-into-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/
 +
*https://forums.adafruit.com/viewtopic.php?f=19&t=47716
 +
 
 +
==create .local domain name for raspberry pi==
 +
*http://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/
 +
 
 +
==apt-get not connecting==
 +
*add DNS server. see here:
 +
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=63&t=17016
 +
 
 +
==vim instead of vi==
 +
vim instead of vi so arrow keys work:
 +
*<code>sudo apt-get update</code>
 +
*<code>sudo apt-get -y install vim</code>
 +
 
 +
==bash configuration==
 +
*edit .bashrc:
 +
**uncomment <code>ll</code> and <code>la</code>
 +
==add a user account==
 +
while logged in as PI user:
 +
*<code>sudo adduser MyUser</code>
 +
*<code>sudo adduser MyUser sudo</code>
 +
now it is time to test out your new account.
 +
*logout as pi:
 +
**<code>logout</code>
 +
*at the login prompt, login as your username created above.
 +
*CONGRATS!
 +
*time to shut down your system:
 +
**<code>sudo poweroff</code> type in your password. the system will shut down.
 +
 
 +
==add audio for non-default user==
 +
getting audio to work for a non-default user:
 +
#<code>sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input rtwomey</code>
 +
#logout, then login
 +
 
 +
==SSH Login==
 
ssh login:
 
ssh login:
 
*should work by default. you just need to know the IP address.  
 
*should work by default. you just need to know the IP address.  
*Connecting to local mac it through netgear box, it's probably 192.168.2.3, or 192.168.2.2.
+
*Connecting to a local mac with internet sharing on, it's probably 192.168.2.3, or 192.168.2.2.
vnc remote login:
+
*Store your public key on the remote system, so you aren't prompted for password:
 +
http://www.linuxproblem.org/art_9.html
 +
 
 +
==not resolving IP addresses==
 +
*<code>sudo vi /etc/resolv.conf</code>
 +
*add the line <code>nameserver 8.8.8.8</code>
 +
**this is the google nameserver.
 +
 
 +
==vnc remote==
 
*http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc/installing-vnc
 
*http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc/installing-vnc
getting audio to work for a non-default user:
 
#sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input rtwomey
 
#logout/login
 
 
*http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=34094
 
*http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=34094
vim instead of vi so arrow keys work:
+
==overclocking==
#sudo apt-get update
+
*using command line http://www.jeremymorgan.com/tutorials/raspberry-pi/how-to-overclock-raspberry-pi/
#sudo apt-get -y install vim
+
*using raspi-config http://elinux.org/RPi_raspi-config
overclocking
+
 
*http://www.jeremymorgan.com/tutorials/raspberry-pi/how-to-overclock-raspberry-pi/
+
==scp==
 +
*to copy photos to my current computer, over ethernet cable:
 +
**scp rtwomey@192.168.2.3:~/images/*.jpg ~/Pictures/
 +
*'''if you've stored your ssh public key, you won't be prompted for password!'''
 +
 
 
=Software=
 
=Software=
 +
==pocketsphinx / usb mic==
 +
https://wolfpaulus.com/journal/embedded/raspberrypi2-sr/
 +
==google speech scripts==
 +
<s>*install pyaudio:
 +
<syntaxhighlight lang="bash">
 +
sudo apt-get install python-pyaudio
 +
</syntaxhighlight>
 +
</s>
 +
*install pyaudio dependencies:
 +
<syntaxhighlight lang="bash">
 +
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
 +
</syntaxhighlight>
 +
*install pyaudio:
 +
<syntaxhighlight lang="bash">
 +
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
 +
cd pyaudio
 +
sudo python setup.py install
 +
</syntaxhighlight>
 +
*install flac:
 +
<syntaxhighlight lang="bash">
 +
sudo apt-get install flac
 +
</syntaxhighlight>
 +
*clone google speech scripts:
 +
<syntaxhighlight lang="bash">
 +
git clone https://github.com/jeysonmc/python-google-speech-scripts
 +
</syntaxhighlight>
 +
 +
==Voice Command==
 +
*http://www.instructables.com/id/Raspberri-Personal-Assistant/?ALLSTEPS
 +
*http://stevenhickson.blogspot.nl/2013/06/installing-and-updating-piauisuite-and.html
 +
*http://blog.oscarliang.net/raspberry-pi-voice-recognition-works-like-siri/
 +
===Jasper===
 +
http://jasperproject.github.io/documentation/software/architecture.png
 +
*http://jasperproject.github.io/
 +
 +
==FM Transmitter==
 +
*FM transmitter with python code - http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter
 +
**[https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CDYQIDAA&url=http%3A%2F%2Fwebcache.googleusercontent.com%2Fsearch%3Fq%3Dcache%3A2sSuOAJQhN4J%3Awww.icrobotics.co.uk%2Fwiki%2Findex.php%2FTurning_the_Raspberry_Pi_Into_an_FM_Transmitter%2B%26cd%3D1%26hl%3Den%26ct%3Dclnk%26gl%3Dus&ei=hRNoUdL8BOjNiwKcyoHQDQ&usg=AFQjCNGyc_GeDwSk8vkDfCza2kXyzizQQg&sig2=KDBObi8f6eNfyZo8TMYJOg&bvm=bv.45175338,d.cGE cached]
 +
**this works!!
 +
*get file with wget:
 +
**<code>wget http://www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz</code>
 +
*unzip the file:
 +
**<code>tar -xvzf Pifm.tar.gz </code>
 +
*What files were created extracted, and where did it put them?
 +
**<code>ls -la</code>
 +
*Make a '''radio''' folder and move the files in.
 +
**<code>mkdir radio</code>
 +
**<code>mv pifm.* radio</code>
 +
**<code>mv PiFm.py radio</code>
 +
**<code>mv sound.wav radio</code>
 +
 
==gphoto2==
 
==gphoto2==
 +
*installing:
 +
**<code>sudo apt-get install gphoto2</code>
 +
*take a photo:
 +
**<code>gphoto2 --capture-image-and-download</code>
 +
*after taking a photo it's necessary to reset the USB port. use usbreset util.
 +
**<code>usbreset /dev/bus/usb/001/004</code>
 +
**put your /dev/bus/usb device as the second argument above. you can find it from --list-ports.
 +
*list cameras:
 +
**<code>gphoto2 --list-ports</code>
 
*control and capture of DSLR http://skowron.biz/artikel/gphoto-raspberry/
 
*control and capture of DSLR http://skowron.biz/artikel/gphoto-raspberry/
 +
 +
==usbreset==
 +
*build by hand: http://toothbrushsymphony.blogspot.com/2013/01/usb-reset-on-raspberry-pi.html
 +
*apt-get?
 
==festival==
 
==festival==
 
*festival on raspberry pi - http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis)
 
*festival on raspberry pi - http://elinux.org/RPi_Text_to_Speech_(Speech_Synthesis)
Line 28: Line 249:
 
*http://wiki.roberttwomey.com/Setting_Up_Festival_TTS#Using_Voice_on_Raspberry_Pi
 
*http://wiki.roberttwomey.com/Setting_Up_Festival_TTS#Using_Voice_on_Raspberry_Pi
 
*sphinx on raspberry pi - https://sites.google.com/site/observing/Home/speech-recognition-with-the-raspberry-pi
 
*sphinx on raspberry pi - https://sites.google.com/site/observing/Home/speech-recognition-with-the-raspberry-pi
 +
*http://www.raspberrypi.org/phpBB3/viewtopic.php?f=37&t=9487
 +
==Pockesphinx==
 +
*Install libasound2-dev, bison (bison was already installed on my raspberry pi):
 +
**<code>sudo apt-get install libasound2-dev </code>
 +
*Get sphinxbase and pocketsphinx, preferrably putting them in a code directory:
 +
**<code>wget http://sourceforge.net/projects/cmusphinx/files/sphinxbase/0.8/sphinxbase-0.8.tar.gz</code>
 +
**<code>wget http://sourceforge.net/projects/cmusphinx/files/pocketsphinx/0.8/pocketsphinx-0.8.tar.gz</code>
 +
*Unzip:
 +
**<code>tar -xzf sphinxbase-0.8.tar.gz</code>
 +
**<code>tar -xzf pocketsphinx-0.8.tar.gz</code>
 +
*Generate configuration files. In the sphinxbase-0.8 directory:
 +
**<code>./autogen.sh</code>
 +
**<code>make</code>
 +
**<code>make install</code>
 +
*Repeat in pocketsphinx-0.8 directory.
 +
*test is out
 +
**<code>src/programs/pocketsphinx_continuous -samprate 48000</code>
 +
 
==megahal==
 
==megahal==
 
*try it -
 
*try it -
 
==supercollider==
 
==supercollider==
 +
*try this: http://wiki.linuxaudio.org/wiki/raspberrypi
 +
 +
others
 +
 +
*installing on rpi: http://sam.aaron.name/2012/11/02/supercollider-on-pi.html
 +
*example install directory: <code>/usr/share/doc/supercollider/examples/</code>
 
*http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SC-on-Beagle-Board-Raspberry-Pi-td7581949.html
 
*http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/SC-on-Beagle-Board-Raspberry-Pi-td7581949.html
 
*satellite CCRMA - https://ccrma.stanford.edu/wiki/Satellite_CCRMA_First_Steps
 
*satellite CCRMA - https://ccrma.stanford.edu/wiki/Satellite_CCRMA_First_Steps
 +
 +
==nltk==
 +
*http://www.raspberrypi.org/phpBB3/viewtopic.php?f=9&t=6097
 +
*install setup tools
 +
**<code>wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg#md5=fe1f997bc722265116870bc7919059ea</code>
 +
**<code>sudo sh setuptools-0.6c11-py2.7.egg</code>
 +
*install pip
 +
**<code>sudo easy_install pip</code>
 +
*install numpy (precompiled binary)
 +
**<code>sudo apt-get install python-numpy</code>
 +
*install nltk
 +
**<code>sudo pip install nltk --upgrade</code>
 +
*run nltk
 +
**run python then type import nltk
 +
==OpenCV==
 +
*http://www.technolabsz.com/2013/03/how-to-easily-install-opencv-on.html
 +
==hd video playback==
 +
*omxplayer http://elinux.org/Omxplayer
 +
**play a file: <code>omxplayer -o hdmi ~/Movies/robot_playing_catch.mp4</code>
 +
*play script: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=9789&p=112154
 +
==Video==
 +
*RPi video looper - http://www.timschwartz.org/raspberry-pi-video-looper/
 +
 +
==OSC==
 +
===liblo===
 +
To use liblo to write an OSC client and server in C, first install the liblo development package on both the computer you would like to broadcast from (the client) and the computer that will receive the messages (the server). Using APT:
 +
<code>apt-get install liblo-dev</code>
 +
 +
Then, visit http://liblo.sourceforge.net/ and navigate to the example code or documentation. The example code provides a simple client and server. If you're just copying and pasting these, and would like to quickly compile them and test that they work, do the following for the server:
 +
<nowiki>
 +
wget http://liblo.sourceforge.net/examples/example_server.c
 +
gcc -o server example_server.c -llo
 +
./server</nowiki>
 +
And for the client:
 +
<nowiki>
 +
wget http://liblo.sourceforge.net/examples/example_client.c</nowiki>
 +
Then on the line defining an <code>lo_address</code>, change <code>NULL</code> to the IP address of your server. Finally
 +
<nowiki>
 +
gcc -o client example_client.c -llo
 +
./client</nowiki>
 +
If you've done everything successfully, you should see a variety of sample output from the running <code>server</code> program.
 +
==receive osc messages through puredata pd==
 +
*https://www.youtube.com/watch?v=ZBX7UzXTmd4
 +
*execute shell commands http://puredata.hurleur.com/sujet-9005-inteface-shell-scripts
 +
==pyOSC==
 +
*http://www.raspberrypi.org/forums/viewtopic.php?t=59714&p=446513
 +
 +
=Graphics=
 +
==OpenGL==
 +
Using OpenGL on the Raspberry Pi appears to be pretty idiosyncratic. For instance, see https://benosteen.wordpress.com/2012/04/27/using-opengl-es-2-0-on-the-raspberry-pi-without-x-windows/. Don't be misled by what is described on that webpage. While correct, far simpler example projects exist on the Raspberry Pi at /opt/vc/src/hello_pi. These are very useful! Read the <code>README</code> there, and get cracking. To get started, you can build every project by running:
 +
<nowiki>
 +
sh rebuild.sh</nowiki>
 +
If you would only like to build a subset of the projects, first <code>cd</code> to <code>/opt/vc/src/hello_pi/libs</code>, and build each library included there. Specifically:
 +
<nowiki>
 +
cd /opt/vc/src/hello_pi/libs/ilcient && make
 +
cd ../vgfont && make</nowiki>
 +
After these libraries are built, you can then <code>cd</code> to each example project, <code>make</code>, and run the resultant binary file. Please note that these instructions are repeated in the included <code>README</code> file.
 +
 +
=Pi Camera=
 +
*getting started - http://www.raspberrypi.org/archives/3890
 +
*code: https://github.com/raspberrypi/userland/tree/master/host_applications/linux/apps/raspicam
 +
==taking photos with raspistill==
 +
<syntaxhighlight lang="bash">
 +
raspistill -o image.jpg
 +
</syntaxhighlight>
 +
*faster photo: https://bitbucket.org/niklas_rother/rasperry-pi-userland/raw/master/host_applications/linux/apps/raspicam/raspifastcamd_scripts
 +
 +
==taking video with raspivid==
 +
*take a video
 +
<syntaxhighlight lang="bash">
 +
raspivid -o video.h264
 +
</syntaxhighlight>
 +
*Convert to mp4
 +
<syntaxhighlight lang="bash">
 +
ffmpeg -i video.h264 -vcodec copy video.mp4
 +
</syntaxhighlight>
 +
 +
==new video modes==
 +
*http://www.raspberrypi.org/new-camera-mode-released/
 +
*install rpi-update:
 +
<syntaxhighlight lang="bash">
 +
sudo apt-get install rpi-update
 +
</syntaxhighlight>
 +
*update:
 +
<syntaxhighlight lang="bash">
 +
sudo rpi-update
 +
</syntaxhighlight>
 +
*exploring camera modes:
 +
<syntaxhighlight lang="bash">
 +
v4l2-ctl -p 90
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="bash">
 +
v4l2-ctl -v width=640,height=480,pixelformat=H264
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="bash">
 +
v4l2-ctl --stream-mmap=3 --stream-count=900 --stream-to=test90fps.h264
 +
</syntaxhighlight>
 +
 +
*half resolution, binned:
 +
<syntaxhighlight lang="bash">
 +
raspivid -w 1296 -h 972 -t 10000 -o pi_0.h264
 +
</syntaxhighlight>
 +
*90 frames per second VGA:
 +
<syntaxhighlight lang="bash">
 +
raspivid -w 640 -h 480 -fps 90 -t 10000 -o test90fps.h264
 +
</syntaxhighlight>
 +
 +
 +
 +
==streaming the pi camera==
 +
*RPi:
 +
<syntaxhighlight lang="bash">
 +
raspivid -t 999999 -o - | nc 192.168.2.31 5001
 +
</syntaxhighlight>
 +
*Laptop:
 +
<syntaxhighlight lang="bash">
 +
nc -l 5001 | mplayer -fps 31 -cache 1024 -
 +
</syntaxhighlight>
 +
*low-latency: http://blog.tkjelectronics.dk/2013/06/how-to-stream-video-and-audio-from-a-raspberry-pi-with-no-latency/
 +
 +
==python interface (picam)==
 +
*http://www.raspberrypi.org/learning/python-picamera-setup/
 +
==motion-triggered capture==
 +
*PIR triggered (motion triggered) camera
 +
*PIR sensor - http://www.raspberrypi.org/learning/parent-detector/
 +
*launch python script in detached screen session:
 +
<syntaxhighlight lang="bash">
 +
sudo screen -dmS mocap /home/pi/code/housemachine/pircam.py
 +
</syntaxhighlight>
 +
*reconnect to screen:
 +
<syntaxhighlight lang="bash">
 +
sudo screen -r mocap
 +
</syntaxhighlight>
 +
*copy new video files:
 +
<syntaxhighlight lang="bash">
 +
rsync -va --ignore-existing pi@office.local:~/videos/pircam/ ~/Pictures/ceiling_fisheye/
 +
</syntaxhighlight>
 +
 +
*mmal opencv modetect
 +
*set recording format in code.
 +
*with motion detection opencv - http://www.sodnpoo.com/posts.xml/raspberrypi_camera_with_opencv_motion_detection_and_recording.xml
 +
*https://github.com/sodnpoo/rpi-mmal-opencv-modetect
 +
*run in terminal and save motion frames to video:
 +
<syntaxhighlight lang="bash">
 +
./mmal_opencv_modect > video.h264
 +
</syntaxhighlight>
 +
==wrap h264 then combine two files==
 +
*concat first and second half:
 +
<syntaxhighlight lang="bash">
 +
avconv -i concat:a.h264\|b.h264 -c copy sum.h264
 +
</syntaxhighlight>
 +
*wrap as h264 (with avconv):
 +
<syntaxhighlight lang="bash">
 +
avconv -i sum.h264 -vcodec copy sum2.mp4
 +
</syntaxhighlight>
 +
*wrap as h264 (with ffmpeg):
 +
<syntaxhighlight lang="bash">
 +
ffmpeg -i sum.h264 -vcodec copy sum.mp4
 +
</syntaxhighlight>
 +
 +
==alternate lens mounts==
 +
*Adding an M12 mount: http://wiki.raspberrytorte.com/index.php?title=Camera_Module_Lens_Modifcation#Lens_Mount_Modification
 +
 +
=Wolfson Audio=
 +
*update wolfson audio drivers - https://blog.georgmill.de/2015/02/18/update-for-wolfson-audio-card-on-raspberry-pi/
 +
*Command line recording - http://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2014/04/06/wolfson-audio-project
 +
==Jack from OSX to Raspberry Pi==
 +
On Raspberry Pi:
 +
*wolfson script to select audio output:
 +
<syntaxhighlight lang="bash">Playback_to_Lineout.sh</syntaxhighlight> or the direct amixer commands
 +
<syntaxhighlight lang="bash">
 +
amixer -Dhw:0 cset name='HPOUT2 Digital Switch' on
 +
amixer -Dhw:0 cset name='HPOUT2L Input 1' AIF1RX1
 +
amixer -Dhw:0 cset name='HPOUT2L Input 1 Volume' 32
 +
amixer -Dhw:0 cset name='HPOUT2R Input 1' AIF1RX2
 +
amixer -Dhw:0 cset name='HPOUT2R Input 1 Volume' 32
 +
</syntaxhighlight>
 +
*run dbus:
 +
<syntaxhighlight lang="bash">
 +
eval dbus-launch --auto-syntax </syntaxhighlight>
 +
*copy results and export them:
 +
<syntaxhighlight lang="bash">
 +
export DBUS_SESSION_BUS_ADDRESS= ...
 +
export DBUS_SESSION_BUS_PID= ...
 +
</syntaxhighlight>
 +
*start jackd:
 +
<syntaxhighlight lang="bash">jackd -R -T -p 32 -d alsa -n 3 -p 2048 -r 44100 -i2 -o2 &</syntaxhighlight>
 +
*start netone pointed to slave IP:
 +
<syntaxhighlight lang="bash">jack_netsource -H 192.168.0.104 &</syntaxhighlight>
 +
 +
On OS X:
 +
*configure jack for necessary outputs (only done once) (2 in 2 out)
 +
*qjackctl with netone backend
 +
 +
On Pi:
 +
*route jack signals:
 +
<syntaxhighlight lang="bash">
 +
jack_connect netjack:capture_1 system:playback_1
 +
jack_connect netjack:capture_2 system:playback_2
 +
</syntaxhighlight>
 +
 +
*jack routing - https://gist.github.com/nyarla/36724e8931fa6bc244a0
 +
*https://github.com/jackaudio/jackaudio.github.com/wiki/WalkThrough_User_NetJack2
 +
 +
=Hardware Peripherals=
 +
Verified Peripherals - http://elinux.org/RPi_VerifiedPeripherals
 +
 +
==C-Media USB sound device==
 +
*setting up with alsamixer, etc - http://asliceofraspberrypi.blogspot.com/2013/02/adding-audio-input-device.html
 +
*setup C-media usb sound device - http://www.cpmspectre.pwp.blueyonder.co.uk/raspberry_pi/MoinMoinExport/DaffodilUSBSoundAdapter.html
 +
==U9 MiniMic==
 +
<syntaxhighlight lang="bash">arecord -f dat | aplay -f dat &</syntaxhighlight>
 +
 +
==C920==
 +
*USB packet loss (90% of frames)
 +
**http://www.raspberrypi.org/phpBB3/viewtopic.php?t=29879
 +
**beagleboard http://www.oz9aec.net/index.php/gstreamer/473-using-the-logitech-c920-webcam-with-gstreamer
 +
**http://www.oz9aec.net/index.php/beaglebone/476-turning-the-beaglebone-into-a-high-definition-ip-camera#comment-678839135
 +
 
==microline 320 printer ==
 
==microline 320 printer ==
*parallel:/dev/usblp0
+
===installing===
 +
*install cups
 +
**<code>sudo apt-get install cups</code>
 +
**willtake a little while
 +
*install menu item:
 +
**<code>sudo apt-get install system-config-printers</code>
 +
*reboot
 +
*add printer
 +
**start ltxde:
 +
***<code>startx</code>
 +
**Select ''Menu->Preferences->Printing''
 +
**Printer should autodetect. Or you can enter the URI manually: <code>parallel:/dev/usblp0</code>
 +
**Change model to Generic, type Raw. This will pass raw data to printer.
 
*http://ubuntuforums.org/showthread.php?t=1436079&page=2
 
*http://ubuntuforums.org/showthread.php?t=1436079&page=2
 +
===command line===
 +
*printing
 +
**<code>cat myTextFile.txt | lp -oraw</code>
 +
*list printers
 +
**<code>lpstat -p -d</code>
 +
*lp help http://www.cups.org/documentation.php/options.html
 +
==Wireless Adapters==
 +
*Adafruit adapter: https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/install-software
 +
*LB-Link with mt7601: https://www.raspberrypi.org/forums/viewtopic.php?t=49864
 +
**for kernel 3.18.7-v7: https://dl.dropboxusercontent.com/u/80256631/mt7601-3.18.7-v7-755.tar.gz
 +
 +
=GPIO=
 +
*pin over-voltage protection circuits - http://elinux.org/RPi_Tutorial_EGHS:GPIO_Protection_Circuits
 +
*light example - https://projects.drogon.net/raspberry-pi/gpio-examples/tux-crossing/gpio-examples-1-a-single-led/
 +
**uses wiringPI, command line tool, for ex:<code>gpio</code>
 +
**installed using git - https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/
 +
==through python==
 +
*follow adafruit - http://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/overview
 +
**Rpi.GPIO -
 +
**requires python-dev
 +
**python-rpi.gpio
 +
*https://code.google.com/p/raspberry-gpio-python/
 +
==Logic Level Conversion==
 +
*RPi is 3.3V.
  
 
=untested=
 
=untested=
Line 42: Line 542:
 
*opencv - http://mitchtech.net/raspberry-pi-opencv/
 
*opencv - http://mitchtech.net/raspberry-pi-opencv/
 
*julius - http://www.aonsquared.co.uk/raspi_voice_control
 
*julius - http://www.aonsquared.co.uk/raspi_voice_control
 
+
=Applications=
 +
==Use as AirPlay receiver==
 +
*http://lifehacker.com/5978594/turn-a-raspberry-pi-into-an-airplay-receiver-for-streaming-music-in-your-living-room
 +
*http://www.raywenderlich.com/44918/raspberry-pi-airplay-tutorial
 
=Problems=
 
=Problems=
 
*raspberry pi resets audio device after recording begins. similar to this complaint - http://www.raspberrypi.org/phpBB3/viewtopic.php?t=12086&p=135385
 
*raspberry pi resets audio device after recording begins. similar to this complaint - http://www.raspberrypi.org/phpBB3/viewtopic.php?t=12086&p=135385
=Uses=
+
=Course of Instruction=
==FM Transmitter==
+
*week 1
*FM transmitter with python code - http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter
+
*week 2
**this works!!
+
*[[Raspberry Pi - Week 3]]
 +
*[[Raspberry Pi - Week 4]]

Latest revision as of 17:19, 31 October 2015

<<< back to Wiki Home

Contents

Setup

Install OS on SD card

TextMate and rmate for simple remote editing

  • install textmate on os x system
  • install ruby on raspberry pi:
sudo apt-get install ruby
  • install rmate on raspberry pi:
sudo gem install rmate
  • setup ssh tunneling
ssh -R 52698:localhost:52698 pi@192.168.2.144

Debugging

Using a USB to TTL cable

  • Install USB drivers
  • Connect pins like so: 954close_MED.jpg
  • NOTE: LEAVE THE RED WIRE OFF TO USE EXTERNAL POWER SUPPLY. leave the red wire connected to power pi from the usb cable.
  • Use screen to connect to pi. From Terminal, start session:
    • screen /dev/cu.usbserial 115200

What port is my raspberry pi on?

  • list all device addresses on a port
    • arp -i bridge0 -a

Set IP address

  • On OS X set ethernet to DHCP with manual addressing. Choose address 192.168.3.1.
  • Scan for raspberry pi:
    sudo nmap -sP 192.168.2.1/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
    

Set .local name

Maintenance

Backup your System Image

backup with rpi-clone

  • uses dd and rsync:

https://github.com/billw2/rpi-clone


backup with tar.gz

http://sysmatt.blogspot.com/2014/08/backup-restore-customize-and-clone-your.html

backup with dd

  • power off the pi, remove the sd card, and insert it in your computer.
  • check what drive it is. on os x:
    • df
    • you should see something like /dev/disk2s1, figure out which is your hard drive and which is the SD card.
  • unmount the card.
    • diskutil unmount /dev/disk2s1
  • duplicate the disk to your hard drive. replace the second argument, of=/Volumes/Cistern/RaspberryPi/... with the path and filename where you want to backup the image.
    • sudo dd if=/dev/rdisk2 of=/Volumes/Cistern/RaspberryPi/wheezy-20130522-backup.img bs=1m
    • you can hit Ctrl-t on your keyboard to see stats about the copy in progress.
  • when it is done. eject the disk.
    • diskutil eject /dev/rdisk2

Restore from backup image

  • repeat steps above to insert SD card, identify, and unmount.
  • duplicate from image file to sd card:
sudo dd if=twomey2-20140130-backup.img of=/dev/rdisk2 bs=1m

Shrinking too large image

Backup and Restore Raspberry Pi images to smaller SD cards, using a Linux computer

Add a Data Partition

4 GB:

rtwomey@rtwomey-MacBookPro:~$ sudo fdisk -u /dev/mmcblk0
[sudo] password for rtwomey: 
You will not be able to write the partition table.

Command (m for help): p

Disk /dev/mmcblk0: 3959 MB, 3959422976 bytes
4 heads, 16 sectors/track, 120832 cylinders, total 7733248 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000f06a6

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     7733247     3805184   83  Linux

16 GB

rtwomey@rtwomey-MacBookPro:~$ sudo fdisk -u /dev/mmcblk0

Command (m for help): p

Disk /dev/mmcblk0: 16.1 GB, 16130244608 bytes
4 heads, 16 sectors/track, 492256 cylinders, total 31504384 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00014d34

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880    31504383    15690752   83  Linux

update firmware with rpi-update

Configuration

create local wifi hotspot

create .local domain name for raspberry pi

apt-get not connecting

  • add DNS server. see here:

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=63&t=17016

vim instead of vi

vim instead of vi so arrow keys work:

  • sudo apt-get update
  • sudo apt-get -y install vim

bash configuration

  • edit .bashrc:
    • uncomment ll and la

add a user account

while logged in as PI user:

  • sudo adduser MyUser
  • sudo adduser MyUser sudo

now it is time to test out your new account.

  • logout as pi:
    • logout
  • at the login prompt, login as your username created above.
  • CONGRATS!
  • time to shut down your system:
    • sudo poweroff type in your password. the system will shut down.

add audio for non-default user

getting audio to work for a non-default user:

  1. sudo usermod -a -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input rtwomey
  2. logout, then login

SSH Login

ssh login:

  • should work by default. you just need to know the IP address.
  • Connecting to a local mac with internet sharing on, it's probably 192.168.2.3, or 192.168.2.2.
  • Store your public key on the remote system, so you aren't prompted for password:

http://www.linuxproblem.org/art_9.html

not resolving IP addresses

  • sudo vi /etc/resolv.conf
  • add the line nameserver 8.8.8.8
    • this is the google nameserver.

vnc remote

overclocking

scp

  • to copy photos to my current computer, over ethernet cable:
    • scp rtwomey@192.168.2.3:~/images/*.jpg ~/Pictures/
  • if you've stored your ssh public key, you won't be prompted for password!

Software

pocketsphinx / usb mic

https://wolfpaulus.com/journal/embedded/raspberrypi2-sr/

google speech scripts

*install pyaudio:

sudo apt-get install python-pyaudio

  • install pyaudio dependencies:
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
  • install pyaudio:
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
cd pyaudio
sudo python setup.py install
  • install flac:
sudo apt-get install flac
  • clone google speech scripts:
git clone https://github.com/jeysonmc/python-google-speech-scripts

Voice Command

Jasper

architecture.png

FM Transmitter

gphoto2

  • installing:
    • sudo apt-get install gphoto2
  • take a photo:
    • gphoto2 --capture-image-and-download
  • after taking a photo it's necessary to reset the USB port. use usbreset util.
    • usbreset /dev/bus/usb/001/004
    • put your /dev/bus/usb device as the second argument above. you can find it from --list-ports.
  • list cameras:
    • gphoto2 --list-ports
  • control and capture of DSLR http://skowron.biz/artikel/gphoto-raspberry/

usbreset

festival

pocketsphinx

Pockesphinx

megahal

  • try it -

supercollider

others

nltk

OpenCV

hd video playback

Video

OSC

liblo

To use liblo to write an OSC client and server in C, first install the liblo development package on both the computer you would like to broadcast from (the client) and the computer that will receive the messages (the server). Using APT: apt-get install liblo-dev

Then, visit http://liblo.sourceforge.net/ and navigate to the example code or documentation. The example code provides a simple client and server. If you're just copying and pasting these, and would like to quickly compile them and test that they work, do the following for the server:

wget http://liblo.sourceforge.net/examples/example_server.c
gcc -o server example_server.c -llo
./server

And for the client:

wget http://liblo.sourceforge.net/examples/example_client.c

Then on the line defining an lo_address, change NULL to the IP address of your server. Finally

gcc -o client example_client.c -llo
./client

If you've done everything successfully, you should see a variety of sample output from the running server program.

receive osc messages through puredata pd

pyOSC

Graphics

OpenGL

Using OpenGL on the Raspberry Pi appears to be pretty idiosyncratic. For instance, see https://benosteen.wordpress.com/2012/04/27/using-opengl-es-2-0-on-the-raspberry-pi-without-x-windows/. Don't be misled by what is described on that webpage. While correct, far simpler example projects exist on the Raspberry Pi at /opt/vc/src/hello_pi. These are very useful! Read the README there, and get cracking. To get started, you can build every project by running:

sh rebuild.sh

If you would only like to build a subset of the projects, first cd to /opt/vc/src/hello_pi/libs, and build each library included there. Specifically:

cd /opt/vc/src/hello_pi/libs/ilcient && make
cd ../vgfont && make

After these libraries are built, you can then cd to each example project, make, and run the resultant binary file. Please note that these instructions are repeated in the included README file.

Pi Camera

taking photos with raspistill

raspistill -o image.jpg

taking video with raspivid

  • take a video
raspivid -o video.h264
  • Convert to mp4
ffmpeg -i video.h264 -vcodec copy video.mp4

new video modes

sudo apt-get install rpi-update
  • update:
sudo rpi-update
  • exploring camera modes:
v4l2-ctl -p 90
 v4l2-ctl -v width=640,height=480,pixelformat=H264
 v4l2-ctl --stream-mmap=3 --stream-count=900 --stream-to=test90fps.h264
  • half resolution, binned:
raspivid -w 1296 -h 972 -t 10000 -o pi_0.h264
  • 90 frames per second VGA:
raspivid -w 640 -h 480 -fps 90 -t 10000 -o test90fps.h264


streaming the pi camera

  • RPi:
raspivid -t 999999 -o - | nc 192.168.2.31 5001
  • Laptop:
nc -l 5001 | mplayer -fps 31 -cache 1024 -

python interface (picam)

motion-triggered capture

sudo screen -dmS mocap /home/pi/code/housemachine/pircam.py
  • reconnect to screen:
sudo screen -r mocap
  • copy new video files:
rsync -va --ignore-existing pi@office.local:~/videos/pircam/ ~/Pictures/ceiling_fisheye/
 ./mmal_opencv_modect > video.h264

wrap h264 then combine two files

  • concat first and second half:
avconv -i concat:a.h264\|b.h264 -c copy sum.h264
  • wrap as h264 (with avconv):
avconv -i sum.h264 -vcodec copy sum2.mp4
  • wrap as h264 (with ffmpeg):
ffmpeg -i sum.h264 -vcodec copy sum.mp4

alternate lens mounts

Wolfson Audio

Jack from OSX to Raspberry Pi

On Raspberry Pi:

  • wolfson script to select audio output:
Playback_to_Lineout.sh
or the direct amixer commands
amixer -Dhw:0 cset name='HPOUT2 Digital Switch' on
amixer -Dhw:0 cset name='HPOUT2L Input 1' AIF1RX1
amixer -Dhw:0 cset name='HPOUT2L Input 1 Volume' 32
amixer -Dhw:0 cset name='HPOUT2R Input 1' AIF1RX2
amixer -Dhw:0 cset name='HPOUT2R Input 1 Volume' 32
  • run dbus:
eval dbus-launch --auto-syntax
  • copy results and export them:
export DBUS_SESSION_BUS_ADDRESS= ...
export DBUS_SESSION_BUS_PID= ...
  • start jackd:
jackd -R -T -p 32 -d alsa -n 3 -p 2048 -r 44100 -i2 -o2 &
  • start netone pointed to slave IP:
jack_netsource -H 192.168.0.104 &

On OS X:

  • configure jack for necessary outputs (only done once) (2 in 2 out)
  • qjackctl with netone backend

On Pi:

  • route jack signals:
jack_connect netjack:capture_1 system:playback_1
jack_connect netjack:capture_2 system:playback_2

Hardware Peripherals

Verified Peripherals - http://elinux.org/RPi_VerifiedPeripherals

C-Media USB sound device

U9 MiniMic

arecord -f dat | aplay -f dat &

C920

microline 320 printer

installing

  • install cups
    • sudo apt-get install cups
    • willtake a little while
  • install menu item:
    • sudo apt-get install system-config-printers
  • reboot
  • add printer
    • start ltxde:
      • startx
    • Select Menu->Preferences->Printing
    • Printer should autodetect. Or you can enter the URI manually: parallel:/dev/usblp0
    • Change model to Generic, type Raw. This will pass raw data to printer.
  • http://ubuntuforums.org/showthread.php?t=1436079&page=2

command line

Wireless Adapters

GPIO

through python

Logic Level Conversion

  • RPi is 3.3V.

untested

Applications

Use as AirPlay receiver

Problems

Course of Instruction