RPi Quadcopter blog

RPi Quadcopter blog
Click to open

May 3, 2014

NEO6MV2 GPS Module with Arduino Uno HOW-TO


Introduction

Using the NEO6MV2 GPS Module with Arduino is pretty straightforward. This tutorial uses TinyGPS Library by Mikal Hart. The library is only for data manipulation purposes, so it is not actually required to read the data from the module. SoftwareSerial library is used for the communication.

I got the module from DealExtreme: http://www.dx.com/p/gy-neo6mv2-flight-controller-gps-module-blue-232595

This tutorial should work with Ublox-NEO6MV2, GY-NEO6MV2...

Hardware

NEO6MV2 GPS module uses 3v3 logic compared to 5v which the Arduino uses. To convert the logic, we add two resistors in our wiring.


Parts


Wiring

image developed using Fritzing. For more circuit examples, see the Fritzing project page


Software

Download the TinyGPS library here: https://github.com/mikalhart/TinyGPS/releases/tag/v13.
Open the "test_with_gps_device.ino" from the examples folder.
This module uses baudrate 9600, so in the setup() method find the code "ss.begin(4800);
" and replace it with ss.begin(9600);. Now upload the code and open the serial monitor. If the module fails to get a fix, try to use it near a window or outdoors. The fix could take several minutes.

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



Jun 2, 2011

Samsung remote IR-codes

The IRremote library could not parse samsung infrared data, but here's the raw codes with examples how to send them. I only read the most used buttons. Codes are already in variables :)

Codes:

// Power ON/OFF
const unsigned int S_pwr[68]={4600,4350,700,1550,650,1550,650,1600,650,450,650,450,650,450,650,450,700,400,700,1550,650,1550,650,1600,650,450,650,450,650,450,700,450,650,450,650,450,650,1550,700,450,650,450,650,450,650,450,650,450,700,400,650,1600,650,450,650,1550,650,1600,650,1550,650,1550,700,1550,650,1550,650};

// channel 1 
const unsigned int S_1[68]={4650,4300,700,1550,700,1550,650,1550,700,400,700,400,700,400,700,450,700,400,700,1500,700,1500,700,1550,700,450,650,400,700,450,650,450,700,400,700,400,700,450,650,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,450,650,1550,700,1550,650,1550,700,1500,700,1550,650};

// channel 2
const unsigned int S_2[68]={4600,4350,650,1550,700,1500,700,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1500,700,1550,700,400,700,450,650,450,700,400,700,400,700,1500,700,400,700,1550,700,400,700,400,700,450,650,450,700,400,700,400,700,1550,650,450,700,1500,700,1550,650,1550,700,1500,700,1550,650};

// channel 3
const unsigned int S_3[68]={4600,4350,700,1500,700,1550,650,1600,650,400,700,450,700,400,700,400,700,400,700,1550,650,1550,700,1500,700,400,700,450,700,400,700,400,700,400,700,400,700,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,400,700,400,700,1550,650,1550,700,1500,700,1550,700,1500,700};

// channel 4
const unsigned int S_4[68]={4600,4350,650,1550,700,1500,700,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,400,700,450,650,450,700,400,700,400,700,400,700,400,700,450,650,1550,700,400,700,400,700,450,700,400,700,1500,700,1550,650,1550,700,400,700,1550,650,1550,700,1500,700,1550,650};

// channel 5
const unsigned int S_5[68]={4650,4350,700,1500,700,1550,650,1550,700,400,700,450,700,400,700,400,700,400,700,1500,700,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,400,700,400,650,1550,700,450,650,450,700,400,700,450,650,450,650,1550,650,1550,700,400,700,1550,700,1500,700,1500,700,1550,700};

// channel 6
const unsigned int S_6[68]={4600,4350,650,1550,700,1500,700,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,400,700,450,700,400,700,400,700,400,700,400,700,1550,700,400,700,1500,700,450,650,450,700,400,700,400,700,1550,650,450,650,1550,700,400,700,1550,650,1550,700,1500,700,1550,650};
 
