Attiny85 + 433Mhz transmitter+ DHT11 ----------> Received with Arduino or RaspberryPi

Attiny85 from eBay is really cheap. I paid 5 Attiny85 $8!

433MhZ receiver and transmitter from eBay. Each (both receiver+transmitter)cost $1.

DHT11 also from eBay which cost $1.25.

Transmit code:
#include <dht.h>
#include <VirtualWire.h>
#include <avr/sleep.h>
#include <util/delay.h>

int led=0;
const int transmit_pin = 4;
dht DHT;

#define DHT11_PIN 3

void setup(){
  vw_set_tx_pin(transmit_pin);
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(2000); // Bits per sec
}

byte count = 1;

void loop(){
  int chk = DHT.read11(DHT11_PIN);
  int t=0;
  int h=0;
  //_delay_ms(200);
  t=DHT.temperature;
  h=DHT.humidity;
  char myBigArray[128];
  char temp[4];
  itoa( t, temp, 10);
  //char razib[1]={'k'};
  //char msg[7] = {'H','e','l','l','o',' ','#'};
  myBigArray[0] = '\0';
  //strcat(myBigArray, "T:");
  strcat(myBigArray,temp );
  strcat(myBigArray, ":");
  itoa( h, temp, 10);
  //strcat(myBigArray, razib);
  strcat(myBigArray, temp);
  //msg[6] = count;
  //digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)myBigArray, strlen(myBigArray));
  vw_wait_tx(); // Wait until the whole message is gone
  //digitalWrite(led_pin, LOW);
//  delay(100);
  count = count + 1;
  //system_sleep();
  //delayMicroseconds(20);
  _delay_ms(1000);
}

WiFi without wicd-curses RaspberryPi

I found a way to connect your RPi without wicd-curses:

nano /etc/network/interfaces
---------------------------------------------------------
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.con$

----------------------------------------------------------
save and exit by pressing ctrl+x

 nano /etc/wpa_supplicant/wpa_supplicant.conf
----------------------------------------------------------------
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="yourNetworkName"
scan_ssid=1
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="yourNetworkPassword"
}
--------------------------------------------------------
save and exit by pressing ctrl+x
restarts all the networks services :
  • /etc/init.d/networking restart
  • or
  • ifconfig wlan0 down
    ifconfig wlan0 up

XBMC_OpenElec_Chromecast

By the way, I have implemented a Chrome plugin too for the same purpose, you can download it from here:StreamToXBMC – Adrian
Note: I have only implemented new servers in this extension-> Stream To XBMC
To install it, you only have to unzip the downloaded file, navigate to Chrome extensions
, expand the developer dropdown menu and click “Load Unpacked Extension” and navigate to local folder. Assuming there are no errors, the extension should load into your browser.
Once installed, we have to click “configure” in the extension and introduce the XBMC ip:

HPC2N job submission

Make.sbatch
***------------------------------------------------------ ***
#!/bin/bash
## Name of the script - unnecessary, but useful to help find the job in a long list
#SBATCH -A 5DV152-VT14
#SBATCH -J mpiCountSort

## Names of output and error files. You can call them what you will. If you
## don't give them a name, the file containing output and any errors, will be called
## slurm-<jobid>.out.
##

## asking for 24 processes. There are 48 cores per node on Abisko.
## If you do not specify processes/cores, you will get the smalles allocatable amount,
## Which is one 'socket' (6 cores, as far as SLURM is concerned). Runtime (walltime)
## in this example is 4 minutes max. If
## the job completes sooner, it will return at that time.
#SBATCH -n 6
#SBATCH --time=01:00:00
# Spread the tasks evenly across two nodes
#SBATCH --ntasks-per-node=48

#SBATCH --output=pN:6&dN:700.out
#SBATCH --error=pN:6&dN:700.err

## Load any modules you need (here OpenMPI for PathScale compilers)
module add openmpi/gcc/1.6.5
echo "Starting at `date`"
echo "Running on hosts: $SLURM_NODELIST"
echo "Running on $SLURM_NNODES nodes."
echo "Running on $SLURM_NPROCS processors."
echo "Current working directory is `pwd`"

