Test DS18B20 sensor

  1. sudo modprobe w1-gpio
  2. sudo modprobe w1-therm
  3. cd /sys/bus/w1/devices
  4. ls
  5. cd 28-xxxx (change this to match what serial number pops up)
  6. cat w1_slave
modprobe.png

The interface is a little unreliable, but fortunately it tells us if there is a valid temperature to read. It’s like a file, so all we have to do is read

The response will either have YES or NO at the end of the first line. If it is yes, then the temperature will be at the end of the second line, in 1/000 degrees C. So, in the example above, the temperature is actually read as 20.687 and then 26.125 degrees C.

If you have more than one Sensor connected, you’ll see multiple 28-xxx files. Each one will have the unique serial number so you may want to plug one in at a time, look at what file is created, and label the sensor!

  

UltraSonic Sensors

Ebay Kit
The Sensor is powered by a +5v rail from pin 2 of the Pi. The trigger pin comes from pin 16 (Gpio23) and this tell the sensor to start measuring. The echo pin in normally low until the sensor sends an output then it goes +5v for the time the sensor took to measure the distance. This is the reason for the resistors as the GPIO can only handle a +3.3v.

Diagram

The Code

#!/usr/bin/python
# Import required Python libraries
import time
import RPi.GPIO as GPIO
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
#
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
#
print "Ultrasonic Measurement"
#
# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
#
# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
#
# Allow module to settle
time.sleep(0.5)
#
# Send 10us pulse to trigger
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
while GPIO.input(GPIO_ECHO)==0:
start = time.time()
#
while GPIO.input(GPIO_ECHO)==1:
stop = time.time()
#
# Calculate pulse length
elapsed = stop-start
#
# Distance pulse travelled in that time is time
# multiplied by the speed of sound (cm/s)
distance = elapsed * 34000
#
# That was the distance there and back so halve the value
distance = distance / 2
#
print "Distance : %.1f" % distance
#
# Reset GPIO settings
GPIO.cleanup()

  

Ultrasonic Rocket launcher

rl

rocket launcher diagramThis is the code and diagram to fire the big trak rockets using the ultra sonic sensor on the Pi. The aim is to have the the rocket pod attached to Big Trak with the sensor at the front.The code is simple it will ask for a distance i normally say 80 (8cm).It will then print out the measurements every second until there is one below 80 then it`s fires the rockets , takes a picture using the call function and switches the LED on. This code is a work in progress so if you see any way to improve it I would like to hear.

Diagram in PDF 

#!/usr/bin/python
#
#
# Author : Julian and Kyle Milligan
# Date : 09/01/2013
# Import required Python libraries
import time
import RPi.GPIO as GPIO
from subprocess import call
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
GPIO_FIRE = 4
#
print "Ultrasonic Measurement"
#
# Set pins as output and input
GPIO.setup(GPIO_TRIGGER,GPIO.OUT) # Trigger
GPIO.setup(GPIO_ECHO,GPIO.IN) # Echo
GPIO.setup(GPIO_FIRE,GPIO.OUT) # Fire
# Set trigger to False (Low)
GPIO.output(GPIO_TRIGGER, False)
# GPIO.output(GPIO_FIRE, False)
#
# Allow module to settle
time.sleep(0.5)
#
# set distance to trigger
setdistance = input('Please enter a value to trigger the camera:')#on screen prompt to fire
while True:
time.sleep(0.1)
GPIO.output(GPIO_TRIGGER, True)
time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)
start = time.time()
s = start
quit =0
#
while quit ==0:
quit = GPIO.input(GPIO_ECHO)
start = time.time()
if start - s > 0.1:
quit = 1
#
if start - s < 0.1:
while GPIO.input(GPIO_ECHO) == 1:
stop = time.time()
#
elapsed = stop-start
#
distance = elapsed * 34300
distance = distance / 2
#
print "Distance : %.1f" % distance
#
if distance < setdistance:
call (["raspistill -o image.jpg"], shell=True) # take a picture with Pi Camera
print "Fire"
GPIO.output(GPIO_FIRE,True) ## Turn on GPIO pin 7 fire the rockets
#
# Reset GPIO settings
GPIO.cleanup()

  

Stream a web cam from the Pi

Ingredients

1. Raspberry Pi with network / internet connection.

2. Web Cam newer the better

 

Pre Heat ( software you need to download)

Log into the pi via SSH and run the command sudo apt-get install motion 

This is the only bit of extra software you need.

You do need to make some changes to the config files.

sudo nano /etc/motion/motion.conf
**change deamon off to deamon on
**change webcam_localhost on to off
**change control_localhost on to off

save the changes.

sudo nano /etc/default/motion
**change start_motion_daemon=no to yes

Cooking ( adding it all together )

Start the service by running  sudo service motion start

Find the IP address of your Pi.

On another machine or phone browse to the address of your PI and add :8081 to the end example 192.168.0.22:8081 .

This should show the live feed from your webcam.

Making it look good

On another machine open notepad and copy the text below in to it :-

<!DOCTYPE html>
<html>
<head>
<meta content=”text/html; charset=iso-8859-1″ http-equiv=”Content-Type”>
<title>WebCam Stream from Pi</title>
<style type=”text/css”>
<!–
#apDiv1 {
position: absolute;
width: 423px;
height: 278px;
z-index: 1;
left: 6px;
top: 33px;
}
body,td,th {
color: #000;
}
body {
background-color: #0CF;
}
–>
</style> </head>
<body>
<div id=”apDiv1″> <img style=”-webkit-user-select: none” src=”http://192.168.0.22:8081/”>
</div>
Live Stream from my Pi
</body>
</html>

 

Save it as webcam.html , then open it in a browser and again you should see the feed . The important bit is in apDiv1 this is the code that displays the stream . Make sure to change the IP address to your PI.

I found you can not have to streams open on the same machine so if the webpage does not load make sure you do not have any other streams open.

<?php echo “Hello World”; ?>

  

Time Lapse Code for the Raspberry.

2013-08-04 12.47.47

Ingredients 

1. Raspberry Pi with network / internet connection.

2. Camera

3. Something to support your camera .Lego works great .

2013-08-04 12.47.47

 

 

 

 

 

 

 

Pre Heat ( software you need to download)

Log into the pi via SSH and run the command sudo apt-get install memcoder 

This is the only bit of extra software you need it encodes all the pictures into a video at full HD.

Cooking ( adding it all together )

Create a folder called TL  ( mkdir TL ) and change directory into it ( cd TL )

To run the time lapse run the command

raspistill -o myimage_%04d.jpg -tl 30000 -t 43200000

Ok let`s break it down raspstill – o means take a picture with options

myimage is the file name and the _%04d increments by 1 each time a picture is takin .jpg is the file format.

-tl 30000 is the time between pictures . 30000 = 30 seconds.

-t 43200000 is the time for the project to run. 43200000 = 12 hours there 3600000 milli seconds in 1 hour.

Ok it should happily be taking pictures  just run ls -l to see all the pictures.

When it`s finished it run , run the command ls *.jpg > stills.txt this will create a text file form the mencoder software.

and finally run mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o tlcam.avi -mf type=jpeg:fps=24 mf://@stills.txt

This will create the video file for you . I like doing on the PI however some people say it does run slow I don`t care it`s taking 12 hours to make whats and 30mins. Transfer the file or watch it on the Pi and hay presto you just cooked a Time Lapse.

One tip if your going to do a night shot then cover the led if your filming through a windows the reflection is a pain and could wreck the video.

<?php echo “Hello World”; ?>