// channel 7
const unsigned int S_7[68]={4600,4350,700,1500,700,1550,650,1550,700,400,700,450,700,400,700,400,700,400,700,1550,650,1550,700,1500,700,400,700,450,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,450,700,400,700,400,700,450,650,1550,650,1550,700,450,650,400,700,1550,700,1500,700,1550,650,1550,700};
 
// channel 8
const unsigned int S_8[68]={4600,4350,650,1600,650,1500,700,1550,700,400,700,400,700,400,700,450,700,400,700,1500,700,1550,650,1550,700,400,700,450,650,450,700,400,700,400,700,1550,650,450,650,1550,700,1500,700,450,700,400,700,400,700,400,700,400,700,1550,700,400,700,450,650,1550,650,1550,700,1500,700,1550,650};
 
// channel 9
const unsigned int S_9[68]={4600,4350,700,1500,700,1550,650,1550,700,400,700,450,650,450,650,450,700,400,700,1500,700,1550,700,1550,650,400,700,450,700,400,700,400,700,400,700,450,650,1550,650,1600,650,1550,650,450,700,400,700,400,700,400,700,1550,700,400,700,400,700,400,700,1550,700,1500,700,1500,700,1550,700};
 
// channel 0
const unsigned int S_0[68]={4650,4300,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1550,650,1550,700,400,700,400,700,400,700,450,700,400,700,1550,650,400,700,450,700,400,650,1550,700,400,700,450,700,400,700,400,700,1500,700,1550,700,1500,700,400,700,1550,650,1550,700,1500,700};
 
// source
const unsigned int S_scr[68]={4600,4350,700,1550,650,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,400,700,400,700,1550,700,400,700,450,650,450,650,450,700,400,700,400,700,400,700,450,650,1550,700,1500,700,1550,650,1550,700,1500,700,1550,700,1500,700};
 
// channel up
const unsigned int S_pup[68]={4600,4350,700,1500,700,1500,700,1550,700,450,650,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,450,650,450,700,400,700,400,700,400,700,400,700,1550,700,400,700,400,700,1550,650,450,700,400,700,400,700,1550,650,450,650,1600,650,1550,650,450,700,1500,700,1500,700,1550,650};
 
// channel down
const unsigned int S_pdown[68]={4650,4300,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,700,400,700,400,700,400,700,450,650,450,650,1550,700,400,700,450,650,400,700,1550,700,1500,700,1550,700,1500,700,400,700,1550,650,1550,700,1500,700};
 
// volume up
const unsigned int S_vup[68]={4600,4350,650,1550,700,1500,700,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,400,700,450,700,400,700,400,700,400,700,450,650,450,650,450,650,1550,700,1500,700,1550,700,1500,700,1550,650};

// volume down
const unsigned int S_vdown[68]={4600,4350,700,1550,650,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,450,650,1550,700,400,700,400,700,450,700,400,700,400,700,400,700,1550,700,400,700,1500,700,1500,700,1550,700,1500,700};

// TV/DTV
const unsigned int S_tv[68]={4600,4350,650,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,700,400,700,1500,700,1500,700,1550,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,700,400,700,400,700,400,700,400,700,1550,700,400,700,400,700,400,700,1550,700,1500,700,1550,650,1550,700,400,700,1500,700};
 
// guide
const unsigned int S_guide[68]={4600,4350,700,1500,700,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,650,1550,700,1500,700,450,650,450,700,400,700,400,700,400,700,1550,700,1500,700,1550,650,1550,700,400,700,400,700,1550,700,400,700,400,700,400,700,450,700,400,650,1550,700,1550,650,450,700,1500,700};

// exit
const unsigned int S_exit[68]={4650,4300,700,1550,650,1550,700,1550,700,400,700,400,700,450,650,450,650,450,650,1550,700,1500,700,1550,700,450,650,400,700,450,650,450,700,400,700,1500,700,400,700,1550,700,1500,700,400,700,1550,700,450,650,400,700,450,650,1550,700,400,700,400,700,1550,650,450,650,1550,700,1500,700};
 
