Pages: [1]   Go Down
Author Topic: room scaning project need a bit of help to get it to work  (Read 621 times)
0 Members and 1 Guest are viewing this topic.
new zealand
Offline Offline
Newbie
*
Karma: 1
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

my project consists of two servos ,a distance sensor and a prossessing code the servos are ment to goto mouseX and mouseY which they do then the distance sensor is ment to send the distance to the prossessing and it creates a box at mouseX and mouseY and it  coulor depends on how
 far the distance is but it is geting weird distances which repeat so i am unsure of the problem

processing
Code:
import processing.serial.*;
int Y;
int X;
Serial myPort;  // Create object from Serial class
int D;
int C;
void setup()
{
  size(660, 660);
  String portName = Serial.list()[8];
  myPort = new Serial(this, portName, 9600);
  background(255);    // Setting the background to white          // Setting the outline (stroke) to black    
}

void draw() {
  delay(100);
X=mouseX/8;
myPort.write(X);
delay(1);
Y=(mouseY/8)+91;
myPort.write(Y);
delay(1);
myPort.write(183);
delay(1);
  if ( myPort.available() > 0) {  // If data is available,
    D = myPort.read();         // read it and store it in val
  }
println(D);
C = D*2;
stroke(C);
fill(C);
rect(mouseX,mouseY,6,6);

}



ardiuno

Code:
#include <Servo.h>
int pingPin = 7;
Servo x;
Servo y;
int X = 0;
int Y = 0;
int a = 0;
void setup()
{
Serial.begin(9600);
 x.attach(10);
 y.attach(9);
}
void loop()  
{
  if ( Serial.available() > 0 )
  {
a = Serial.read();
if (a<=90){
X=a;
x.write(X*2);}
}
if (a>=91 & a<182){
  Y=a-91;
  y.write(Y*2);
}




  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  Serial.print(cm);

  
  delay(500);



}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
« Last Edit: February 05, 2011, 04:10:27 am by magicman5511 » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33374
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to break the problem down. First off just send the data to the monitor window and see if the data you ate recording looks ok. Only then proceed to do something with it. Without the hardware schematic and more information about what you are getting it is hard to tell what is wrong.
Logged

new zealand
Offline Offline
Newbie
*
Karma: 1
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the ardiuno side of the project works fine because the serial monitor gives the correct reading then i open the prossing code it is wrong it is saying that the value that i sent from the ardiuno is 50 55 10 13 not in that order  but it was 228 then when i make it smaller it remain the same could it just be that it is reading the data in the wrong format or is it just the script     the problem is that yesterday it was more stable eg 228 read 56 and  190 read 56 but 170 read 55 and soon at no particular interval
Logged

Pages: [1]   Go Up
Jump to: