Cmcdaid
Posts: 22
Joined: Wed Mar 12, 2014 2:38 pm

A Sponge needing to absorb some Raspberry pi knowledge...

Wed Mar 12, 2014 3:39 pm

Hi,

This is my first post, and I need some help!

I am a final year industrial design student and need to know what I need to turn my project into a working model.

I am trying to create a small product which can use height and width of things e.g a wall and then show the area on screen.

http://www.raspberrypi-spy.co.uk/2012/1 ... on-part-1/

I have found this tutorial and it seems like setting up an ultrasonic sensor with the pi relatively simple, but what I need is to have two sensors one to do height and the other to width and then the reading to show up in cm² on a screen.

I have my model b pi
2 Ultrasonic sensors
LCD screen

as well as breadboard and jumper leads on route...

I am just wondering how difficult this might be in a shortish timeframe with relatively little pi knowledge and if anyone can give me some advice or guidance and help me smash my degree!

Cheers

c

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Wed Mar 12, 2014 4:57 pm

Have a look at this page:
http://www.robot-electronics.co.uk/htm/srf04tech.htm

As well as saying a bit about how a typical one of these sensors works, the polar plots at the bottom give you some idea how poor these things are for directional precision! My worry is that if another person is standing in the middle of the room with a broom handle, it might get detected as an early echo and under read the size of the room.

These sensors usually return the first echo that looks strong enough - if you had one that allowed you to read later echoes too it might allow you to pick the longest one and use that. Maybe...

I have seen people use room measurers and they have a laser spot on them, but that may just be a fancy-looking way to mark where it's pointed. The actual measurement might still be a simple ultrasound thing. It might be useful for you to find out what method these use.

But as you already have two, you might as well have a crack at it and see what happens...

Cmcdaid
Posts: 22
Joined: Wed Mar 12, 2014 2:38 pm

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Wed Mar 12, 2014 6:00 pm

Well I'm fairly new with this stuff but I figure things out quick, I haven't played around yet as i haven't got everything I need. Over the next day or two I'm just going to copy this chaps experiment and them get a mate of mine to see what he can do with the programming. With regard the ultra sonic sensor inaccuracy I know that the sound can be affected by the surroundings but at this point my main concern is getting the two sensors hooked up to the pi and then get the distance to multiply and show on screen. (also the same guy addresses that kind of thing so that side doesn't have me too worried.)

http://www.raspberrypi-spy.co.uk/2013/0 ... on-part-2/

I thought that maybe someone would have a similar project of some sort on the forum I could read up on as I believe the term for myself with regard this is NOOB :)

Cmcdaid
Posts: 22
Joined: Wed Mar 12, 2014 2:38 pm

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Wed Mar 12, 2014 6:20 pm

I will know in the next few days but I can not imagine why it wouldn't!

I have a meeting with the robotics team at or Uni as I think this kind of thing may be what they use to stop there robots running into eacheother lol but until then I'm just buying components and trying to research other projects…. :)

mikerr
Posts: 2825
Joined: Thu Jan 12, 2012 12:46 pm
Location: UK
Contact: Website

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Wed Mar 12, 2014 6:23 pm

Ravenous wrote: These sensors usually return the first echo that looks strong enough - if you had one that allowed you to read later echoes too it might allow you to pick the longest one and use that. Maybe..
That's down to the software you write really.
The sensor is just a speaker and a microphone in one package, your software sends a pulse and waits to hear the echo(es).

I've had two sensors next to each other and been surprised that they don't pickup each other's echos.
Might be a different story if they were facing each other ;)
Android app - Raspi Card Imager - download and image SD cards - No PC required !

Cmcdaid
Posts: 22
Joined: Wed Mar 12, 2014 2:38 pm

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Mon Mar 17, 2014 9:16 pm

Updates Updates Updates...

Okay so using the guide in first link I have one sensor setup and working fairly accurately with the code specified. Everything works great.

My queries are, I think there is enough pins to directly attach the another ultrasonic module to the GPIO (same setup just other half of the breadboard?) but how can I learn or what will I need to do to the code so that it takes the two measurements and multiples them to show the area? Do I need to phone my computer science pal or is it relatively simple lol?

Once this is sorted I'm on to getting that value on a screen and making it portable but if anyone can shed light on adding another sensor and modifying the code that would be a massive help :)

here is the code btw

Code: Select all

#!/usr/bin/python
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|
#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
# ultrasonic_1.py
# Measure distance using an ultrasonic module
#
# Author : Matt Hawkins
# Date   : 09/01/2013

# 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()

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Tue Mar 18, 2014 9:25 am

If you look through Matt's code, it's got a few constants "GPIO_TRIGGER = 23 GPIO_ECHO = 24",

I think you'll want to add two more, like GPIO_TRIGGER2 or something like that, and add more code at the bottom of the program to read the second sensor in the same way as the first. Connect up the second board to whatever the new pins are. (Might start to get fiddly to cram the power wiring in)

The numbers 23 and 24 don't necessarily correspond to positions on the P1 connector - you might have to dig around to find which numbers correspond to usable/suitable pins. Maybe have a look at this reference:
http://elinux.org/Rpi_Low-level_peripherals

Then at the bottom you would print the width, the length, and the area all in one line. Beginning to look like a fun gadget...

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Tue Mar 18, 2014 11:54 am

Cmcdaid wrote:I think there is enough pins to directly attach the another ultrasonic module to the GPIO (same setup just other half of the breadboard?) but how can I learn or what will I need to do to the code so that it takes the two measurements and multiples them to show the area? Do I need to phone my computer science pal or is it relatively simple lol?
This is a final year (undergraduate) project? I think evidence of a bit of thinking and research might earn you marks! Or maybe you have chosen the wrong project because it is getting a bit late to learn a programming language...

Look at what you have already got.

Code: Select all

# Define GPIO to use on Pi
GPIO_TRIGGER = 23
GPIO_ECHO = 24
So it takes 2 pins to connect your module. The RPi has 17 gpio pins - see http://elinux.org/RPi_Low-level_periphe ... ion_header - so there are plenty of pins spare to connect another module.

You already have code from Matt Hawkins that shows you how to process the input from the module to get the corresponding distance.

Code: Select all

# 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
You simply need to replicate that with your newly chosen Trigger and Echo pins, then 'multiple' the two results.

If you don't know enough Python to be able to make that simple change you will need to call on help from your 'computer science pal.' Whether or not you need her help, I hope your project will acknowledge that the code you have submitted is not your own work.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Cmcdaid
Posts: 22
Joined: Wed Mar 12, 2014 2:38 pm

Re: A Sponge needing to absorb some Raspberry pi knowledge..

Tue Mar 18, 2014 4:25 pm

Cheers for the link Ravenous.

It is final year and yes it is undergraduate, no need to worry about how I will be marked I have that covered the marks are delegated based on the design thinking, context, execution etc which I am always on top of.

The course is not computer programming and I'm not expected to learn how to code, I just like to have fully functioning models and in this case it means working with something which I'm unfamiliar with. I have already specified I have used this guide to set up the experiment and show how it will work.

I have been tinkering today and I think I may have it sorted. When I make it a portable unit I will throw up some pics.

Cheers for the advice folks :)

Return to “General discussion”