RPi Quadcopter blog

RPi Quadcopter blog
Click to open

Apr 28, 2013

Raspberry PI webcam streaming

How to stream webcam from Raspberry Pi with Raspbian(wheezy) installed.

1. Update apt-get:

$ sudo apt-get update

2. Install required packages:

$ sudo apt-get install libv4l-dev libjpeg8-dev subversion imagemagick uvcdynctrl -y

3. Copy mjpg-streamer code from svn and compile it

$ svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer
$ cd mjpg-streamer/mjpg-streamer
$ make USE_LIBV4L2=true clean all
$ sudo make DESTDIR=/usr install

4a. To get the best performing capture and streaming, change cpu governor setting to performance
$ sudo nano /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
erase "ondemand" -row and write "performance" (without quotes)
save and exit with ctrl+o (enter), ctrl+x

4b. Optionally you can set a script to change the cpu governor to performance on boot, because the governor will always change back to ondemand after shutdown

$ sudo nano /etc/local.rc

copy and paste "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor" (without quotes)
save and exit with ctrl+o (enter), ctrl+x

do a $ sudo reboot, if you skipped setp 4a.

5. Plug in your USB webcam, if you haven't done so yet and use uvcdynctrl to list it's supported formats.

$ uvcdynctrl -f

To get the best performance, you should only use the formats you see in this list. even fullHD @30fps is using about 5% cpu.

6. Start streaming

Use this, if you did see mjpg listed in the supported formats:

$ mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 1280x720 -f 30 -n" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"
else, add -y flag to the input string:

$ mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -r 1280x720 -f 30 -n -y" -o "/usr/lib/output_http.so -p 8090 -w /var/www/mjpg_streamer"

7. Test it

open http://<RPi IP ADDRESS>:8090/?action=stream with your browser or VLC

Apr 16, 2013

Exposing Arduino pins to Raspberry Pi with USB connection

This guide helps you to setup Arduino to talk with a Raspberry Pi, but this will work with any other computer/operating system as long as it has python installed. We will be using python code to send commands with Firmata -protocol to Arduino (Uno) which will have corresponding firmata program running. This guide assumes you have Raspbian installed.

0 Content

  1. Setting up  Raspberry Pi
  2. Setting up Arduino
  3. Run simple test program
  4. Links

1 Setting up Raspberry Pi

Install needed libraries pySerial and pyFirmata

Log in to your RPi with ssh and go to downloads

 $ cd Downloads/  

Next download and extract pySerial library

 $ wget https://pypi.python.org/packages/source/p/pyserial/pyserial-2.6.tar.gz#md5=cde799970b7c1ce1f7d6e9ceebe64c98  
 $ tar -zxvf pyserial-2.6.tar.gz  

Install pySerial and go back to Downloads

 $ cd pyserial-2.6/  
 $ sudo python setup.py install  
 $ cd ..  

Install a git client, because we will be cloning pyFirmata library from github.

 $ sudo apt-get update  
 $ sudo apt-get install git-core  

 $ git clone https://github.com/tino/pyFirmata.git  
 $ cd pyFirmata  
 $ sudo python setup.py install  

2 Setting up Arduino

Connect your arduino and open Arduino IDE. Open StandardFirmata sketch from examples: File>examples>Firmata>StandardFirmata. Upload the code to your arduino, then connect it to Raspberry Pi with usb. Make sure raspberry pi sees arduino:

 $ lsusb  

You sould see something like this "Bus 001 Device 007: ID 2341:0001 Arduino SA Uno (CDC ACM)".

3 Running simple test program

Download blink example to your Raspberry Pi from https://bitbucket.org/fab/pyfirmata/src/96116e877527/examples

Connect a led to arduino pin 12 and run blink.py from raspberry.

 $ python blink.py  

4 Links