// mute
const unsigned int S_mute[68]={4650,4350,650,1550,650,1550,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,1550,700,400,700,450,650,400,700,450,700,400,700,1500,700,1550,650,1550,700,1500,700,450,700,400,700,400,700,400,700,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,1500,700};

Sending:

Irsend.sendRAW(S_pwr,68,38);

Remote will probably work in all samsung models, but with LE40M8 for sure.

May 28, 2011

Fujlight ir-codes

Found this remotecontrolled led -bulb for cheap: http://www.verkkokauppa.com/fi/product/8159/cgfmm

The remote is  "MCL Remote Controller" and it seems to be used in various other products. These codes should then work with other products with the same remote.

Infrared NEC codes:

speed +: 0xFF08F7
speed -: 0xFFC03F
Pause: 0xFF807F
Off: 0xFF609F
skip 1: 0xFF906F
skip 2: 0xFFB847
Fade: 0xFFF807
Strobe: 0xFFB04F
Red1: 0xFF9867
R2: 0xFFE817
R3: 0xFF02FD
R4: 0xFF40BF
R5: 0xFF50AF
Green1: 0xFFD827
G2: 0xFF48B7
G3: 0xFF12ED
G4: 0xFFA05F
G5: 0xFF7887
Blue1: 0xFF8877
B2: 0xFF6897
B3: 0xFF20DF
B4: 0xFF2AD5
B5: 0xFF708F
White: 0xFFA857
100%: 0xFF32CD
75%: 0xFF00FF
50%: 0xFFB24D
25%: 0xFF58A7

See how to send these NEC-codes with Arduino!



The whole top part of the controller is glued sheet of plastic with buttons. You may see this remote with different layouts, so I included .odt/excel file where you can see the codes in button order. Download

Arduino and PHP

To comunicate between arduino and pc, you have many options. Php works really well for sending data to arduino, but I'd say you cannot get data straight from arduino without 100% cpu usage and days of trial and error.

The code below requires "php_serial.class.php". Download it to the same folder where you save this code:

// hello from php.php
 <?php
if(isset($_REQUEST['message'])){
$msg=$_REQUEST['message'];
require("php_serial.class.php");
$serial = new phpSerial();
$serial->deviceSet("/dev/ttyACM0"); // Arduino usb-port
$serial->confBaudRate(115200);  //baud rate
$serial->confParity("none");  //Parity
$serial->confCharacterLength(8); //Character length  
$serial->confStopBits(1);  //Stop bits
$serial->confFlowControl("none");
$serial->deviceOpen(); // open connection

$serial->sendMessage($msg); //send the message
}
?>
<html><body>
<h3>If you're running Linux: remember to give permissions to www-data to access usbport ($ sudo chmod 777 /dev/ttyACM0)</h3>
<a href="hello_from_php.php?message=HelloFromPhp">Send hello message</a>
</body></html>
If you are not getting any data to Arduino, you must first (and every time you connect usb) give permissions to www-data to access your Arduino usb-port.

Try the example above with "Arduino: How to read serial to string" for best results!

May 25, 2011

Arduino: How to read serial to string

String reserves a lot of memory for it self. Avoiding string type variables is a good idea. This example is good for debugging purposes when you don’t know how long strings you are sending to arduino.  when your code becomes longer and you know how long strings you are sending, use char[20].
String inData;
void setup()
{
 Serial.begin(115200);
}
void loop(){
inData="";
     if (Serial.available() > 0) {
         int h=Serial.available();   
        // if you are getting escape -characters try h--; here
    
for (int i=0;i<h;i++){
             inData += (char)Serial.read();
         }
    // if you are getting escape -characters try Serial.read(); here
    }
    //print it out
    Serial.println(inData);
}