srun -n $SLURM_NPROCS ./mpiCountSort 700
echo "Program finished with exit code $? at: `date`"
***-------------------------------------------***
Submit the program with:
sbatch <my_jobscript> 
Help link: http://www.hpc2n.umu.se/batchsystem/examples_scripts

Raspberry Pi change default ssh login message

Changing this message requires editing two different files. The first three sections can be modified by editing the following file:
/etc/motd

To disable the last login message (which I don’t recommend doing), you will need to edit the following file in sudo mode:
/etc/ssh/sshd_config
Find this line in the file and change the yes to no as shown:
PrintLastLog no

Json live temperature update

Get temperature with DS18B20 and save live update with python+php+Json
You can buy DS18B20 from ebay, cost >1$ and you need RaspberryPi.
Full tutorial
temp.py
import os
import glob
import time

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c, temp_f
   
while True:
    print(read_temp())
    deg_c, deg_f = read_temp()
    msg='<?php echo json_encode(array( "author" => "razib","tweet" => "Temparature is: " . '+str(deg_c)+',"date" => date("l jS \of F Y h:i:s A"))); ?>'
    f = open('/var/www/python/feed.php','w')
    f.write(msg)
    f.close()
    time.sleep(1)

 


index.php
<html>
<head><title>Tweets</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<style>
#tweets {
    width: 500px;
    font-family: Helvetica, Arial, sans-serif;
}
#tweets li {
    background-color: #E5EECC;
    margin: 2px;
    list-style-type: none;
}
.author {
    font-weight: bold
}
.date {
    font-size: 10px;
}
</style>

<script>
jQuery(document).ready(function() {
    setInterval("showNewTweets()", 1000);
});

function showNewTweets() {
    $.getJSON("feed.php", null, function(data) {
        if (data != null) {
            $("#tweets").prepend($("<li><span class=\"author\">" + data.author + "</span> " +  data.tweet + "<br /><span class=\"date\">" + data.date + "</span></li>").fadeIn("slow"));
        }
    });
}
</script>

</head>
<body>

<ul id="tweets"></ul>

</body>
</html>

feed.php
<?php
echo json_encode(array( "author" => "razib",
                        "tweet" => "The time is: " . time(),
                        "date" => date('l jS \of F Y h:i:s A')));
?>

crontab -e

Just add to your crontab
* * * * * for i in {0..59};

RaspberryPi python+php web switch control or car controll with camera

python code:

#!/usr/bin/python
import MySQLdb
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)

def dbConn():
        db = MySQLdb.connect("localhost",user=" ",passwd=" ",db=" ")
        cur = db.cursor(MySQLdb.cursors.DictCursor)
        cur.execute("SELECT * FROM pinMap")
        return cur
# you must create a Cursor object. It will let
#  you execute all the queries you need

# Use all the SQL you like

# print all the first cell of all the rows

try:
   while True:
        cur=dbConn()
        print "|ID  |GPOI num\t|Status\t|"
        print "+-----------------------+"
        for row in cur.fetchall() :
            print "|",row['id'], "|" ,row["pin"], "\t|" , row['status'], "\t|"
            GPIO.setup(int(row["pin"]), GPIO.OUT)
            GPIO.output(int(row["pin"]),int(row["status"]))
        print "+-----------------------+"
        time.sleep(2)
except KeyboardInterrupt:
                pass
GPIO.cleanup()

PHP code:

<!DOCTYPE html>
<html>
<head>
<title>PiCar</title>

</head>

<body>

<div style="text-align:center">
    <h1>Raspberry Pi GPIO</h1>
<form action="index.php" method="post">
    <input type="image" src="forward.jpg" name="forward"  value="forward">
<br>
    <input type="image" src="left.jpg" name="left"  value="left">
    <input type="image" src="right.jpg" name="right"  value="right">

<br>
        <input type="image" src="backward.jpg" name="backward"  value="backward">
<br>
        <input type="image" src="stop.jpg" name="stop"  value="stop">
    </div>
</form>

</body>
</html>
<?php
function fileRead($num){
    $myFile = "example.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    $stringData = "$num\n";
    fwrite($fh, $stringData);
    fclose($fh);
}
function db($pin,$setting){
    include('db.php');
    //$setting = "1";
    //$pin=4;
    mysql_query("UPDATE pinMap SET status='$setting' WHERE pin='$pin';");
    mysql_close();
    header('Location: index.php');
}
function resetPinZero($id,$setting){
    include('db.php');
    //$setting = "1";
    //$pin=4;
    mysql_query("UPDATE pinMap SET status='$setting' WHERE id='$id';");
    mysql_close();
    header('Location: index.php');
}

