Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / Re: room scaning progect need a bit of help to get it to work on: February 04, 2011, 04:36:07 pm
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
2  Using Arduino / Audio / Re: Voice transmission with Arduino + XBee on: February 03, 2011, 10:28:23 pm
you cant tranzmit analog signals but you can digital so you will have to find away to convert them
3  Using Arduino / Project Guidance / room scaning project need a bit of help to get it to work on: February 03, 2011, 08:54:57 pm
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;
}
4  Using Arduino / Interfacing w/ Software on the Computer / need some help with my project on: February 03, 2011, 07:48:26 pm
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;
}
5  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: i need some help with a serial code on: December 01, 2010, 04:31:12 pm
managed to get it to work  

the problem was the serisl only allows a value up to 255 and then it goes back to 1 ;D ;D
6  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: i need some help with a serial code on: December 01, 2010, 02:46:41 pm
servo x uses the serial to get a number between 0 and 180
were as servo y gets a number between 181 and 361 then it takes away 181 which gives i a number between 0 and 180 so the servo can run
7  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: i need some help with a serial code on: December 01, 2010, 02:01:03 pm
the X and Y servos are runing one at a time
when my mouse is at X:100 Y:50
it will move one of the servos to 100 then to 50
i want it to move one to 100 and the other to 50
8  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: i need some help with a serial code on: December 01, 2010, 01:55:35 pm
thank you but it has not worked smiley-sad
here is my prosesing script that works with it

import processing.serial.*;
int Y;
Serial myPort;  // Create object from Serial class
int D=1000;
int X;
void setup()
{
  size(180, 180);
  Serial.list();
  String portName = Serial.list()[10];
  myPort = new Serial(this, portName, 9600);
}
void draw() {
  delay(D);
  X=mouseX;
myPort.write(X);
println(mouseX);
delay(D);
myPort.write(Y);
Y=mouseY+181;
println(mouseY);
}
9  Forum 2005-2010 (read only) / Frequently-Asked Questions / i need some help with a serial code on: December 01, 2010, 01:40:07 pm
I am making two servos point at a spot using 1 serial port
but my code is not working please can you give me some idea where i have go wrong

#include <Servo.h>
int pingPin = 3;
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()
{
a = Serial.read();
if (a>=181){
Y=a-181;
y.write(Y);
}
else {if (a<=180){
X=a;
x.write(X);
}}


if (a==361){
long duration, inches, cm;
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);    
inches = microsecondsToInches(duration);
Serial.print(inches);
Serial.println();

}}
long microsecondsToInches(long microseconds)
{
 return microseconds / 147/ 2;
}
Pages: [1]