if (isset($_POST['forward']) && ($_POST['forward'] == 'forward')) {
    echo "forward";
        fileRead("1");
        db("8","0");
        db("7","1");
/*        sleep(1);
        fileRead("0");
        header("Location: fileOne.php");*/
}
else if (isset($_POST['backward']) && ($_POST['backward'] == 'backward')) {
    echo "backward";
        db("7","0");
        db("8","1");
        fileRead("2");
}

else if (isset($_POST['left']) && ($_POST['left'] == 'left')) {
    echo "left";
        db("23","0");
        db("24","1");
        fileRead("2");
}
else if (isset($_POST['right']) && ($_POST['right'] == 'right')) {
    echo "right";
        db("24","0");
        db("23","1");
        fileRead("3");
}
else if (isset($_POST['stop']) && ($_POST['stop'] == 'stop')) {
    echo "stop";
        for($i=0;$i<=17;$i++)
            resetPinZero($i,0);
        fileRead("4");
}
?>
db.php:
<?php
      $conn = mysql_connect('localhost', ' ', ' ');
      $db   = mysql_select_db(' ');
            if($conn)
                echo "success";
            else
                echo "not success!";
?>

MySql:-- phpMyAdmin SQL Dump
-- version 3.4.11.1deb2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 14, 2014 at 04:40 PM
-- Server version: 5.5.37
-- PHP Version: 5.4.4-14+deb7u12

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `gpioPin`
--

-- --------------------------------------------------------

--
-- Table structure for table `pinMap`
--

CREATE TABLE IF NOT EXISTS `pinMap` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `pin` int(10) NOT NULL,
  `status` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;

--
-- Dumping data for table `pinMap`
--

INSERT INTO `pinMap` (`id`, `pin`, `status`) VALUES
(0, 7, 0),
(2, 8, 0),
(3, 10, 0),
(4, 11, 0),
(5, 12, 0),
(6, 13, 0),
(7, 15, 0),
(8, 16, 0),
(9, 18, 0),
(10, 19, 0),
(11, 21, 0),
(12, 22, 0),
(13, 23, 0),
(14, 24, 0),
(15, 26, 0),
(16, 3, 0),
(17, 5, 0);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Picture:




motorControl.py :
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)

"""back motor"""
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
"""front motor"""
GPIO.setup(8, GPIO.OUT)
GPIO.setup(10, GPIO.OUT)
"""
GPIO.output(11,1)
GPIO.output(12,0)
time.sleep(0.5)
GPIO.output(11,0)
GPIO.output(12,1)
time.sleep(0.5)
"""
speed=80
clock=50
p=GPIO.PWM(11,clock)
q=GPIO.PWM(12,clock)

p.start(0)
q.start(0)

try:
    while True:
                    for i in range(speed):
                                p.ChangeDutyCycle(i)
                                time.sleep(0.02)
                    for i in range(speed):
                                p.ChangeDutyCycle(speed-i)

                    p.ChangeDutyCycle(0)

                    for i in range(speed):
                                q.ChangeDutyCycle(i)
                                time.sleep(0.02)
                    for i in range(speed):
                                q.ChangeDutyCycle(speed-i)

                    q.ChangeDutyCycle(0)
except KeyboardInterrupt:
                pass
p.stop()
"""
GPIO.output(8,1)
GPIO.output(10,0)
time.sleep(0.5)
GPIO.output(8,0)
GPIO.output(10,1)
time.sleep(0.5)
"""
GPIO.cleanup()

I am using ebay cheap motor driver and it's cost 1$. You can control 2 dc motor.
 

fixed ip address RPi

To configure the board to use DHCP or static IP settings:
  1. You can use a terminal window after accessing the Linux® desktop. See Access the Linux Desktop Using Computer Peripherals.
  2. Display the contents of the /etc/network/interfaces file. Enter:
    cat /etc/network/interfaces 
    If the board is configured to use DHCP services (the default configuration), dhcp appears at the end of the following line:
    iface eth0 inet dhcp
    If the board is configured to use static IP settings, static appears at the end of the following line:
    iface eth0 inet static
  3. Create a backup of the /etc/network/interfaces file. Enter:
    sudo cp /etc/network/interfaces /etc/network/interfaces.backup
    If prompted, enter the root password.
  4. Edit interfaces using a simple editor called nano. Enter:
    sudo nano /etc/network/interfaces
  5. Edit the last word of line that starts with iface eth0 inet.
    To use DHCP services, change the line to:
    iface eth0 inet dhcp
    To use static IP settings, change the line to:
    iface eth0 inet static
  6. For static IP settings, add lines for address, netmask, and gateway. For example:
    iface eth0 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        gateway 192.168.1.1
    For static IP settings:
    • The value of the subnet mask must be the same for all devices on the network.
    • The value of the IP address must be unique for each device on the network.
    For example, if the Ethernet port on your host computer has a network mask of 255.255.255.0 and a static IP address of 192.168.1.1, set:
    • netmask to use the same network mask value, 255.255.255.0.
    • address to an unused IP address, between 192.168.1.2 and 192.168.1.254.
  7. Save the changes and exit nano:
    1. Press Ctrl+X.
    2. Enter Y to save the modified buffer.
    3. For "File Name to Write: /etc/network/interfaces", press Enter.
    4. The nano editor confirms that it "Wrote # lines" and returns control to the command line.
  8. Reboot the board. In MATLAB® Command Window, enter:
    h = raspberrypi
    h.execute('sudo shutdown -r now')
  9. Test the IP settings by logging in to the board over a telnet session.

send email if IP change or sendnormal email using RaspberryPi

sudo apt-get update
sudo apt-get install mailutils ssmtp
sudo nano /etc/ssmtp/ssmtp.conf
mailhub=smtp.gmail.com:587
AuthUser=yourgmailaddress@gmail.com
AuthPass=yourgmailpassword (do not use any # in your password!)
UseSTARTTLS=YES 
 


root:root@your.domain:smtp.gmail.com:587
www-data:yourwebpagesname@your.domain:smtp.gmail.com:587

root:yourgmailaddress@gmail.com:smtp.gmail.com:587
create file sendIp.sh and put

#!/bin/sh

SUBJ="This is new IP for Pi"
EMAIL="*****@gmail.com"

ip1=""
ip2=""

read ip1 < ip.txt
ip2=$(wget -qO- ifconfig.me/ip)

if [ "$ip1" = "$ip2" ]
then
  exit
else
  echo "$ip2" > ip.txt
  echo "$ip2" | mail -s $SUBJ $EMAIL
  exit
fi
 
 
 

save it.

sudo crontab -e
0,15,30,45 * * * * sh *full path to script here sendIp.sh &>/dev/null

Quick check: echo “Test text” | mail -s “Test Mail” targetperson@example.com

More tutorial  
  
Raspberry Pi Remote control:

Last of this tutorial you can control any remote control device with your voice.

I will try to describe every step to complete this tutorial.

Hardware:

1. Raspberry Pi
2. IR receiver
3. IR transmitter
4. WiFi module (optional)

Connection:

IR Receiver :                    

Data  --------------------------> GPIO18(PIN 12)
VCC   --------------------------> 3V (PIN1)
GND  --------------------------> Ground(PIN6)


IR Transmitter


Data  --------------------------> GPIO17(PIN 11)
VCC   --------------------------> 5V (PIN2)
GND  --------------------------> Ground(PIN14)


IR receiver and transmitter can buy from ebay and it's look like:
it's cheap, cost : C $3.29 










Software:

1. You need Raspbian. 
2. For IR device:

First, we’ll need to install and configure LIRC to run on the RaspberryPi:
sudo apt-get install lirc
Add this to your /etc/modules file:
lirc_dev
lirc_rpi gpio_in_pin=23 gpio_out_pin=22

Change your /etc/lirc/hardware.conf file to:
########################################################
# /etc/lirc/hardware.conf
#
# Arguments which will be used when launching lircd
LIRCD_ARGS="--uinput"

# Don't start lircmd even if there seems to be a good config file
# START_LIRCMD=false

# Don't start irexec, even if a good config file seems to exist.
# START_IREXEC=false

# Try to load appropriate kernel modules
LOAD_MODULES=true

# Run "lircd --driver=help" for a list of supported drivers.
DRIVER="default"
# usually /dev/lirc0 is the correct setting for systems using udev
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"

# Default configuration files for your hardware if any
LIRCD_CONF=""
LIRCMD_CONF=""
########################################################
Now restart lircd so it picks up these changes:
sudo /etc/init.d/lirc stop
sudo /etc/init.d/lirc start

Testing the IR receiver

Testing the IR receiver is relatively straightforward.
Run these two commands to stop lircd and start outputting raw data from the IR receiver:
sudo /etc/init.d/lirc stop
mode2 -d /dev/lirc0
Point a remote control at your IR receiver and press some buttons. You should see something like this:
space 16300
pulse 95
space 28794
pulse 80
space 19395
pulse 83
space 402351
pulse 135
space 7085
pulse 85
space 2903
If you don’t, something is probably incorrectly configured. Triple check that you’ve connected everything properly and haven’t crossed any wires. I highly recommend referring to the schematics I linked to above. There is also some trouble shooting advice in the RaspberryPi Forum thread I linked to above. Finally - you may want to do this in a dark room. I found that my desk lamp and overhead light would cause the IR receiver to think it was receiving valid signals.

 

Wiring up the IR transceiver

The /etc/lirc/lircd.conf file tells LIRC about your remote control. Since every remote control is different, you need to generate a different config for each remote. Alternatively you could try and find your remote control config file here: http://lirc.sourceforge.net/remotes/.
To generate your own configuration run:
$ sudo irrecord -f -d /dev/lirc0 /etc/lirc/lircd.conf
and carefully follow the on-screen instructions. At some point it will ask you to enter the commands for each button you press. You can list the available commands (in another terminal) with:
$ irrecord --list-namespace
After you have finished, restart the lirc daemon (or reboot) and test your remote by running:
$ irw
Your commands should appear in the console.

 

Testing the IR LED

You’re going to need to either find an existing LIRC config file for your remote control or use your IR receiver to generate a new LIRC config file. In my case I created a new LIRC config file. To do this, read the documentation on the irrecord application that comes with LIRC.
When using irrecord it will ask you to name the buttons you’re programming as you program them. Be sure to run irrecord --list-namespace to see the valid names before you begin.
Here were the commands that I ran to generate a remote configuration file:
# Stop lirc to free up /dev/lirc0
sudo /etc/init.d/lirc stop

# Create a new remote control configuration file (using /dev/lirc0) and save the output to ~/lircd.conf
irrecord -d /dev/lirc0 ~/lircd.conf

# Make a backup of the original lircd.conf file
sudo mv /etc/lirc/lircd.conf /etc/lirc/lircd_original.conf

# Copy over your new configuration file
sudo cp ~/lircd.conf /etc/lirc/lircd.conf

# Start up lirc again
sudo /etc/init.d/lirc start
Once you’ve completed a remote configuration file and saved/added it to /etc/lirc/lircd.confyou can try testing the IR LED. We’ll be using the irsend application that comes with LIRC to facilitate sending commands. You’ll definitely want to check out the documentation to learn more about the options irsend has.
Here are the commands I ran to test my IR LED (using the “yamaha” remote configuration file I created): yamaha or /home/pi/lircd.conf
# List all of the commands that LIRC knows for 'yamaha'
irsend LIST yamaha ""

# Send the KEY_POWER command once
irsend SEND_ONCE yamaha KEY_POWER

# Send the KEY_VOLUMEDOWN command once
irsend SEND_ONCE yamaha KEY_VOLUMEDOWN
I tested that this was working by pointing the IR led at my Yamaha receiver and testing whether I could turn it on and adjust the volume.
DIRECTIVE can be:
SEND_ONCE - send CODE [CODE ...] once SEND_START - start repeating CODE SEND_STOP - stop repeating CODE LIST - list configured remote items SET_TRANSMITTERS - set transmitters NUM [NUM ...] SIMULATE - simulate IR event

Success!

That’s it! You’ve now successfully installed and configured LIRC on your RaspberryPi. You can add additional remote control configuration files to your /etc/lirc/lircd.conf file to control multiple remotes.
 Setup voice command: